This commit is contained in:
Manuele Simi 2011-02-05 21:02:27 +00:00
parent f97788792f
commit 6986f187d2
1 changed files with 16 additions and 5 deletions

View File

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