Skip to content

Commit

Permalink
Reduce inits of MetroConfigLoader
Browse files Browse the repository at this point in the history
Creating a MetroConfigLoader requires frequent class- and resource-loading, so re-use factories when applicable
  • Loading branch information
DaScheid committed Jun 19, 2024
1 parent ee7f1c7 commit 94e5388
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.sun.istack.NotNull;
import com.sun.istack.logging.Logger;
import com.sun.xml.ws.api.server.Container;
import com.sun.xml.ws.assembler.dev.ClientTubelineAssemblyContext;
import com.sun.xml.ws.assembler.dev.ServerTubelineAssemblyContext;
import com.sun.xml.ws.resources.TubelineassemblyMessages;
Expand All @@ -23,6 +24,9 @@
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;

/**
*
Expand All @@ -32,6 +36,11 @@ final class TubelineAssemblyController {

private final MetroConfigName metroConfigName;

private static final Map<Container, TubeFactoryList> tubeFactoryListCache = new ConcurrentHashMap<>();
private static final ReentrantLock cacheLock = new ReentrantLock();
private static final int MAX_CACHE_SIZE = 100;


TubelineAssemblyController(MetroConfigName metroConfigName) {
this.metroConfigName = metroConfigName;
}
Expand Down Expand Up @@ -59,8 +68,21 @@ Collection<TubeCreator> getTubeCreators(ClientTubelineAssemblyContext context) {
endpointUri = null;
}

MetroConfigLoader configLoader = new MetroConfigLoader(context.getContainer(), metroConfigName);
return initializeTubeCreators(configLoader.getClientSideTubeFactories(endpointUri));
TubeFactoryList tubeFactoryList = tubeFactoryListCache.get(context.getContainer());
if (tubeFactoryList == null) {
MetroConfigLoader configLoader = new MetroConfigLoader(context.getContainer(), metroConfigName);
tubeFactoryList = configLoader.getClientSideTubeFactories(endpointUri);
cacheLock.lock();
try {
if (tubeFactoryListCache.size() >= MAX_CACHE_SIZE) {
tubeFactoryListCache.remove(tubeFactoryListCache.keySet().iterator().next());
}
tubeFactoryListCache.put(context.getContainer(), tubeFactoryList);
} finally {
cacheLock.unlock();
}
}
return initializeTubeCreators(tubeFactoryList);
}

/**
Expand Down

0 comments on commit 94e5388

Please sign in to comment.