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 11, 2024
1 parent 6a992ce commit 51d5589
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

package com.sun.xml.ws.assembler;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
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 +26,7 @@
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;

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

private final MetroConfigName metroConfigName;

private static final Cache<Container, TubeFactoryList> tubeFactoryListCache = CacheBuilder.newBuilder()
.maximumSize(100)
.expireAfterWrite(5, TimeUnit.MINUTES)
.build();

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

MetroConfigLoader configLoader = new MetroConfigLoader(context.getContainer(), metroConfigName);
return initializeTubeCreators(configLoader.getClientSideTubeFactories(endpointUri));
TubeFactoryList tubeFactoryList = tubeFactoryListCache.getIfPresent(context.getContainer());
if (tubeFactoryList == null) {
MetroConfigLoader configLoader = new MetroConfigLoader(context.getContainer(), metroConfigName);
tubeFactoryList = configLoader.getClientSideTubeFactories(endpointUri);
tubeFactoryListCache.put(context.getContainer(), tubeFactoryList);
}
return initializeTubeCreators(tubeFactoryList);
}

/**
Expand Down

0 comments on commit 51d5589

Please sign in to comment.