Improving the local resources management
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@34441 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
274f1dba36
commit
91147638bd
|
@ -19,12 +19,14 @@ import org.gcube.common.core.utils.events.GCUBEProducer;
|
|||
import org.gcube.common.core.utils.events.GCUBETopic;
|
||||
import org.gcube.common.core.utils.handlers.GCUBEHandler;
|
||||
import org.gcube.common.core.utils.handlers.GCUBEScheduledHandler;
|
||||
import org.gcube.informationsystem.registry.impl.local.LocalProfileConsumerImpl;
|
||||
import org.gcube.informationsystem.registry.impl.porttypes.RegistryFactory;
|
||||
import org.gcube.informationsystem.registry.impl.porttypes.ResourceRegistration;
|
||||
import org.gcube.informationsystem.registry.impl.resourcemanagement.EliminatePoolingThread;
|
||||
import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource;
|
||||
import org.gcube.informationsystem.registry.stubs.CreateResourceMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.UpdateResourceMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.resourceregistration.CreateMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.resourceregistration.RemoveMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.resourceregistration.UpdateMessage;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -164,100 +166,13 @@ public class ServiceContext extends GCUBEServiceContext {
|
|||
*/
|
||||
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(final GCUBEResource resource, final GCUBEScope scope) {
|
||||
logger.debug("onProfileRegistered event received in scope " + scope );
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
ServiceContext.this.waitUntilReady();
|
||||
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());
|
||||
//crm.setScopes(new String[] {scope.toString()});
|
||||
factory.createResource(crm);
|
||||
} catch (Exception e) {
|
||||
logger.error("cannot handle the create resource event"+e);
|
||||
}
|
||||
}
|
||||
|
||||
}.start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer#onProfileRemoved(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected void onProfileRemoved(final String resourceID, final String type, final GCUBEScope scope) {
|
||||
logger.debug("onProfileRemoved event received" );
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
ServiceContext.this.waitUntilReady();
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer#onProfileUpdated(org.gcube.common.core.resources.GCUBEResource)
|
||||
*/
|
||||
@Override
|
||||
protected void onProfileUpdated(final GCUBEResource resource, final GCUBEScope scope) {
|
||||
logger.debug("onProfileUpdated event received" );
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
ServiceContext.this.waitUntilReady();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
pub.subscribeLocalProfileEvents(cons);
|
||||
logger.debug("Subscribing IS-Registry to local profile events");
|
||||
pub.subscribeLocalProfileEvents(new LocalProfileConsumerImpl());
|
||||
}
|
||||
|
||||
private void waitUntilReady() {
|
||||
while (true) {
|
||||
if (ServiceContext.getContext().getStatus() != Status.READIED)
|
||||
public void waitUntilReady() {
|
||||
while (true) {
|
||||
if (ServiceContext.getContext().getStatus() == Status.READIED)
|
||||
break;
|
||||
else
|
||||
try {
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
package org.gcube.informationsystem.registry.impl.local;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
|
||||
import org.gcube.informationsystem.registry.impl.porttypes.ResourceRegistration;
|
||||
import org.gcube.informationsystem.registry.stubs.resourceregistration.CreateMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.resourceregistration.RemoveMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.resourceregistration.UpdateMessage;
|
||||
|
||||
public class LocalProfileConsumerImpl extends LocalProfileConsumer {
|
||||
|
||||
private final static GCUBELog logger = new GCUBELog(LocalProfileConsumerImpl.class);
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer#onProfileRegistered(org.gcube.common.core.resources.GCUBEResource)
|
||||
*/
|
||||
@Override
|
||||
protected void onProfileRegistered(final GCUBEResource resource, final GCUBEScope scope) {
|
||||
logger.debug("onProfileRegistered event received in scope " + scope );
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
ServiceContext.getContext().waitUntilReady();
|
||||
ResourceRegistration factory= new ResourceRegistration();
|
||||
try {
|
||||
ServiceContext.getContext().setScope(scope);
|
||||
CreateMessage crm = new CreateMessage();
|
||||
StringWriter writer = new StringWriter();
|
||||
resource.store(writer);
|
||||
crm.setProfile(writer.toString());
|
||||
crm.setType(resource.getType());
|
||||
//crm.setScopes(new String[] {scope.toString()});
|
||||
logger.debug("Creating resource ");
|
||||
factory.create(crm);
|
||||
} catch (Exception e) {
|
||||
logger.error("cannot handle the create resource event"+e);
|
||||
}
|
||||
}
|
||||
|
||||
}.start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer#onProfileRemoved(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected void onProfileRemoved(final String resourceID, final String type, final GCUBEScope scope) {
|
||||
logger.debug("onProfileRemoved event received" );
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
ServiceContext.getContext().waitUntilReady();
|
||||
ServiceContext.getContext().setScope(scope);
|
||||
ResourceRegistration factory= new ResourceRegistration();
|
||||
RemoveMessage rrm= new RemoveMessage();
|
||||
rrm.setType(type);
|
||||
rrm.setUniqueID(resourceID);
|
||||
try {
|
||||
factory.remove(rrm);
|
||||
} catch (Exception e) {
|
||||
logger.error("cannot handle the remove resource event"+e);
|
||||
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.common.core.informationsystem.publisher.ISLocalPublisher.LocalProfileConsumer#onProfileUpdated(org.gcube.common.core.resources.GCUBEResource)
|
||||
*/
|
||||
@Override
|
||||
protected void onProfileUpdated(final GCUBEResource resource, final GCUBEScope scope) {
|
||||
logger.debug("onProfileUpdated event received" );
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
ServiceContext.getContext().waitUntilReady();
|
||||
ServiceContext.getContext().setScope(scope);
|
||||
ResourceRegistration factory= new ResourceRegistration();
|
||||
try {
|
||||
UpdateMessage urm= new UpdateMessage();
|
||||
StringWriter writer = new StringWriter();
|
||||
resource.store(writer);
|
||||
urm.setXmlProfile(writer.toString());
|
||||
urm.setType(resource.getType());
|
||||
urm.setUniqueID(resource.getID());
|
||||
factory.update(urm);
|
||||
} catch (Exception e) {
|
||||
logger.error("cannot handle the update resource event"+e);
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue