From 12d150862157b0b51f208add3e10114b915ee952 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Wed, 23 Apr 2008 20:17:29 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@485 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../registry/impl/core/ServiceContext.java | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/org/gcube/informationsystem/registry/impl/core/ServiceContext.java b/src/org/gcube/informationsystem/registry/impl/core/ServiceContext.java index dc6c8ed..c2cba3b 100644 --- a/src/org/gcube/informationsystem/registry/impl/core/ServiceContext.java +++ b/src/org/gcube/informationsystem/registry/impl/core/ServiceContext.java @@ -11,6 +11,8 @@ import org.gcube.common.core.resources.GCUBEHostingNode; import org.gcube.common.core.resources.GCUBEResource; import org.gcube.common.core.resources.GCUBERunningInstance; import org.gcube.common.core.scope.GCUBEScope; +import org.gcube.common.core.utils.handlers.GCUBEHandler; +import org.gcube.common.core.utils.handlers.GCUBEScheduledHandler; import org.gcube.informationsystem.registry.impl.core.RegistryConfiguration.ROOT_SERVICES; /** @@ -35,6 +37,41 @@ public class ServiceContext extends GCUBEServiceContext { protected boolean isICCodeployed = false; + + protected class NotificationResourceScheduler extends GCUBEScheduledHandler { + + public NotificationResourceScheduler(long interval, Mode mode) { + super(interval, mode); + } + + protected boolean repeat(Exception exception, int exceptionCount) { + if (exception!=null) { + logger.warn("Failed to create the notification resource (attempt "+exceptionCount+" out of 20)",exception); + if (exceptionCount >= 20) { + logger.error("Max attempts reached, no more chance to register the notification resource"); + return false; + } + } + return true; + } + + } + + /** Tries to create the resource */ + protected class NotificationResource extends GCUBEHandler { + @SuppressWarnings("unchecked") + public void run() throws Exception { + try { + 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 ); + } catch (Exception e) { + + throw e; + } + } + } private ServiceContext() {} @@ -54,7 +91,7 @@ public class ServiceContext extends GCUBEServiceContext { //creates the single RegistryResource used to raise notifications about profiles' changes logger.info("Creating IS-Registry notification resource..."); - new Thread() { + /*new Thread() { public void run() { try { Thread.sleep(5000); @@ -65,7 +102,11 @@ public class ServiceContext extends GCUBEServiceContext { } catch (Exception e) { ServiceContext.this.logger.error("Failed to create the notification resource", e); } - }}.start(); + }}.start();*/ + + NotificationResourceScheduler scheduler = new NotificationResourceScheduler(3000, GCUBEScheduledHandler.Mode.LAZY); + scheduler.setHandled(new NotificationResource()); + scheduler.run(); logger.info("IS-Registry notification resource registered");