]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.jcr/src/org/argeo/slc/jcr/execution/JcrProcessThread.java
Adapt to changes in Argeo Commons.
[gpl/argeo-slc.git] / org.argeo.slc.jcr / src / org / argeo / slc / jcr / execution / JcrProcessThread.java
1 /*
2
3 * Copyright (C) 2007-2012 Argeo GmbH
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.argeo.slc.jcr.execution;
18
19 import java.util.List;
20
21 import javax.jcr.Node;
22 import javax.jcr.RepositoryException;
23 import javax.jcr.Session;
24
25 import org.argeo.api.NodeConstants;
26 import org.argeo.jcr.JcrUtils;
27 import org.argeo.slc.SlcException;
28 import org.argeo.slc.SlcNames;
29 import org.argeo.slc.execution.ExecutionModulesManager;
30 import org.argeo.slc.execution.ExecutionProcess;
31 import org.argeo.slc.execution.RealizedFlow;
32 import org.argeo.slc.runtime.ProcessThread;
33
34 /** Where the actual execution takes place */
35 public class JcrProcessThread extends ProcessThread implements SlcNames {
36
37 public JcrProcessThread(ThreadGroup processesThreadGroup, ExecutionModulesManager executionModulesManager,
38 JcrExecutionProcess process) {
39 super(processesThreadGroup, executionModulesManager, process);
40 }
41
42 /** Overridden in order to set progress status on realized flow nodes. */
43 @Override
44 protected void process() throws InterruptedException {
45 Session session = null;
46 if (getProcess() instanceof JcrExecutionProcess)
47 try {
48 session = ((JcrExecutionProcess) getProcess()).getRepository().login(NodeConstants.HOME);
49
50 List<RealizedFlow> realizedFlows = getProcess().getRealizedFlows();
51 for (RealizedFlow realizedFlow : realizedFlows) {
52 Node realizedFlowNode = session.getNode(((JcrRealizedFlow) realizedFlow).getPath());
53 setFlowStatus(realizedFlowNode, ExecutionProcess.RUNNING);
54
55 try {
56 //
57 // EXECUTE THE FLOW
58 //
59 execute(realizedFlow, true);
60
61 setFlowStatus(realizedFlowNode, ExecutionProcess.COMPLETED);
62 } catch (RepositoryException e) {
63 throw e;
64 } catch (InterruptedException e) {
65 setFlowStatus(realizedFlowNode, ExecutionProcess.KILLED);
66 throw e;
67 } catch (RuntimeException e) {
68 setFlowStatus(realizedFlowNode, ExecutionProcess.ERROR);
69 throw e;
70 }
71 }
72 } catch (RepositoryException e) {
73 throw new SlcException("Cannot process " + getJcrExecutionProcess().getNodePath(), e);
74 } finally {
75 JcrUtils.logoutQuietly(session);
76 }
77 else
78 super.process();
79 }
80
81 protected void setFlowStatus(Node realizedFlowNode, String status) throws RepositoryException {
82 realizedFlowNode.setProperty(SLC_STATUS, status);
83 realizedFlowNode.getSession().save();
84 }
85
86 protected JcrExecutionProcess getJcrExecutionProcess() {
87 return (JcrExecutionProcess) getProcess();
88 }
89 }