This commit is contained in:
Lucio Lelii 2008-11-24 17:50:17 +00:00
parent e1fc80d8bb
commit 7f0a5355d8
4 changed files with 75 additions and 3 deletions

View File

@ -16,6 +16,7 @@ import org.apache.axis.components.uuid.UUIDGenFactory;
import org.gcube.common.core.faults.GCUBEFault;
import org.gcube.common.core.resources.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.resources.service.Package.GHNRequirement;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.state.GCUBEWSResourceKey;
import org.gcube.common.core.utils.events.GCUBEEvent;
@ -25,6 +26,7 @@ import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
import org.gcube.informationsystem.registry.impl.state.ProfileResource;
import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource;
import org.gcube.informationsystem.registry.impl.util.EliminatePoolingThread;
import org.gcube.informationsystem.registry.impl.util.ProfileManager;
import org.gcube.informationsystem.registry.impl.util.RegistryUtil;
import org.gcube.informationsystem.registry.stubs.CreateResourceMessage;
@ -170,6 +172,8 @@ public class RegistryFactory{
logger.debug(resource.getID()+" Creating the stateful resource for " + resource.getID());
ProfileResource presource = (ProfileResource) ProfileContext.getContext().getWSHome().create(ProfileContext.getContext().makeKey(resource.getID()),resource);
presource.getPersistenceDelegate().store(presource);
if (resource.getType().compareTo(GCUBEHostingNode.TYPE)!=0)
EliminatePoolingThread.getStack().add(presource);
}
catch (Exception ex) {
String msg = "Error creating Resource";
@ -193,6 +197,9 @@ public class RegistryFactory{
} catch (Exception e) {
logger.error("Persistence failed for " + resource.getID(), e);
}
logger.info("Profile " + resource.getID() + " created ");
return writer.toString();
}

View File

@ -52,6 +52,7 @@ public class ServiceContext extends GCUBEServiceContext {
protected class NotificationResourceScheduler extends GCUBEScheduledHandler {
public NotificationResourceScheduler(long interval, Mode mode) {
super(interval, mode);
}
@ -71,10 +72,7 @@ public class ServiceContext extends GCUBEServiceContext {
}
private ServiceContext() {}
/**
@ -105,6 +103,7 @@ public class ServiceContext extends GCUBEServiceContext {
@Override
protected void onReady() throws Exception {
//switch to the production mode if needed
if (GHNContext.getContext().getMode() == Mode.ROOT)
GHNContext.getContext().setMode(Mode.CONNECTED);

View File

@ -27,6 +27,8 @@ import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
import org.globus.wsrf.ResourceException;
import org.globus.wsrf.impl.SimpleTopic;
import org.oasis.wsrf.properties.GetMultipleResourcePropertiesResponse;
import org.oasis.wsrf.properties.GetMultipleResourceProperties_Element;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;

View File

@ -0,0 +1,64 @@
package org.gcube.informationsystem.registry.impl.util;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.informationsystem.client.ISClient;
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.state.ProfileResource;
public class EliminatePoolingThread extends Thread {
private static List<ProfileResource> stack = Collections.synchronizedList(new LinkedList<ProfileResource>());
private static GCUBELog logger = new GCUBELog(EliminatePoolingThread.class.getName());
public void run(){
boolean noErrors= true;
while(noErrors){
try {
this.sleep(30000);
} catch (InterruptedException e) {}
LinkedList<ProfileResource> tmpStack = new LinkedList<ProfileResource>();
ISClient client;
GCUBEGenericQuery query;
try {
client = GHNContext.getImplementation(ISClient.class);
query = client.getQuery(GCUBEGenericQuery.class);
ProfileResource p;
synchronized (stack) {
int numRes= stack.size();
while ((p=stack.remove(stack.size()-1))!=null){
query.setExpression("declare namespace is = 'http://gcube-system.org/namespaces/informationsystem/registry';for $result in collection(\"/db/Profile\")//Document/Data/is:Profile/Resource where $result/ID/string() eq '"+p.getID().getValue()+"' return true");
if (client.execute(query, GCUBEScope.getScope(p.getResourcePropertySet().getScope().get(0))).size()>0) p.remove();
else tmpStack.offer(p);
}
logger.debug("cannot destroy "+tmpStack.size()+" resources retrying in 30 seconds");
logger.debug("destroyed "+(numRes-tmpStack.size())+" resources ");
stack.addAll(tmpStack);
}
} catch (Exception e) {
logger.error("Cannot continue with thread Excecution "+e);
noErrors=false;
}
}
}
public static synchronized List<ProfileResource> getStack(){
return stack;
}
}