git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@7709 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
591bb3d14b
commit
27d94bb106
|
@ -1,17 +1,23 @@
|
||||||
package org.gcube.informationsystem.registry.impl.contexts;
|
package org.gcube.informationsystem.registry.impl.contexts;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.rmi.RemoteException;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
||||||
import org.gcube.common.core.contexts.GHNContext;
|
import org.gcube.common.core.contexts.GHNContext;
|
||||||
|
import org.gcube.common.core.faults.GCUBEFault;
|
||||||
|
|
||||||
import static org.gcube.common.core.contexts.GHNContext.Mode;
|
import static org.gcube.common.core.contexts.GHNContext.Mode;
|
||||||
import org.gcube.common.core.informationsystem.client.AtomicCondition;
|
import org.gcube.common.core.informationsystem.client.AtomicCondition;
|
||||||
import org.gcube.common.core.informationsystem.client.ISClient;
|
import org.gcube.common.core.informationsystem.client.ISClient;
|
||||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEGHNQuery;
|
import org.gcube.common.core.informationsystem.client.queries.GCUBEGHNQuery;
|
||||||
import org.gcube.common.core.informationsystem.client.queries.GCUBERIQuery;
|
import org.gcube.common.core.informationsystem.client.queries.GCUBERIQuery;
|
||||||
|
import org.gcube.common.core.informationsystem.publisher.ISLocalPublisher;
|
||||||
import org.gcube.common.core.informationsystem.publisher.ISPublisher;
|
import org.gcube.common.core.informationsystem.publisher.ISPublisher;
|
||||||
import org.gcube.common.core.informationsystem.publisher.ISPublisherException;
|
import org.gcube.common.core.informationsystem.publisher.ISPublisherException;
|
||||||
|
import org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer;
|
||||||
import org.gcube.common.core.resources.GCUBEHostingNode;
|
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;
|
||||||
|
@ -24,6 +30,9 @@ import org.gcube.informationsystem.registry.impl.RegistryFactory;
|
||||||
import org.gcube.informationsystem.registry.impl.core.RegistryConfiguration.ROOT_SERVICES;
|
import org.gcube.informationsystem.registry.impl.core.RegistryConfiguration.ROOT_SERVICES;
|
||||||
import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource;
|
import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource;
|
||||||
import org.gcube.informationsystem.registry.impl.util.EliminatePoolingThread;
|
import org.gcube.informationsystem.registry.impl.util.EliminatePoolingThread;
|
||||||
|
import org.gcube.informationsystem.registry.stubs.CreateResourceMessage;
|
||||||
|
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
|
||||||
|
import org.gcube.informationsystem.registry.stubs.UpdateResourceMessage;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -171,6 +180,8 @@ public class ServiceContext extends GCUBEServiceContext {
|
||||||
|
|
||||||
scheduler.run();
|
scheduler.run();
|
||||||
|
|
||||||
|
this.subscribeToLocalRegistrationEvents();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,5 +296,78 @@ public class ServiceContext extends GCUBEServiceContext {
|
||||||
protected boolean isICCodeployed() {
|
protected boolean isICCodeployed() {
|
||||||
return isICCodeployed;
|
return isICCodeployed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void subscribeToLocalRegistrationEvents() throws Exception{
|
||||||
|
ISLocalPublisher pub = GHNContext.getImplementation(ISLocalPublisher.class);
|
||||||
|
|
||||||
|
LocalProfileConsumer cons = new LocalProfileConsumer() {
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer#onProfileRegistered(org.gcube.common.core.resources.GCUBEResource)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onProfileRegistered(GCUBEResource resource, GCUBEScope scope) {
|
||||||
|
logger.debug("onProfileRegistered event received" );
|
||||||
|
RegistryFactory factory= new RegistryFactory();
|
||||||
|
try {
|
||||||
|
ServiceContext.getContext().setScope(scope);
|
||||||
|
CreateResourceMessage crm = new CreateResourceMessage();
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
resource.store(writer);
|
||||||
|
crm.setProfile(writer.toString());
|
||||||
|
crm.setType(resource.getType());
|
||||||
|
factory.createResource(crm);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("cannot handle the create resource event"+e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer#onProfileRemoved(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onProfileRemoved(String resourceID, String type, GCUBEScope scope) {
|
||||||
|
ServiceContext.getContext().setScope(scope);
|
||||||
|
RegistryFactory factory= new RegistryFactory();
|
||||||
|
RemoveResourceMessage rrm= new RemoveResourceMessage();
|
||||||
|
rrm.setType(type);
|
||||||
|
rrm.setUniqueID(resourceID);
|
||||||
|
try {
|
||||||
|
factory.removeResource(rrm);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("cannot handle the remove resource event"+e);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer#onProfileUpdated(org.gcube.common.core.resources.GCUBEResource)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onProfileUpdated(GCUBEResource resource, GCUBEScope scope) {
|
||||||
|
logger.debug("onProfileUpdated event received" );
|
||||||
|
ServiceContext.getContext().setScope(scope);
|
||||||
|
RegistryFactory factory= new RegistryFactory();
|
||||||
|
try {
|
||||||
|
UpdateResourceMessage urm= new UpdateResourceMessage();
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
resource.store(writer);
|
||||||
|
urm.setXmlProfile(writer.toString());
|
||||||
|
urm.setType(resource.getType());
|
||||||
|
urm.setUniqueID(resource.getID());
|
||||||
|
factory.updateResource(urm);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("cannot handle the update resource event"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
pub.subscribeLocalProfileEvents(cons);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue