diff --git a/src/main/java/org/gcube/smartgears/handler/resourceregistry/EServiceHandler.java b/src/main/java/org/gcube/smartgears/handler/resourceregistry/EServiceHandler.java index c353a7b..46d4b37 100644 --- a/src/main/java/org/gcube/smartgears/handler/resourceregistry/EServiceHandler.java +++ b/src/main/java/org/gcube/smartgears/handler/resourceregistry/EServiceHandler.java @@ -104,8 +104,6 @@ public class EServiceHandler extends ApplicationLifecycleHandler { Set startContextsUUID = new HashSet<>(); for (String token : startTokens) { - UUID contextUUID = ContextUtility.getContextUUID(token); - startContextsUUID.add(contextUUID); if (create) { ContextUtility.setContextFromToken(token); eServiceManager = new EServiceManager(applicationContext); @@ -113,6 +111,7 @@ public class EServiceHandler extends ApplicationLifecycleHandler { create = false; } else { try { + UUID contextUUID = ContextUtility.getContextUUID(token); eServiceManager.addToContext(contextUUID); } catch (Exception e) { UUID uuid = UUID.fromString(applicationContext.id()); @@ -121,6 +120,16 @@ public class EServiceHandler extends ApplicationLifecycleHandler { throw e; } } + + /* + * Do not move this code before having instantiated HostingNodeManager + * which in turn instantiate the ResourceRegistryPublisher + * which in turn initialize ContextCacheRenewal in ContextCache. + * Please note that to properly instantiate ResourceRegistryPublisher + * it is necessary having set a token. + */ + UUID contextUUID = ContextUtility.getContextUUID(token); + startContextsUUID.add(contextUUID); } Set resourceContextsUUID = eServiceManager.getContextsUUID().keySet(); diff --git a/src/main/java/org/gcube/smartgears/handler/resourceregistry/HostingNodeHandler.java b/src/main/java/org/gcube/smartgears/handler/resourceregistry/HostingNodeHandler.java index 433004f..5e04f64 100644 --- a/src/main/java/org/gcube/smartgears/handler/resourceregistry/HostingNodeHandler.java +++ b/src/main/java/org/gcube/smartgears/handler/resourceregistry/HostingNodeHandler.java @@ -102,10 +102,10 @@ public class HostingNodeHandler extends ContainerHandler { List startTokens = containerContext.configuration().startTokens(); + + Set startContextsUUID = new HashSet<>(); for (String token : startTokens) { - UUID contextUUID = ContextUtility.getContextUUID(token); - startContextsUUID.add(contextUUID); if (create) { ContextUtility.setContextFromToken(token); hostingNodeManager = new HostingNodeManager(containerContext); @@ -113,6 +113,7 @@ public class HostingNodeHandler extends ContainerHandler { create = false; } else { try { + UUID contextUUID = ContextUtility.getContextUUID(token); hostingNodeManager.addToContext(contextUUID); } catch (Exception e) { UUID uuid = UUID.fromString(containerContext.id()); @@ -121,6 +122,16 @@ public class HostingNodeHandler extends ContainerHandler { throw e; } } + + /* + * Do not move this code before having instantiated HostingNodeManager + * which in turn instantiate the ResourceRegistryPublisher + * which in turn initialize ContextCacheRenewal in ContextCache. + * Please note that to properly instantiate ResourceRegistryPublisher + * it is necessary having set a token. + */ + UUID contextUUID = ContextUtility.getContextUUID(token); + startContextsUUID.add(contextUUID); } Set resourceContextsUUID = hostingNodeManager.getContextsUUID().keySet();