This commit is contained in:
Lucio Lelii 2008-11-28 19:00:40 +00:00
parent 7f0a5355d8
commit 97279c10ad
5 changed files with 62 additions and 21 deletions

View File

@ -32,12 +32,12 @@
</Dependencies>
<GARArchive>org.gcube.informationsystem.registry.gar</GARArchive>
<PortType>
<Name>gcube/informationsystem/registry/registryFactory</Name>
<Name>gcube/informationsystem/registry/RegistryFactory</Name>
<Security/>
<WSDL/>
</PortType>
<PortType>
<Name>gcube/informationsystem/registry/registry</Name>
<Name>gcube/informationsystem/registry/Registry</Name>
<Security/>
<WSDL/>
</PortType>

View File

@ -13,7 +13,10 @@ import java.util.Collections;
import java.util.List;
import org.apache.axis.components.uuid.UUIDGen;
import org.apache.axis.components.uuid.UUIDGenFactory;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.faults.GCUBEFault;
import org.gcube.common.core.informationsystem.notifier.ISNotifier;
import org.gcube.common.core.informationsystem.publisher.ISPublisherException;
import org.gcube.common.core.resources.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.resources.service.Package.GHNRequirement;
@ -172,8 +175,13 @@ 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);
if (resource.getType().compareTo(GCUBEHostingNode.TYPE)!=0){
GCUBEScope tmpScope= ServiceContext.getContext().getScope().getType() == GCUBEScope.Type.VRE ? ServiceContext.getContext().getScope().getEnclosingScope() : ServiceContext.getContext().getScope();
if(!ServiceContext.threadTable.get(tmpScope.getName()).getStack().contains(presource)){
ServiceContext.threadTable.get(tmpScope.getName()).getStack().add(presource);
logger.trace("Adding resource to EliminatePoolingThread "+presource.getGCubeResource().getID());
}
}
}
catch (Exception ex) {
String msg = "Error creating Resource";
@ -242,7 +250,15 @@ public class RegistryFactory{
try {
resource = ResourceType.valueOf(mess.getType()).getResourceClass();
resource.load(new StringReader(xmlProfile));
getProfileResource(ID).updateResource(resource);
ProfileResource pr= getProfileResource(ID);
pr.updateResource(resource);
if (resource.getType().compareTo(GCUBEHostingNode.TYPE)!=0){
GCUBEScope tmpScope= ServiceContext.getContext().getScope().getType() == GCUBEScope.Type.VRE ? ServiceContext.getContext().getScope().getEnclosingScope() : ServiceContext.getContext().getScope();
if(!ServiceContext.threadTable.get(tmpScope.getName()).getStack().contains(pr)){
ServiceContext.threadTable.get(tmpScope.getName()).getStack().add(pr);
logger.trace("Adding resource to EliminatePoolingThread "+pr.getGCubeResource().getID());
}
}
}
catch (Exception e) {
logger.error("Error updating profile for ID "+ e);
@ -314,6 +330,7 @@ public class RegistryFactory{
try{
ProfileContext.getContext().getWSHome().remove(ProfileContext.getContext().makeKey(ID));
logger.info(" Resource Destroyed");
}
catch (Exception e) {
@ -334,6 +351,7 @@ public class RegistryFactory{
logger.warn("Error updating counting info for resource with ID " + ID ,e);
}
}
return new RemoveResourceResponse();
}

View File

@ -1,6 +1,7 @@
package org.gcube.informationsystem.registry.impl.contexts;
import java.util.Hashtable;
import java.util.List;
import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.contexts.GHNContext;
@ -22,6 +23,7 @@ import org.gcube.common.core.utils.handlers.GCUBEScheduledHandler;
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;
/**
@ -34,6 +36,8 @@ public class ServiceContext extends GCUBEServiceContext {
public static final String JNDI_NAME = "gcube/informationsystem/registry";
public static Hashtable<String, EliminatePoolingThread> threadTable= new Hashtable<String, EliminatePoolingThread>();
protected static final ServiceContext cache = new ServiceContext();
protected ISClient client = null;
@ -104,6 +108,7 @@ public class ServiceContext extends GCUBEServiceContext {
protected void onReady() throws Exception {
//switch to the production mode if needed
if (GHNContext.getContext().getMode() == Mode.ROOT)
GHNContext.getContext().setMode(Mode.CONNECTED);
@ -111,6 +116,13 @@ public class ServiceContext extends GCUBEServiceContext {
//creates the single RegistryResource used to raise notifications about profiles' changes
logger.info("Scheduling IS-Registry notification resource...");
for (GCUBEScope scope: ServiceContext.getContext().getStartScopes()){
EliminatePoolingThread ept= new EliminatePoolingThread();
ServiceContext.getContext().setScope(ept, scope);
ept.start();
threadTable.put(scope.getName(), ept);
}
NotificationResourceScheduler scheduler = new NotificationResourceScheduler(20, GCUBEScheduledHandler.Mode.LAZY);
scheduler.setHandled(new GCUBEHandler(){
public void run() throws Exception {

View File

@ -20,6 +20,7 @@ import org.gcube.common.core.resources.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.resources.GCUBERunningInstance;
import org.gcube.common.core.resources.GCUBEService;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.state.GCUBEWSResource;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.RegistryFactory;
@ -43,9 +44,7 @@ public class ProfileResource extends GCUBEWSResource {
private ISPublisher publisher = null;
private ISNotifier notifier= null;
ArrayList<SimpleTopic> listQname = new ArrayList<SimpleTopic>();
//private ISNotifier notifier= null;
protected static final String NotificationProfileRP="NotificationProfile";
@ -110,6 +109,7 @@ public class ProfileResource extends GCUBEWSResource {
if (hasToLive(resource)) this.setTerminationTime(null);
/*
if (hasToLive(resource)) {
//registration of Topic To IS-Notifier
@ -129,7 +129,7 @@ public class ProfileResource extends GCUBEWSResource {
}
}
}
*/
}
/**
@ -226,11 +226,11 @@ public class ProfileResource extends GCUBEWSResource {
e.printStackTrace();
}
/*
if (RegistryFactory.notificationMap.contains(this.getID()))
{
try {
notifier = GHNContext.getImplementation(ISNotifier.class);
notifier.unregisterISNotification(this.getEPR(),listQname,ServiceContext.getContext());
} catch (ISPublisherException e) {
e.printStackTrace();
@ -241,10 +241,11 @@ public class ProfileResource extends GCUBEWSResource {
synchronized(RegistryFactory.notificationMap) {
RegistryFactory.notificationMap.remove(this.getID());
}
}
}*/
try {
publisher.removeWSResource(this,ServiceContext.getContext().getScope());
System.out.println(" "+this.getResourcePropertySet().getScope().get(0));
} catch (ISPublisherException e) {
e.printStackTrace();
}

View File

@ -7,16 +7,19 @@ 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.XMLResult;
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.RegistryFactory;
import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
import org.gcube.informationsystem.registry.impl.state.ProfileResource;
public class EliminatePoolingThread extends Thread {
private static List<ProfileResource> stack = Collections.synchronizedList(new LinkedList<ProfileResource>());
private List<ProfileResource> stack = Collections.synchronizedList(new LinkedList<ProfileResource>());
private static GCUBELog logger = new GCUBELog(EliminatePoolingThread.class.getName());
private static GCUBELog logger = new GCUBELog(RegistryFactory.class.getName());
public void run(){
boolean noErrors= true;
@ -36,9 +39,15 @@ public class EliminatePoolingThread extends Thread {
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();
while (stack.size()>0){
p=stack.remove(stack.size()-1);
query.setExpression("declare namespace is = 'http://gcube-system.org/namespaces/informationsystem/registry';" +
"for $result in collection(\"/db/Profiles\")//Document/Data/is:Profile/Resource where ($result/ID/string() eq '"+p.getGCubeResource().getID()+"') return 1");
List<XMLResult> list= client.execute(query, ServiceContext.getContext().getScope());
if (list.size()>0) try {
ProfileContext.getContext().getWSHome().remove(p.getID());
}catch(Exception e){e.printStackTrace();tmpStack.offer(p);}
else tmpStack.offer(p);
}
@ -46,10 +55,11 @@ public class EliminatePoolingThread extends Thread {
logger.debug("destroyed "+(numRes-tmpStack.size())+" resources ");
stack.addAll(tmpStack);
}
} catch (Exception e) {
logger.error("Cannot continue with thread Excecution "+e);
e.printStackTrace();
noErrors=false;
}
@ -57,8 +67,8 @@ public class EliminatePoolingThread extends Thread {
}
public static synchronized List<ProfileResource> getStack(){
return stack;
public synchronized List<ProfileResource> getStack(){
return this.stack;
}
}