Asynch creation of the factory resource

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@34689 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2011-02-05 20:41:01 +00:00
parent 99ee7ae64d
commit f97788792f
1 changed files with 22 additions and 12 deletions

View File

@ -67,19 +67,29 @@ public class RegistryFactory extends GCUBEPortType {
if (singletonResource != null)
return;//cannot create the state twice
logger.info("Initialising the factory state...");
try {
for (GCUBEScope scope: ServiceContext.getContext().getInstance().getScopes().values()){
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();
}
new Thread() {
} catch (Exception e) {
logger.error("Failed to create the resource", e);
throw e;
}
@Override
public void run() {
while (true) {
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();
}
break;
} catch (Exception e) {
RegistryFactory.logger.error("Failed to create the resource", e);
Thread.sleep(1000);
}
}
}
}.start();
}
/**