From 6986f187d229d854da8a50a53c5ea8304fdeff0f Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sat, 5 Feb 2011 21:02:27 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@34690 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../impl/porttypes/RegistryFactory.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/org/gcube/informationsystem/registry/impl/porttypes/RegistryFactory.java b/src/org/gcube/informationsystem/registry/impl/porttypes/RegistryFactory.java index ab694b9..eff9499 100644 --- a/src/org/gcube/informationsystem/registry/impl/porttypes/RegistryFactory.java +++ b/src/org/gcube/informationsystem/registry/impl/porttypes/RegistryFactory.java @@ -12,6 +12,7 @@ import java.util.Calendar; import org.apache.axis.components.uuid.UUIDGen; import org.apache.axis.components.uuid.UUIDGenFactory; import org.gcube.common.core.contexts.GCUBEServiceContext; +import org.gcube.common.core.contexts.GCUBEServiceContext.Status; import org.gcube.common.core.faults.GCUBEFault; import org.gcube.common.core.porttypes.GCUBEPortType; import org.gcube.common.core.resources.GCUBEResource; @@ -71,21 +72,31 @@ public class RegistryFactory extends GCUBEPortType { @Override public void run() { - while (true) { + int attempts = 0; + boolean created = false; + while (attempts++ < 10) { + try { + Thread.sleep(1000); + } catch (InterruptedException e1) { + RegistryFactory.logger.error("Failed to sleep in between factory creation"); + ServiceContext.getContext().setStatus(Status.FAILED); + break; + } try { for (GCUBEScope scope: ServiceContext.getContext().getInstance().getScopes().values()){ RegistryFactory.logger.info("Creating the notification resource " + RegistryFactory.NOTIFICATOR_RESOURCE_KEY + " within the scope " + scope.getName()); ServiceContext.getContext().setScope(scope); singletonResource = (RegistryFactoryResource) FactoryContext.getContext().getWSHome().create(FactoryContext.getContext().makeKey(RegistryFactory.NOTIFICATOR_RESOURCE_KEY)); - singletonResource.store(); - + singletonResource.store(); } + created = true; break; } catch (Exception e) { - RegistryFactory.logger.error("Failed to create the resource", e); - Thread.sleep(1000); + RegistryFactory.logger.error("Failed to create the resource", e); } } + if (!created) + ServiceContext.getContext().setStatus(Status.FAILED); } }.start();