You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2012/02/03 00:01:31 UTC

svn commit: r1239910 - in /incubator/airavata/trunk/modules: commons/common-registry-api/src/main/java/org/apache/airavata/common/registry/api/impl/ commons/registry-api/src/main/java/org/apache/airavata/registry/api/impl/ xbaya-gui/src/main/java/org/a...

Author: samindaw
Date: Thu Feb  2 23:01:30 2012
New Revision: 1239910

URL: http://svn.apache.org/viewvc?rev=1239910&view=rev
Log:
never mind... found it

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
    incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/registrybrowser/nodes/AbstractAiravataTreeNode.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=1239910&r1=1239909&r2=1239910&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 23:01:30 2012
@@ -29,6 +29,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Observable;
+import java.util.Set;
 
 import javax.jcr.Credentials;
 import javax.jcr.Node;
@@ -39,6 +40,10 @@ import javax.jcr.RepositoryException;
 import javax.jcr.RepositoryFactory;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventIterator;
+import javax.jcr.observation.EventListener;
 
 import org.apache.airavata.common.registry.api.Registry;
 import org.apache.airavata.common.registry.api.user.UserManager;
@@ -61,6 +66,7 @@ public class JCRRegistry extends Observa
     private String password;
     private Session defaultSession=null;
     private boolean sessionKeepAlive=false;
+    private EventListener workspaceChangeEventListener;
     
 	private Thread sessionManager;
     private static final int SESSION_TIME_OUT = 60000;
@@ -86,6 +92,53 @@ public class JCRRegistry extends Observa
             setPassword(pass);
             credentials = new SimpleCredentials(getUsername(), new String(pass).toCharArray());
             definiteSessionTimeout();
+            workspaceChangeEventListener=new EventListener() {
+				
+				public void onEvent(EventIterator events) {
+					for(;events.hasNext();){
+						Event event=events.nextEvent();
+						try {
+							String path = event.getPath();
+							synchronized (sessionSynchronousObject) {
+								System.out.println("something happened: " + event.getType() + " " + path);
+								List<Node> nodesToRemove=new ArrayList<Node>();
+								Set<Node> nodeIterator = getSessionNodes().keySet();
+								for (Node node : nodeIterator) {
+									if (node == null) {
+										if (path.equals("/")) {
+											nodesToRemove.add(node);
+										}
+									} else {
+										if (node.getPath().startsWith(path)
+												|| path.startsWith(node
+														.getPath())) {
+											nodesToRemove.add(node);
+										}
+									}
+								}
+								for(Node node:nodesToRemove){
+									getSessionNodes().remove(node);
+								}
+								nodeIterator = getSessionNodeChildren().keySet();
+								nodesToRemove.clear();
+								for (Node node : nodeIterator) {
+									if (node.getPath().startsWith(path)
+											|| path.startsWith(node.getPath())) {
+										nodesToRemove.add(node);
+									}
+								}
+								for(Node node:nodesToRemove){
+									getSessionNodeChildren().remove(node);
+								}
+							}
+							triggerObservers(this);
+						} catch (RepositoryException e) {
+							e.printStackTrace();
+						}
+					}
+					
+				}
+			};
         } catch (ClassNotFoundException e) {
             log.error("Error class path settting", e);
         } catch (RepositoryException e) {
@@ -129,7 +182,7 @@ public class JCRRegistry extends Observa
         setSessionKeepAlive(true);
     	sessionManager=new Thread(new Runnable() {
 			public void run() {
-				while (!isSessionValid() && isSessionKeepAlive()){
+				while (!isSessionInvalid() && isSessionKeepAlive()){
 					try {
 						setSessionKeepAlive(false);
 						Thread.sleep(SESSION_TIME_OUT);
@@ -167,7 +220,8 @@ public class JCRRegistry extends Observa
 	}
 	
 	public Session getSession() throws RepositoryException {
-    	if (isSessionValid()){
+    	if (isSessionInvalid()){
+    		reallyCloseSession(defaultSession);
         	synchronized (sessionSynchronousObject) {
 	    		System.out.println("session created");
 		        Session session = null;
@@ -180,6 +234,7 @@ public class JCRRegistry extends Observa
 		            session = resetSession(session);
 		        }
 		        defaultSession=session;
+				defaultSession.getWorkspace().getObservationManager().addEventListener(getWorkspaceChangeEventListener(), Event.NODE_ADDED|Event.NODE_REMOVED|Event.NODE_MOVED, "/", true, null, null, false);
 		        currentSessionUseCount.put(session, 1);
         	}
 	        setupSessionManagement();
@@ -240,22 +295,30 @@ public class JCRRegistry extends Observa
     }
 
     protected void closeSession(Session session) {
-    	//Do nothing - let the session management thread handle closing the thread
-    	currentSessionUseCount.put(session,currentSessionUseCount.get(session)-1);
-    	if (session!=defaultSession){
-    		reallyCloseSession(session);
-    	}
+    	if (session!=null) {
+			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 && currentSessionUseCount.get(session)==0){
 				if (session != null && session.isLive()) {
-		            session.logout();
+					try {
+						session.getWorkspace().getObservationManager().removeEventListener(getWorkspaceChangeEventListener());
+					} catch (UnsupportedRepositoryOperationException e) {
+						e.printStackTrace();
+					} catch (RepositoryException e) {
+						e.printStackTrace();
+					}
+					session.logout();
 		        }
 				sessionNodes=null;
 				sessionNodeChildren=null;
-				nodeHistory=null;
 				if (session!=defaultSession){
 					currentSessionUseCount.remove(session);
 				}
@@ -263,7 +326,7 @@ public class JCRRegistry extends Observa
     	}
 	}
 
-    private boolean isSessionValid(){
+    private boolean isSessionInvalid(){
     	boolean isValid=false;
     	synchronized (sessionSynchronousObject) {
     		isValid=(defaultSession==null || !defaultSession.isLive());
@@ -330,15 +393,14 @@ public class JCRRegistry extends Observa
 	}
 	
 	protected List<Node> getChildNodes(Node node) throws RepositoryException{
-//		if (!getSessionNodeChildren().containsKey(node) || getNodeHistory().get(node)<node.getBaseVersion().getCreated().getTimeInMillis()){
+		if (!getSessionNodeChildren().containsKey(node)){
 			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);
 	}
 
@@ -349,22 +411,13 @@ public class JCRRegistry extends Observa
 		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 EventListener getWorkspaceChangeEventListener() {
+		return workspaceChangeEventListener;
 	}
 
-	public Map<Node,Long> getNodeHistory() {
-		if (nodeHistory==null){
-			nodeHistory=new HashMap<Node, Long>();
-		}
-		return nodeHistory;
+	public void setWorkspaceChangeEventListener(
+			EventListener workspaceChangeEventListener) {
+		this.workspaceChangeEventListener = workspaceChangeEventListener;
 	}
 
 }

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=1239910&r1=1239909&r2=1239910&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 23:01:30 2012
@@ -149,7 +149,7 @@ public class AiravataJCRRegistry extends
             if (node != null) {
                 node.remove();
                 session.save();
-                triggerObservers(this);
+//                triggerObservers(this);
             }
         } catch (Exception e) {
             throw new ServiceDescriptionRetrieveException(e);
@@ -210,7 +210,7 @@ public class AiravataJCRRegistry extends
             if (node != null) {
                 node.remove();
                 session.save();
-                triggerObservers(this);
+//                triggerObservers(this);
             }
         } catch (Exception e) {
             throw new HostDescriptionRetrieveException(e);
@@ -263,7 +263,7 @@ public class AiravataJCRRegistry extends
             session.save();
 
             result = node.getIdentifier();
-            triggerObservers(this);
+//            triggerObservers(this);
         } catch (Exception e) {
             System.out.println(e);
             throw new RegistryException("Error while saving host description!!!", e);
@@ -284,7 +284,7 @@ public class AiravataJCRRegistry extends
             session.save();
 
             result = node.getIdentifier();
-            triggerObservers(this);
+//            triggerObservers(this);
         } catch (Exception e) {
             System.out.println(e);
             throw new RegistryException("Error while saving service description!!!", e);
@@ -307,7 +307,7 @@ public class AiravataJCRRegistry extends
             session.save();
 
             result = appName.getIdentifier();
-            triggerObservers(this);
+//            triggerObservers(this);
         } catch (Exception e) {
             System.out.println(e);
             throw new RegistryException("Error while saving deployment description!!!", e);
@@ -443,7 +443,7 @@ public class AiravataJCRRegistry extends
             }
             if (found) {
                 session.save();
-                triggerObservers(this);
+//                triggerObservers(this);
             }
         } catch (Exception e) {
             throw new DeploymentDescriptionRetrieveException(e);
@@ -604,7 +604,7 @@ public class AiravataJCRRegistry extends
                 gfacDataNode.setProperty(propertyName, gfacURL + ";" + timestamp.getTime());
                 session.save();
             }
-            triggerObservers(this);
+//            triggerObservers(this);
         } catch (Exception e) {
             System.out.println(e);
             throw new RegistryException("Error while saving GFac Descriptor to the registry!!!", e);
@@ -625,7 +625,7 @@ public class AiravataJCRRegistry extends
             if (prop != null) {
                 prop.setValue((String) null);
                 session.save();
-                triggerObservers(this);
+//                triggerObservers(this);
             }
         } catch (Exception e) {
             System.out.println(e);
@@ -675,7 +675,7 @@ public class AiravataJCRRegistry extends
             session.save();
 
             result = node.getIdentifier();
-            triggerObservers(this);
+//            triggerObservers(this);
         } catch (Exception e) {
             System.out.println(e);
             throw new RegistryException("Error while saving workflow output to the registry!!!", e);
@@ -762,7 +762,7 @@ public class AiravataJCRRegistry extends
             workflowNode.setProperty("Description", resourceDesc);
             workflowNode.setProperty("Type", REGISTRY_TYPE_WORKFLOW);
             session.save();
-            triggerObservers(this);
+//            triggerObservers(this);
         } catch (Exception e) {
             throw new RegistryException("Error while saving workflow to the registry!!!", e);
         } finally {
@@ -780,7 +780,7 @@ public class AiravataJCRRegistry extends
             if (result != null) {
                 result.remove();
                 session.save();
-                triggerObservers(this);
+//                triggerObservers(this);
             }
         } catch (Exception e) {
             throw new RegistryException("Error while deleting workflow from registry!!!", e);

Modified: incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/registrybrowser/nodes/AbstractAiravataTreeNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/registrybrowser/nodes/AbstractAiravataTreeNode.java?rev=1239910&r1=1239909&r2=1239910&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/registrybrowser/nodes/AbstractAiravataTreeNode.java (original)
+++ incubator/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/registrybrowser/nodes/AbstractAiravataTreeNode.java Thu Feb  2 23:01:30 2012
@@ -205,10 +205,10 @@ public abstract class AbstractAiravataTr
     }
 
     protected void reloadTreeNode(JTree tree, TreeNode node) {
-        TreePath selectionPath = tree.getSelectionPath();
-        ((DefaultTreeModel) tree.getModel()).nodeChanged(node);
-        ((DefaultTreeModel) tree.getModel()).reload(node);
-        tree.expandPath(selectionPath);
+//        TreePath selectionPath = tree.getSelectionPath();
+//        ((DefaultTreeModel) tree.getModel()).nodeChanged(node);
+//        ((DefaultTreeModel) tree.getModel()).reload(node);
+//        tree.expandPath(selectionPath);
     }
 
     public abstract String getActionCaption(AbstractBrowserActionItem action);