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
.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
;
34 /** Where the actual execution takes place */
35 public class JcrProcessThread
extends ProcessThread
implements SlcNames
{
37 public JcrProcessThread(ThreadGroup processesThreadGroup
, 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().login(NodeConstants
.HOME
);
50 List
<RealizedFlow
> realizedFlows
= getProcess().getRealizedFlows();
51 for (RealizedFlow realizedFlow
: realizedFlows
) {
52 Node realizedFlowNode
= session
.getNode(((JcrRealizedFlow
) realizedFlow
).getPath());
53 setFlowStatus(realizedFlowNode
, ExecutionProcess
.RUNNING
);
59 execute(realizedFlow
, true);
61 setFlowStatus(realizedFlowNode
, ExecutionProcess
.COMPLETED
);
62 } catch (RepositoryException e
) {
64 } catch (InterruptedException e
) {
65 setFlowStatus(realizedFlowNode
, ExecutionProcess
.KILLED
);
67 } catch (RuntimeException e
) {
68 setFlowStatus(realizedFlowNode
, ExecutionProcess
.ERROR
);
72 } catch (RepositoryException e
) {
73 throw new SlcException("Cannot process " + getJcrExecutionProcess().getNodePath(), e
);
75 JcrUtils
.logoutQuietly(session
);
81 protected void setFlowStatus(Node realizedFlowNode
, String status
) throws RepositoryException
{
82 realizedFlowNode
.setProperty(SLC_STATUS
, status
);
83 realizedFlowNode
.getSession().save();
86 protected JcrExecutionProcess
getJcrExecutionProcess() {
87 return (JcrExecutionProcess
) getProcess();