git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@485 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
5d0613798c
commit
12d1508621
|
@ -11,6 +11,8 @@ import org.gcube.common.core.resources.GCUBEHostingNode;
|
||||||
import org.gcube.common.core.resources.GCUBEResource;
|
import org.gcube.common.core.resources.GCUBEResource;
|
||||||
import org.gcube.common.core.resources.GCUBERunningInstance;
|
import org.gcube.common.core.resources.GCUBERunningInstance;
|
||||||
import org.gcube.common.core.scope.GCUBEScope;
|
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;
|
import org.gcube.informationsystem.registry.impl.core.RegistryConfiguration.ROOT_SERVICES;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,6 +38,41 @@ public class ServiceContext extends GCUBEServiceContext {
|
||||||
protected boolean isICCodeployed = false;
|
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<Object> {
|
||||||
|
@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() {}
|
private ServiceContext() {}
|
||||||
|
|
||||||
public static ServiceContext getContext() {
|
public static ServiceContext getContext() {
|
||||||
|
@ -54,7 +91,7 @@ public class ServiceContext extends GCUBEServiceContext {
|
||||||
|
|
||||||
//creates the single RegistryResource used to raise notifications about profiles' changes
|
//creates the single RegistryResource used to raise notifications about profiles' changes
|
||||||
logger.info("Creating IS-Registry notification resource...");
|
logger.info("Creating IS-Registry notification resource...");
|
||||||
new Thread() {
|
/*new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
|
@ -65,7 +102,11 @@ public class ServiceContext extends GCUBEServiceContext {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ServiceContext.this.logger.error("Failed to create the notification resource", 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");
|
logger.info("IS-Registry notification resource registered");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue