Improve encapsulation and synchronization of logging.
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 13 Jan 2013 16:53:31 +0000 (16:53 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 13 Jan 2013 16:53:31 +0000 (16:53 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@6023 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionProcess.java
runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrProcessThread.java

index 641132d6accfc2563b5e6143c84b9ca5d22d444d..d96abf0972cbf94f3d5540d4328d22f0365591f4 100644 (file)
@@ -20,6 +20,7 @@ import java.util.GregorianCalendar;
 import java.util.List;
 
 import javax.jcr.Node;
+import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 
 import org.apache.commons.logging.Log;
@@ -33,7 +34,7 @@ import org.argeo.slc.jcr.SlcTypes;
 
 /** Execution process implementation based on a JCR node. */
 public class JcrExecutionProcess implements ExecutionProcess, SlcNames {
-       private Log log = LogFactory.getLog(JcrExecutionProcess.class);
+       private final static Log log = LogFactory.getLog(JcrExecutionProcess.class);
        private final Node node;
 
        private Long nextLogLine = 1l;
@@ -42,7 +43,7 @@ public class JcrExecutionProcess implements ExecutionProcess, SlcNames {
                this.node = node;
        }
 
-       public String getUuid() {
+       public synchronized String getUuid() {
                try {
                        return node.getProperty(SLC_UUID).getString();
                } catch (RepositoryException e) {
@@ -50,7 +51,7 @@ public class JcrExecutionProcess implements ExecutionProcess, SlcNames {
                }
        }
 
-       public String getStatus() {
+       public synchronized String getStatus() {
                try {
                        return node.getProperty(SLC_STATUS).getString();
                } catch (RepositoryException e) {
@@ -62,7 +63,7 @@ public class JcrExecutionProcess implements ExecutionProcess, SlcNames {
                }
        }
 
-       public void setStatus(String status) {
+       public synchronized void setStatus(String status) {
                try {
                        node.setProperty(SLC_STATUS, status);
                        // last modified properties needs to be manually updated
@@ -132,8 +133,25 @@ public class JcrExecutionProcess implements ExecutionProcess, SlcNames {
                }
        }
 
-       public Node getNode() {
-               return node;
+       // public Node getNode() {
+       // return node;
+       // }
+
+       public String getNodePath() {
+               try {
+                       return node.getPath();
+               } catch (RepositoryException e) {
+                       throw new SlcException("Cannot get process node path for " + node,
+                                       e);
+               }
        }
 
+       public Repository getRepository() {
+               try {
+                       return node.getSession().getRepository();
+               } catch (RepositoryException e) {
+                       throw new SlcException("Cannot get process JCR repository for "
+                                       + node, e);
+               }
+       }
 }
index e816b1c3724bef8e270816d04da93f451f4dd85a..41353e05260394f2468560b2e3618789420d7fcc 100644 (file)
@@ -22,8 +22,10 @@ import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.Property;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 
 import org.argeo.ArgeoException;
+import org.argeo.jcr.JcrUtils;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.core.execution.DefaultExecutionSpec;
 import org.argeo.slc.core.execution.PrimitiveSpecAttribute;
@@ -50,8 +52,11 @@ public class JcrProcessThread extends ProcessThread implements SlcNames {
 
        @Override
        protected void process() throws InterruptedException {
+               Session session = null;
                try {
-                       Node rootRealizedFlowNode = getNode().getNode(SLC_FLOW);
+                       session = getJcrExecutionProcess().getRepository().login();
+                       Node rootRealizedFlowNode = session.getNode(
+                                       getJcrExecutionProcess().getNodePath()).getNode(SLC_FLOW);
                        // we just manage one level for the time being
                        NodeIterator nit = rootRealizedFlowNode.getNodes(SLC_FLOW);
                        while (nit.hasNext()) {
@@ -85,7 +90,10 @@ public class JcrProcessThread extends ProcessThread implements SlcNames {
                                }
                        }
                } catch (RepositoryException e) {
-                       throw new ArgeoException("Cannot process " + getNode(), e);
+                       throw new ArgeoException("Cannot process "
+                                       + getJcrExecutionProcess().getNodePath(), e);
+               } finally {
+                       JcrUtils.logoutQuietly(session);
                }
        }
 
@@ -193,7 +201,7 @@ public class JcrProcessThread extends ProcessThread implements SlcNames {
                }
        }
 
-       protected Node getNode() {
-               return ((JcrExecutionProcess) getProcess()).getNode();
+       protected JcrExecutionProcess getJcrExecutionProcess() {
+               return (JcrExecutionProcess) getProcess();
        }
 }