Added facilities to use the client outside of container

This commit is contained in:
Luca Frosini 2023-03-02 14:51:22 +01:00
parent 022b3acc8b
commit 6639589e9e
2 changed files with 25 additions and 7 deletions

View File

@ -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);
}

View File

@ -60,9 +60,12 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
protected final String address;
protected Map<String, String> 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<Context> 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) {