incubator-airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From samin...@apache.org
Subject svn commit: r1239868 - in /incubator/airavata/trunk/modules/commons: common-registry-api/src/main/java/org/apache/airavata/common/registry/api/impl/JCRRegistry.java registry-api/src/main/java/org/apache/airavata/registry/api/impl/AiravataJCRRegistry.java
Date Thu, 02 Feb 2012 21:38:07 GMT
Author: samindaw
Date: Thu Feb  2 21:38:07 2012
New Revision: 1239868

URL: http://svn.apache.org/viewvc?rev=1239868&view=rev
Log:
Updating the JCRRegistry api implementation to support reuse session variables & nodes
based on a renewable and expiring ttl
TODO: need to cache node children when node children are requested (this is not done yet bcos
there is no way to know if the node children/properties changed in order to figure-out to
throwaway the cache and retrieve the data again)

Modified:
    incubator/airavata/trunk/modules/commons/common-registry-api/src/main/java/org/apache/airavata/common/registry/api/impl/JCRRegistry.java
    incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/impl/AiravataJCRRegistry.java

Modified: incubator/airavata/trunk/modules/commons/common-registry-api/src/main/java/org/apache/airavata/common/registry/api/impl/JCRRegistry.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/common-registry-api/src/main/java/org/apache/airavata/common/registry/api/impl/JCRRegistry.java?rev=1239868&r1=1239867&r2=1239868&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/commons/common-registry-api/src/main/java/org/apache/airavata/common/registry/api/impl/JCRRegistry.java
(original)
+++ incubator/airavata/trunk/modules/commons/common-registry-api/src/main/java/org/apache/airavata/common/registry/api/impl/JCRRegistry.java
Thu Feb  2 21:38:07 2012
@@ -24,11 +24,15 @@ package org.apache.airavata.common.regis
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Observable;
 
 import javax.jcr.Credentials;
 import javax.jcr.Node;
+import javax.jcr.NodeIterator;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
@@ -55,9 +59,17 @@ public class JCRRegistry extends Observa
     private Class registryRepositoryFactory;
     private Map<String,String> connectionMap;
     private String password;
-
+    private Session defaultSession=null;
+    private boolean sessionKeepAlive=false;
+    
+	private Thread sessionManager;
+    private static final int SESSION_TIME_OUT = 60000;
+    private static final int DEFINITE_SESSION_TIME_OUT = 300000;
     private static Logger log = LoggerFactory.getLogger(JCRRegistry.class);
-
+    private Map<Node,Map<String,Node>> sessionNodes;
+    private Map<Node,List<Node>> sessionNodeChildren;
+    private Map<Session,Integer> currentSessionUseCount=new HashMap<Session, Integer>();
+    
     public JCRRegistry(URI repositoryURI, String className, String user, String pass, Map<String,
String> map)
             throws RepositoryException {
         try {
@@ -73,6 +85,7 @@ public class JCRRegistry extends Observa
             setUsername(user);
             setPassword(pass);
             credentials = new SimpleCredentials(getUsername(), new String(pass).toCharArray());
+            definiteSessionTimeout();
         } catch (ClassNotFoundException e) {
             log.error("Error class path settting", e);
         } catch (RepositoryException e) {
@@ -82,23 +95,101 @@ public class JCRRegistry extends Observa
             log.error("Error init", e);
         }
     }
+    
+    private void definiteSessionTimeout(){
+    	Thread m=new Thread(new Runnable() {
+			public void run() {
+				while (true){
+					int timeoutCount=0;
+					int shortStep=10000;
+					Session currentSession=defaultSession;
+					while(timeoutCount<DEFINITE_SESSION_TIME_OUT){
+						try {
+							Thread.sleep(shortStep);
+						} catch (InterruptedException e) {
+							//life sucks anyway, so who cares if this exception is thrown
+						}
+						timeoutCount=timeoutCount+shortStep;
+						if (currentSession!=defaultSession){
+							//reset start from begining since its a new session
+							currentSession=defaultSession;
+							timeoutCount=0;
+						}
+					}
+					reallyCloseSession(defaultSession);
+				}
+				
+			}
+		});
+    	m.start();
+    }
+    
+    private void setupSessionManagement(){
+    	stopSessionManager();
+        setSessionKeepAlive(true);
+    	sessionManager=new Thread(new Runnable() {
+			public void run() {
+				while (!isSessionValid() && isSessionKeepAlive()){
+					try {
+						setSessionKeepAlive(false);
+						Thread.sleep(SESSION_TIME_OUT);
+					} catch (InterruptedException e) {
+						//no issue
+					}
+				}
+				reallyCloseSession(defaultSession);
+			}
+		});
+    	sessionManager.start();
+    }
+    
+    private void stopSessionManager(){
+    	if (sessionManager!=null) {
+			sessionManager.interrupt();
+		}
+    }
+    protected boolean isSessionKeepAlive() {
+		return sessionKeepAlive;
+	}
 
-    public JCRRegistry(Repository repo, Credentials credentials) {
+	public JCRRegistry(Repository repo, Credentials credentials) {
         this.repository = repo;
         this.credentials = credentials;
     }
 
-    public Session getSession() throws RepositoryException {
-        Session session = null;
-        try {
-            session = repository.login(credentials);
-            if (session == null) {
-                session = resetSession(session);
-            }
-        } catch (Exception e) {
-            session = resetSession(session);
-        }
-        return session;
+	protected Node getRootNode(Session session) throws RepositoryException {
+		String ROOT_NODE_TEXT = "root";
+		if (!getSessionNodes().containsKey(null)){
+			getSessionNodes().put(null, new HashMap<String, Node>());
+			getSessionNodes().get(null).put(ROOT_NODE_TEXT, session.getRootNode());
+		}
+		return getOrAddNode(null, ROOT_NODE_TEXT);
+	}
+	
+	public Session getSession() throws RepositoryException {
+    	if (isSessionValid()){
+        	synchronized (sessionSynchronousObject) {
+	    		System.out.println("session created");
+		        Session session = null;
+		        try {
+		            session = repository.login(credentials);
+		            if (session == null) {
+		                session = resetSession(session);
+		            }
+		        } catch (Exception e) {
+		            session = resetSession(session);
+		        }
+		        defaultSession=session;
+		        currentSessionUseCount.put(session, 1);
+        	}
+	        setupSessionManagement();
+    	}else{
+            setSessionKeepAlive(true);
+            synchronized (sessionSynchronousObject) {
+		        currentSessionUseCount.put(defaultSession, currentSessionUseCount.get(defaultSession)+1);
+        	}
+    	}
+        return defaultSession;
     }
 
     protected Session resetSession(Session session){
@@ -125,9 +216,19 @@ public class JCRRegistry extends Observa
     }
 
     protected Node getOrAddNode(Node node, String name) throws RepositoryException {
+    	Map<Node, Map<String, Node>> sessionNodes = getSessionNodes();
+    	if (sessionNodes.containsKey(node)){
+    		if (sessionNodes.get(node)!=null && sessionNodes.get(node).containsKey(name)){
+    			return sessionNodes.get(node).get(name);
+    		}
+    	}else{
+    		sessionNodes.put(node,new HashMap<String, Node>());
+    	}
         Node node1 = null;
         try {
+        	System.out.println("node extracted");
             node1 = node.getNode(name);
+            sessionNodes.get(node).put(name, node1);
         } catch (PathNotFoundException pnfe) {
             node1 = node.addNode(name);
         } catch (RepositoryException e) {
@@ -139,11 +240,38 @@ public class JCRRegistry extends Observa
     }
 
     protected void closeSession(Session session) {
-        if (session != null && session.isLive()) {
-            session.logout();
-        }
+    	//Do nothing - let the session management thread handle closing the thread
+    	currentSessionUseCount.put(session,currentSessionUseCount.get(session)-1);
+    	if (session!=defaultSession){
+    		reallyCloseSession(session);
+    	}
+    }
+
+    protected void reallyCloseSession(Session session) {
+    	synchronized (sessionSynchronousObject) {
+    		if (currentSessionUseCount.get(session)==0){
+				if (session != null && session.isLive()) {
+		            session.logout();
+		        }
+				sessionNodes=null;
+				sessionNodeChildren=null;
+				nodeHistory=null;
+				if (session!=defaultSession){
+					currentSessionUseCount.remove(session);
+				}
+    		}
+    	}
+	}
+
+    private boolean isSessionValid(){
+    	boolean isValid=false;
+    	synchronized (sessionSynchronousObject) {
+    		isValid=(defaultSession==null || !defaultSession.isLive());
+		}
+    	return isValid;
     }
-
+    
+    private Object sessionSynchronousObject=new Object();
 
     public UserManager getUserManager() {
         return userManager;
@@ -190,5 +318,53 @@ public class JCRRegistry extends Observa
         return repository;
     }
 
+	public void setSessionKeepAlive(boolean sessionKeepAlive) {
+		this.sessionKeepAlive = sessionKeepAlive;
+	}
+
+	private Map<Node,Map<String,Node>> getSessionNodes() {
+		if (sessionNodes==null) {
+			sessionNodes=new HashMap<Node, Map<String,Node>>();
+		}
+		return sessionNodes;
+	}
+	
+	protected List<Node> getChildNodes(Node node) throws RepositoryException{
+//		if (!getSessionNodeChildren().containsKey(node) || getNodeHistory().get(node)<node.getBaseVersion().getCreated().getTimeInMillis()){
+			List<Node> children=new ArrayList<Node>();
+			NodeIterator nodes = node.getNodes();
+			for (;nodes.hasNext();) {
+				children.add(nodes.nextNode());
+			}
+			getSessionNodeChildren().put(node,children);
+//			getNodeHistory().put(node, node.getBaseVersion().getCreated().getTimeInMillis());
+//		}
+		return getSessionNodeChildren().get(node);
+	}
+
+	public Map<Node,List<Node>> getSessionNodeChildren() {
+		if (sessionNodeChildren==null) {
+			sessionNodeChildren=new HashMap<Node, List<Node>>();
+		}
+		return sessionNodeChildren;
+	}
+	
+	private Map<Node,Long> nodeHistory;
+	
+	protected void notifyNodeChange(Node node){
+		if (getSessionNodeChildren().containsKey(node)){
+			getSessionNodeChildren().remove(node);
+		}
+		if (getSessionNodes().containsKey(node)){
+			getSessionNodes().remove(node);
+		}
+	}
+
+	public Map<Node,Long> getNodeHistory() {
+		if (nodeHistory==null){
+			nodeHistory=new HashMap<Node, Long>();
+		}
+		return nodeHistory;
+	}
 
 }

Modified: incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/impl/AiravataJCRRegistry.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/impl/AiravataJCRRegistry.java?rev=1239868&r1=1239867&r2=1239868&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/impl/AiravataJCRRegistry.java
(original)
+++ incubator/airavata/trunk/modules/commons/registry-api/src/main/java/org/apache/airavata/registry/api/impl/AiravataJCRRegistry.java
Thu Feb  2 21:38:07 2012
@@ -23,7 +23,6 @@ package org.apache.airavata.registry.api
 
 import java.net.URI;
 import java.sql.Timestamp;
-import java.text.DateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
@@ -35,7 +34,6 @@ import java.util.TimeZone;
 import java.util.regex.Pattern;
 
 import javax.jcr.Node;
-import javax.jcr.NodeIterator;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.Property;
 import javax.jcr.PropertyIterator;
@@ -105,15 +103,15 @@ public class AiravataJCRRegistry extends
 	}
     
     private Node getServiceNode(Session session) throws RepositoryException {
-        return getOrAddNode(session.getRootNode(), SERVICE_NODE_NAME);
+        return getOrAddNode(getRootNode(session), SERVICE_NODE_NAME);
     }
 
     private Node getDeploymentNode(Session session) throws RepositoryException {
-        return getOrAddNode(session.getRootNode(), DEPLOY_NODE_NAME);
+        return getOrAddNode(getRootNode(session), DEPLOY_NODE_NAME);
     }
 
     private Node getHostNode(Session session) throws RepositoryException {
-        return getOrAddNode(session.getRootNode(), HOST_NODE_NAME);
+        return getOrAddNode(getRootNode(session), HOST_NODE_NAME);
     }
 
 //    public List<HostDescription> getServiceLocation(String serviceId) {
@@ -186,9 +184,8 @@ public class AiravataJCRRegistry extends
             Node deploymentNode = getDeploymentNode(session);
             Node serviceNode = deploymentNode.getNode(serviceId);
             Node hostNode = serviceNode.getNode(hostId);
-            NodeIterator nodes = hostNode.getNodes();
-            for (; nodes.hasNext();) {
-                Node app = nodes.nextNode();
+            List<Node> childNodes = getChildNodes(hostNode);
+            for (Node app:childNodes) {
                 Property prop = app.getProperty(XML_PROPERTY_NAME);
                 result = ApplicationDeploymentDescription.fromXML(prop.getString());
                 break;
@@ -364,9 +361,8 @@ public class AiravataJCRRegistry extends
         try {
             session = getSession();
             Node node = getServiceNode(session);
-            NodeIterator nodes = node.getNodes();
-            for (; nodes.hasNext();) {
-                Node service = nodes.nextNode();
+            List<Node> childNodes = getChildNodes(node);
+            for (Node service:childNodes) {
                 if (nameRegEx.equals("") || service.getName().matches(nameRegEx)) {
                     Property prop = service.getProperty(XML_PROPERTY_NAME);
                     result.add(ServiceDescription.fromXML(prop.getString()));
@@ -386,9 +382,8 @@ public class AiravataJCRRegistry extends
         try {
             session = getSession();
             Node node = getHostNode(session);
-            NodeIterator nodes = node.getNodes();
-            for (; nodes.hasNext();) {
-                Node host = nodes.nextNode();
+            List<Node> childNodes = getChildNodes(node);
+            for (Node host:childNodes) {
                 if (host != null && host.getName().matches(nameRegEx)) {
                     HostDescription hostDescriptor = getHostDescriptor(host);
                     result.add(hostDescriptor);
@@ -408,17 +403,12 @@ public class AiravataJCRRegistry extends
         try {
             session = getSession();
             Node deploymentNode = getDeploymentNode(session);
-            NodeIterator serviceNodes = deploymentNode.getNodes();
-
-            for (; serviceNodes.hasNext();) {
-                Node serviceNode = serviceNodes.nextNode();
-                NodeIterator hostNodes = serviceNode.getNodes();
-
-                for (; hostNodes.hasNext();) {
-                    Node hostNode = hostNodes.nextNode();
-                    NodeIterator nodes = hostNode.getNodes();
-                    for (; nodes.hasNext();) {
-                        Node app = nodes.nextNode();
+            List<Node> childNodes = getChildNodes(deploymentNode);
+            for (Node serviceNode:childNodes) {
+                List<Node> childNodes2 = getChildNodes(serviceNode);
+                for (Node hostNode:childNodes2) {
+                    List<Node> childNodes3 = getChildNodes(hostNode);
+                    for (Node app:childNodes3) {
                         Property prop = app.getProperty(XML_PROPERTY_NAME);
                         result.put(ApplicationDeploymentDescription.fromXML(prop.getString()),
serviceNode.getName()
                                 + "$" + hostNode.getName());
@@ -441,10 +431,9 @@ public class AiravataJCRRegistry extends
             Node deploymentNode = getDeploymentNode(session);
             Node serviceNode = deploymentNode.getNode(serviceName);
             Node hostNode = serviceNode.getNode(hostName);
-            NodeIterator nodes = hostNode.getNodes();
             boolean found = false;
-            for (; nodes.hasNext();) {
-                Node app = nodes.nextNode();
+            List<Node> childNodes = getChildNodes(hostNode);
+            for (Node app:childNodes) {
                 Property prop = app.getProperty(XML_PROPERTY_NAME);
                 ApplicationDeploymentDescription appDesc = ApplicationDeploymentDescription.fromXML(prop.getString());
                 if (appDesc.getType().getApplicationName().getStringValue().matches(applicationName))
{
@@ -472,9 +461,8 @@ public class AiravataJCRRegistry extends
             Node deploymentNode = getDeploymentNode(session);
             Node serviceNode = deploymentNode.getNode(serviceName);
             Node hostNode = serviceNode.getNode(hostName);
-            NodeIterator nodes = hostNode.getNodes();
-            for (; nodes.hasNext();) {
-                Node app = nodes.nextNode();
+            List<Node> childNodes = getChildNodes(hostNode);
+            for (Node app:childNodes) {
                 Property prop = app.getProperty(XML_PROPERTY_NAME);
                 ApplicationDeploymentDescription appDesc = ApplicationDeploymentDescription.fromXML(prop.getString());
                 if (appDesc.getType().getApplicationName().getStringValue().matches(applicationName))
{
@@ -499,14 +487,12 @@ public class AiravataJCRRegistry extends
 			session = getSession();
 			Node deploymentNode = getDeploymentNode(session);
 			Node serviceNode = deploymentNode.getNode(serviceName);
-			NodeIterator hostNodes = serviceNode.getNodes();
-			for(;hostNodes.hasNext();){
-				Node hostNode = hostNodes.nextNode();
+            List<Node> childNodes = getChildNodes(serviceNode);
+            for (Node hostNode:childNodes) {
 				HostDescription hostDescriptor = getHostDescription(hostNode.getName());
 				result.put(hostDescriptor, new ArrayList<ApplicationDeploymentDescription>());
-				NodeIterator nodes = hostNode.getNodes();
-				for (; nodes.hasNext();) {
-					Node app = nodes.nextNode();
+	            List<Node> childNodes2 = getChildNodes(hostNode);
+	            for (Node app:childNodes2) {
 					Property prop = app.getProperty(XML_PROPERTY_NAME);
 					result.get(hostDescriptor).add(ApplicationDeploymentDescription.fromXML(prop.getString()));
 				}
@@ -530,9 +516,8 @@ public class AiravataJCRRegistry extends
             Node deploymentNode = getDeploymentNode(session);
             Node serviceNode = deploymentNode.getNode(serviceName);
             Node hostNode = serviceNode.getNode(hostName);
-            NodeIterator nodes = hostNode.getNodes();
-            for (; nodes.hasNext();) {
-                Node app = nodes.nextNode();
+            List<Node> childNodes = getChildNodes(hostNode);
+            for (Node app:childNodes) {
                 Property prop = app.getProperty(XML_PROPERTY_NAME);
                 result.add(ApplicationDeploymentDescription.fromXML(prop.getString()));
             }
@@ -610,7 +595,7 @@ public class AiravataJCRRegistry extends
             URI uri = new URI(gfacURL);
             String propertyName = uri.getHost() + "-" + uri.getPort();
             session = getSession();
-            Node gfacDataNode = getOrAddNode(session.getRootNode(), GFAC_INSTANCE_DATA);
+            Node gfacDataNode = getOrAddNode(getRootNode(session), GFAC_INSTANCE_DATA);
             try {
                 Property prop = gfacDataNode.getProperty(propertyName);
                 prop.setValue(gfacURL + ";" + timestamp.getTime());
@@ -635,7 +620,7 @@ public class AiravataJCRRegistry extends
             URI uri = new URI(gfacURL);
             String propertyName = uri.getHost() + "-" + uri.getPort();
             session = getSession();
-            Node gfacDataNode = getOrAddNode(session.getRootNode(), GFAC_INSTANCE_DATA);
+            Node gfacDataNode = getOrAddNode(getRootNode(session), GFAC_INSTANCE_DATA);
             Property prop = gfacDataNode.getProperty(propertyName);
             if (prop != null) {
                 prop.setValue((String) null);
@@ -658,7 +643,7 @@ public class AiravataJCRRegistry extends
         Timestamp timestamp = new Timestamp(today.getTime());
         try {
             session = getSession();
-            Node gfacNode = getOrAddNode(session.getRootNode(), GFAC_INSTANCE_DATA);
+            Node gfacNode = getOrAddNode(getRootNode(session), GFAC_INSTANCE_DATA);
             PropertyIterator propertyIterator = gfacNode.getProperties();
             while (propertyIterator.hasNext()) {
                 Property property = propertyIterator.nextProperty();
@@ -681,7 +666,7 @@ public class AiravataJCRRegistry extends
         String result = null;
         try {
             session = getSession();
-            Node outputNode = getOrAddNode(session.getRootNode(), OUTPUT_NODE_NAME);
+            Node outputNode = getOrAddNode(getRootNode(session), OUTPUT_NODE_NAME);
             Node node = getOrAddNode(outputNode, workflowId);
             for (int i = 0; i < parameters.size(); i++) {
                 node.setProperty(String.valueOf(i), parameters.get(i).toXML());
@@ -705,7 +690,7 @@ public class AiravataJCRRegistry extends
         ArrayList<ActualParameter> result = new ArrayList<ActualParameter>();
         try {
             session = getSession();
-            Node outputNode = getOrAddNode(session.getRootNode(), OUTPUT_NODE_NAME);
+            Node outputNode = getOrAddNode(getRootNode(session), OUTPUT_NODE_NAME);
             Node node = outputNode.getNode(workflowId);
 
             PropertyIterator it = node.getProperties();
@@ -727,16 +712,14 @@ public class AiravataJCRRegistry extends
         Map<QName, Node> workflowList = new HashMap<QName, Node>();
         try {
             session = getSession();
-            Node workflowListNode = getOrAddNode(getOrAddNode(session.getRootNode(), WORKFLOWS),
PUBLIC);
-            NodeIterator iterator = workflowListNode.getNodes();
-            while (iterator.hasNext()) {
-                Node nextNode = iterator.nextNode();
+            Node workflowListNode = getOrAddNode(getOrAddNode(getRootNode(session), WORKFLOWS),
PUBLIC);
+            List<Node> childNodes = getChildNodes(workflowListNode);
+            for (Node nextNode:childNodes) {
                 workflowList.put(new QName(nextNode.getName()), nextNode);
             }
-            workflowListNode = getOrAddNode(getOrAddNode(session.getRootNode(), WORKFLOWS),
userName);
-            iterator = workflowListNode.getNodes();
-            while (iterator.hasNext()) {
-                Node nextNode = iterator.nextNode();
+            workflowListNode = getOrAddNode(getOrAddNode(getRootNode(session), WORKFLOWS),
userName);
+            childNodes = getChildNodes(workflowListNode);
+            for (Node nextNode:childNodes) {
                 workflowList.put(new QName(nextNode.getName()), nextNode);
             }
 
@@ -751,7 +734,7 @@ public class AiravataJCRRegistry extends
         Node result = null;
         try {
             session = getSession();
-            Node workflowListNode = getOrAddNode(getOrAddNode(session.getRootNode(), WORKFLOWS),
userName);
+            Node workflowListNode = getOrAddNode(getOrAddNode(getRootNode(session), WORKFLOWS),
userName);
             result = getOrAddNode(workflowListNode, templateID.getLocalPart());
         } catch (Exception e) {
             throw new RegistryException("Error while retrieving workflow from registry!!!",
e);
@@ -764,7 +747,7 @@ public class AiravataJCRRegistry extends
         Session session = null;
         try {
             session = getSession();
-            Node workflowListNode = getOrAddNode(session.getRootNode(), WORKFLOWS);
+            Node workflowListNode = getOrAddNode(getRootNode(session), WORKFLOWS);
             Node workflowNode = null;
             if (isMakePublic) {
                 workflowNode = getOrAddNode(getOrAddNode(workflowListNode, PUBLIC), workflowName);
@@ -792,7 +775,7 @@ public class AiravataJCRRegistry extends
         Session session = null;
         try {
             session = getSession();
-            Node workflowListNode = getOrAddNode(getOrAddNode(session.getRootNode(), WORKFLOWS),
userName);
+            Node workflowListNode = getOrAddNode(getOrAddNode(getRootNode(session), WORKFLOWS),
userName);
             Node result = getOrAddNode(workflowListNode, resourceID.getLocalPart());
             if (result != null) {
                 result.remove();
@@ -852,15 +835,13 @@ public class AiravataJCRRegistry extends
         try {
             session = getSession();
             Node experimentsNode = getWorkflowDataNode(session);
-            NodeIterator experimentNodes = experimentsNode.getNodes();
-            for (; experimentNodes.hasNext();) {
-                Node experimentNode = experimentNodes.nextNode();
+            List<Node> childNodes = getChildNodes(experimentsNode);
+            for (Node experimentNode:childNodes) {
                 if (experimentIdRegEx != null && !experimentNode.getName().matches(experimentIdRegEx))
{
                     continue;
                 }
-                NodeIterator workflowNodes = experimentNode.getNodes();
-                for (; workflowNodes.hasNext();) {
-                    Node workflowNode = workflowNodes.nextNode();
+                List<Node> childNodes2 = getChildNodes(experimentNode);
+                for (Node workflowNode:childNodes2) {
                     String workflowName = null;
                     if (workflowNode.hasProperty(PROPERTY_WORKFLOW_NAME)) {
 						workflowName = workflowNode.getProperty(
@@ -870,9 +851,8 @@ public class AiravataJCRRegistry extends
 							continue;
 						}
 					}
-					NodeIterator serviceNodes = workflowNode.getNodes();
-                    for (; serviceNodes.hasNext();) {
-                        Node serviceNode = serviceNodes.nextNode();
+                    List<Node> childNodes3 = getChildNodes(workflowNode);
+                    for (Node serviceNode:childNodes3) {
                         if (nodeNameRegEx != null && !serviceNode.getName().matches(nodeNameRegEx))
{
                             continue;
                         }
@@ -964,7 +944,7 @@ public class AiravataJCRRegistry extends
 
 	private Node getWorkflowDataNode(Session session)
 			throws RepositoryException {
-		return getOrAddNode(session.getRootNode(), WORKFLOW_DATA);
+		return getOrAddNode(getRootNode(session), WORKFLOW_DATA);
 	}
     
 	public boolean saveWorkflowExecutionOutput(String experimentId,String outputNodeName,String
output) throws RegistryException{
@@ -1035,10 +1015,10 @@ public class AiravataJCRRegistry extends
     private List<String> getMatchingExperimentIds(String regex,Session session)throws
RepositoryException{
         Node orAddNode = getWorkflowDataNode(session);
         List<String> matchList = new ArrayList<String>();
-        NodeIterator nodes = orAddNode.getNodes();
+        
         Pattern compile = Pattern.compile(regex);
-        while(nodes.hasNext()){
-            Node node = nodes.nextNode();
+        List<Node> childNodes = getChildNodes(orAddNode);
+        for (Node node:childNodes) {
             String name = node.getName();
             if(compile.matcher(name).find()){
                 matchList.add(name);



Mime
View raw message