diff --git a/src/org/gcube/informationsystem/registry/impl/RegistryFactory.java b/src/org/gcube/informationsystem/registry/impl/RegistryFactory.java index 1296f58..ce3945b 100644 --- a/src/org/gcube/informationsystem/registry/impl/RegistryFactory.java +++ b/src/org/gcube/informationsystem/registry/impl/RegistryFactory.java @@ -351,7 +351,7 @@ public class RegistryFactory extends GCUBEStartupPortType{ return (ProfileResource) ProfileContext.getContext().getWSHome().find(ProfileContext.getContext().makeKey(id)); } catch (Exception e ){ - logger.debug("A profile with the given id has not been created yet"); + logger.debug("A profile with the given id "+ id+" has not been created yet"); } return null; diff --git a/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java b/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java index 46d1d02..9d34b35 100644 --- a/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java +++ b/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java @@ -1,6 +1,7 @@ package org.gcube.informationsystem.registry.impl.contexts; import java.io.ByteArrayInputStream; +import java.util.List; import javax.xml.namespace.QName; import org.apache.axis.encoding.TypeMappingRegistry; @@ -95,10 +96,31 @@ public class ServiceContext extends GCUBEServiceContext { @SuppressWarnings("unchecked") public void run() throws Exception { - ServiceContext.getContext().setScope(ServiceContext.getContext().getInstance().getScopes().values().toArray(new GCUBEScope[0])[0]); - RegistryFactoryResource resource = (RegistryFactoryResource) FactoryContext.getContext().getWSHome().create( - FactoryContext.getContext().makeKey(RegistryFactory.NOTIFICATOR_RESOURCE_KEY)); - resource.getPersistenceDelegate().store(resource ); + List pt = GHNContext.getContext().getActivePortTypes(); + if ( (pt == null) || (pt.size() < 1)) + throw new Exception(); + + try { + // register my profile + GCUBERunningInstance RegistryRIProfile = ServiceContext.getContext().getInstance(); + GCUBERIQuery query = client.getQuery(GCUBERIQuery.class); + query.addAtomicConditions(new AtomicCondition("//ServiceClass", ServiceContext.this.getServiceClass()),new AtomicCondition("//ServiceName", this.getName())); + if (ServiceContext.this.client.execute(query, GHNContext.getContext().getDefaultScope()).size() == 0) + registerProfile(RegistryRIProfile, GCUBERunningInstance.TYPE); + + ServiceContext. this.checkCodeployedServices(); + } catch (Exception e) { + logger.error("Failed to register co-deployed services", e); + throw e; + } + + + ServiceContext.getContext().setScope(ServiceContext.getContext().getInstance().getScopes().values().toArray(new GCUBEScope[0])[0]); + RegistryFactoryResource resource = (RegistryFactoryResource) FactoryContext.getContext().getWSHome().create( + FactoryContext.getContext().makeKey(RegistryFactory.NOTIFICATOR_RESOURCE_KEY)); + resource.getPersistenceDelegate().store(resource ); + + } } @@ -120,34 +142,11 @@ public class ServiceContext extends GCUBEServiceContext { GHNContext.getContext().setMode(Mode.PRODUCTION); //creates the single RegistryResource used to raise notifications about profiles' changes - logger.info("Creating IS-Registry notification resource..."); + logger.info("Scheduling IS-Registry notification resource..."); NotificationResourceScheduler scheduler = new NotificationResourceScheduler(10, GCUBEScheduledHandler.Mode.LAZY); scheduler.setHandled(new NotificationResource()); scheduler.run(); - - logger.info("IS-Registry notification resource registered"); - - try {Thread.sleep(20000);} catch (InterruptedException e1) { - logger.error("Unable to get the service instance profile", e1); - } - - // Check if the Registry profile is already registered - - try { - // register my profile - GCUBERunningInstance RegistryRIProfile = ServiceContext.getContext().getInstance(); - GCUBERIQuery query = client.getQuery(GCUBERIQuery.class); - query.addAtomicConditions(new AtomicCondition("//ServiceClass", this.getServiceClass()),new AtomicCondition("//ServiceName", this.getName())); - if (this.client.execute(query, GHNContext.getContext().getDefaultScope()).size() == 0) - registerProfile(RegistryRIProfile, GCUBERunningInstance.TYPE); - - this.checkCodeployedServices(); - } catch (Exception e) { - logger.error("Failed to register co-deployed services", e); - throw e; - } - } @Override