1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.engine.node; |
18 | |
|
19 | |
import java.util.Iterator; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | 0 | public class NodeJotter { |
31 | |
|
32 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(NodeJotter.class); |
33 | |
private static final String INDENT = " "; |
34 | |
|
35 | |
public static void jotNodeInstance(DocumentRouteHeaderValue document, RouteNodeInstance nodeInstance) { |
36 | |
try { |
37 | 0 | if (LOG.isDebugEnabled()) { |
38 | 0 | List initialNodeInstances = document.getInitialRouteNodeInstances(); |
39 | 0 | for (Iterator iterator = initialNodeInstances.iterator(); iterator.hasNext();) { |
40 | 0 | RouteNodeInstance initialNodeInstance = (RouteNodeInstance) iterator.next(); |
41 | 0 | NodeType nodeType = NodeType.fromNodeInstance(initialNodeInstance); |
42 | 0 | LOG.debug(orchestrateOutput(initialNodeInstance, nodeType, null, 0)); |
43 | 0 | } |
44 | 0 | } else if (LOG.isInfoEnabled()) { |
45 | 0 | NodeType nodeType = NodeType.fromNodeInstance(nodeInstance); |
46 | 0 | LOG.info(outputNodeInstanceToLog(nodeInstance, nodeType, 0)); |
47 | |
} |
48 | 0 | } catch (Throwable t) { |
49 | 0 | LOG.warn("Caught error attempting to jot node instance" + nodeInstance); |
50 | 0 | } |
51 | 0 | } |
52 | |
|
53 | |
private static String orchestrateOutput(RouteNodeInstance nodeInstance, NodeType nodeType, SplitJoinContext sjCtx, int indentDepth) throws Exception { |
54 | 0 | String output = ""; |
55 | 0 | boolean isSplit = NodeType.SPLIT.equals(nodeType); |
56 | 0 | boolean isJoin = NodeType.JOIN.equals(nodeType); |
57 | 0 | if (isJoin && sjCtx != null) { |
58 | 0 | sjCtx.joinNodeInstance = nodeInstance; |
59 | 0 | return output; |
60 | |
} |
61 | 0 | SplitJoinContext newSplitJoinContext = null; |
62 | 0 | if (isSplit) { |
63 | 0 | newSplitJoinContext = new SplitJoinContext(nodeInstance); |
64 | |
} |
65 | 0 | output += outputNodeInstanceToLog(nodeInstance, nodeType, indentDepth); |
66 | 0 | for (Iterator iterator = nodeInstance.getNextNodeInstances().iterator(); iterator.hasNext();) { |
67 | 0 | RouteNodeInstance nextNodeInstance = (RouteNodeInstance) iterator.next(); |
68 | 0 | nodeType = NodeType.fromNodeInstance(nextNodeInstance); |
69 | 0 | if (newSplitJoinContext != null) { |
70 | 0 | output += orchestrateOutput(nextNodeInstance, nodeType, newSplitJoinContext, indentDepth + 1); |
71 | |
} else { |
72 | 0 | output += orchestrateOutput(nextNodeInstance, nodeType, sjCtx, indentDepth + 1); |
73 | |
} |
74 | 0 | } |
75 | 0 | if (isSplit) { |
76 | 0 | if (newSplitJoinContext != null && newSplitJoinContext.joinNodeInstance != null) { |
77 | 0 | nodeType = NodeType.fromNodeInstance(newSplitJoinContext.joinNodeInstance); |
78 | 0 | output += orchestrateOutput(newSplitJoinContext.joinNodeInstance, nodeType, sjCtx, indentDepth); |
79 | |
} |
80 | |
} |
81 | 0 | return output; |
82 | |
} |
83 | |
|
84 | |
private static String outputNodeInstanceToLog(RouteNodeInstance nodeInstance, NodeType nodeType, int indentDepth) throws Exception { |
85 | 0 | String memAddress = nodeInstance.toString().split("@")[1]; |
86 | 0 | String dataIndent = getIndent(indentDepth + 1); |
87 | 0 | String output = getIndent(indentDepth) + "[NODE type=" + nodeType.getName() + "]\n" + dataIndent + "Name: " + nodeInstance.getName() + "(" + memAddress + ")\n"; |
88 | 0 | output += dataIndent + "State: "; |
89 | 0 | for (Iterator iterator = nodeInstance.getState().iterator(); iterator.hasNext();) { |
90 | 0 | NodeState nodeState = (NodeState) iterator.next(); |
91 | 0 | output += nodeState.getKey() + "=" + nodeState.getValue(); |
92 | 0 | if (iterator.hasNext()) { |
93 | 0 | output += ","; |
94 | |
} |
95 | 0 | } |
96 | 0 | output += "\n" + dataIndent + "Status Flags: initial=" + nodeInstance.isInitial() + ", active=" + nodeInstance.isActive() + ", complete=" + nodeInstance.isComplete(); |
97 | 0 | output += (nodeInstance.getProcess() == null ? "" : "\n" + dataIndent + "Process Name: " + nodeInstance.getProcess().getName()); |
98 | 0 | output += "\n"; |
99 | 0 | return output; |
100 | |
} |
101 | |
|
102 | |
private static String getIndent(int indentDepth) { |
103 | 0 | StringBuffer buffer = new StringBuffer(); |
104 | 0 | for (int depth = 0; depth < indentDepth; depth++) { |
105 | 0 | buffer.append(INDENT); |
106 | |
} |
107 | 0 | return buffer.toString(); |
108 | |
} |
109 | |
|
110 | 0 | private static class SplitJoinContext { |
111 | |
public RouteNodeInstance splitNodeInstance; |
112 | |
public RouteNodeInstance joinNodeInstance; |
113 | |
|
114 | 0 | public SplitJoinContext(RouteNodeInstance splitNodeInstance) { |
115 | 0 | this.splitNodeInstance = splitNodeInstance; |
116 | 0 | } |
117 | |
} |
118 | |
|
119 | |
} |