3 * Copyright (C) 2007-2012 Argeo GmbH
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org
.argeo
.slc
.jcr
.execution
;
19 import java
.util
.List
;
21 import javax
.jcr
.Node
;
22 import javax
.jcr
.RepositoryException
;
23 import javax
.jcr
.Session
;
25 import org
.argeo
.ArgeoException
;
26 import org
.argeo
.jcr
.JcrUtils
;
27 import org
.argeo
.slc
.core
.execution
.ProcessThread
;
28 import org
.argeo
.slc
.execution
.ExecutionModulesManager
;
29 import org
.argeo
.slc
.execution
.ExecutionProcess
;
30 import org
.argeo
.slc
.execution
.RealizedFlow
;
31 import org
.argeo
.slc
.jcr
.SlcNames
;
33 /** Where the actual execution takes place */
34 public class JcrProcessThread
extends ProcessThread
implements SlcNames
{
36 public JcrProcessThread(ThreadGroup processesThreadGroup
,
37 ExecutionModulesManager executionModulesManager
,
38 JcrExecutionProcess process
) {
39 super(processesThreadGroup
, executionModulesManager
, process
);
42 /** Overridden in order to set progress status on realized flow nodes. */
44 protected void process() throws InterruptedException
{
45 Session session
= null;
46 if (getProcess() instanceof JcrExecutionProcess
)
48 session
= ((JcrExecutionProcess
) getProcess()).getRepository()
51 List
<RealizedFlow
> realizedFlows
= getProcess()
53 for (RealizedFlow realizedFlow
: realizedFlows
) {
54 Node realizedFlowNode
= session
55 .getNode(((JcrRealizedFlow
) realizedFlow
).getPath());
56 setFlowStatus(realizedFlowNode
, ExecutionProcess
.RUNNING
);
62 execute(realizedFlow
, true);
64 setFlowStatus(realizedFlowNode
,
65 ExecutionProcess
.COMPLETED
);
66 } catch (RepositoryException e
) {
68 } catch (InterruptedException e
) {
69 setFlowStatus(realizedFlowNode
, ExecutionProcess
.KILLED
);
71 } catch (RuntimeException e
) {
72 setFlowStatus(realizedFlowNode
, ExecutionProcess
.ERROR
);
76 } catch (RepositoryException e
) {
77 throw new ArgeoException("Cannot process "
78 + getJcrExecutionProcess().getNodePath(), e
);
80 JcrUtils
.logoutQuietly(session
);
86 protected void setFlowStatus(Node realizedFlowNode
, String status
)
87 throws RepositoryException
{
88 realizedFlowNode
.setProperty(SLC_STATUS
, status
);
89 realizedFlowNode
.getSession().save();
92 protected JcrExecutionProcess
getJcrExecutionProcess() {
93 return (JcrExecutionProcess
) getProcess();