diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientFactory.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientFactory.java index 3d43f69..1b570a4 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientFactory.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientFactory.java @@ -12,14 +12,24 @@ public class ResourceRegistryClientFactory { private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryClientFactory.class); - public static ResourceRegistryClient create() { + public static String getResourceRegistryURL() { String address = String.format("%s/%s", ServiceInstance.getServiceURL(),Constants.SERVICE_NAME); + return address; + } + + public static String getResourceRegistryURL(String context) { + String address = String.format("%s/%s", ServiceInstance.getServiceURL(context),Constants.SERVICE_NAME); + return address; + } + + public static ResourceRegistryClient create() { + String address = getResourceRegistryURL(); logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address); return new ResourceRegistryClientImpl(address); } public static ResourceRegistryClient create(String context) { - String address = String.format("%s/%s", ServiceInstance.getServiceURL(context),Constants.SERVICE_NAME); + String address = getResourceRegistryURL(context); logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address); return new ResourceRegistryClientImpl(address); } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java index 2c6a07b..b3f233e 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java @@ -60,9 +60,12 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { protected final String address; protected Map headers; + protected boolean hierarchicalMode; protected boolean includeContextsInHeader; + protected ContextCache contextCache; + @Override public boolean isHierarchicalMode() { return hierarchicalMode; @@ -136,11 +139,19 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { } public ResourceRegistryClientImpl(String address) { + this(address, true); + } + + public ResourceRegistryClientImpl(String address, boolean sharedContextCache) { this.address = address; this.hierarchicalMode = false; this.includeContextsInHeader = false; this.headers = new HashMap<>(); - ContextCache contextCache = ContextCache.getInstance(); + if(sharedContextCache) { + contextCache = ContextCache.getInstance(); + }else { + contextCache = new ContextCache(); + } contextCache.setContextCacheRenewal(contextCacheRenewal); } @@ -173,7 +184,6 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { @Override public List getAllContext() throws ResourceRegistryException { - ContextCache contextCache = ContextCache.getInstance(); return contextCache.getContexts(); } @@ -226,8 +236,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { @Override public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException { - ContextCache contextCache = ContextCache.getInstance(); - Context context = ContextCache.getInstance().getContextByUUID(uuid);; + Context context = contextCache.getContextByUUID(uuid);; if(context == null) { context = getContextFromServer(ContextPath.CURRENT_CONTEXT_PATH_PART); contextCache.cleanCache(); @@ -245,7 +254,6 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { @Override public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException { String contextFullName = org.gcube.common.context.ContextUtility.getCurrentContextFullName(); - ContextCache contextCache = ContextCache.getInstance(); UUID uuid = contextCache.getUUIDByFullName(contextFullName); Context context = null; if(uuid == null) {