This commit is contained in:
Lucio Lelii 2008-12-11 18:14:18 +00:00
parent 591bb3d14b
commit 27d94bb106
1 changed files with 84 additions and 0 deletions

View File

@ -1,17 +1,23 @@
package org.gcube.informationsystem.registry.impl.contexts;
import java.io.StringWriter;
import java.rmi.RemoteException;
import java.util.Hashtable;
import java.util.List;
import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.faults.GCUBEFault;
import static org.gcube.common.core.contexts.GHNContext.Mode;
import org.gcube.common.core.informationsystem.client.AtomicCondition;
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.GCUBERIQuery;
import org.gcube.common.core.informationsystem.publisher.ISLocalPublisher;
import org.gcube.common.core.informationsystem.publisher.ISPublisher;
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.GCUBEResource;
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.state.RegistryFactoryResource;
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();
this.subscribeToLocalRegistrationEvents();
}
@ -285,5 +296,78 @@ public class ServiceContext extends GCUBEServiceContext {
protected boolean 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);
}
}