Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions src/main/java/com/cognitect/transit/impl/Cache.java

This file was deleted.

15 changes: 6 additions & 9 deletions src/main/java/com/cognitect/transit/impl/ReaderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ReaderFactory {

private static Map<Map<String, ReadHandler<?,?>>, ReadHandlerMap> handlerCache = new Cache<Map<String, ReadHandler<?,?>>, ReadHandlerMap>();
private static final ConcurrentHashMap<Map<String, ReadHandler<?,?>>, ReadHandlerMap> handlerCache = new ConcurrentHashMap<>();

public static Map<String, ReadHandler<?,?>> defaultHandlers() {

Expand Down Expand Up @@ -59,14 +60,10 @@ private static Map<String, ReadHandler<?,?>> handlerMap(Map<String, ReadHandler<
return customHandlers;
}

synchronized (ReaderFactory.class) {
ReadHandlerMap readHandlerMap = handlerCache.get(customHandlers);
if (readHandlerMap == null) {
readHandlerMap = new ReadHandlerMap(customHandlers);
handlerCache.put(customHandlers, readHandlerMap);
}
return readHandlerMap;
}
if (customHandlers == null)
return new ReadHandlerMap(null);

return handlerCache.computeIfAbsent(customHandlers, ReadHandlerMap::new);
}

private static DefaultReadHandler defaultHandler(DefaultReadHandler customDefaultHandler) {
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/com/cognitect/transit/impl/WriterFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,22 @@
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

public class WriterFactory {

private static final Map<Map<Class, WriteHandler<?,?>>, WriteHandlerMap> handlerCache = new Cache<Map<Class, WriteHandler<?,?>>, WriteHandlerMap>();
private static final ConcurrentHashMap<Map<Class, WriteHandler<?,?>>, WriteHandlerMap> handlerCache = new ConcurrentHashMap<>();

private static WriteHandlerMap buildWriteHandlerMap(Map<Class, WriteHandler<?, ?>> customHandlers) {
if (customHandlers instanceof WriteHandlerMap)
return new WriteHandlerMap(customHandlers);

WriteHandlerMap writeHandlerMap;
synchronized (handlerCache) {
writeHandlerMap = handlerCache.get(customHandlers);
if (writeHandlerMap == null) {
writeHandlerMap = new WriteHandlerMap(customHandlers);
handlerCache.put(customHandlers, writeHandlerMap);
}
}
return new WriteHandlerMap(writeHandlerMap);
if (customHandlers == null)
return new WriteHandlerMap();

WriteHandlerMap cached = handlerCache.computeIfAbsent(customHandlers, WriteHandlerMap::new);
return new WriteHandlerMap(cached);
}

private static WriteHandlerMap verboseHandlerMap(Map<Class, WriteHandler<?, ?>> customHandlers) {
Expand Down