Code Duplication    Length = 67-67 lines in 2 locations

src/main/java/it/cnr/istc/pst/platinum/executive/dc/DCMonitor.java 1 location

@@ 58-124 (lines=67) @@
55
			
56
			
57
			// check feedback type
58
			switch (feedback.getType()) {
59
			
60
				case PARTIALLY_CONTROLLABLE_TOKEN_COMPLETE : 
61
				case UNCONTROLLABLE_TOKEN_COMPLETE : 
62
				{
63
					// compute node duration of the token in execution 
64
					long duration = Math.max(1, tau - node.getStart()[0]);
65
					try {
66
						
67
						// schedule token duration
68
						this.executive.scheduleTokenDuration(node, duration);
69
						// update node state
70
						this.executive.updateNode(node, ExecutionNodeStatus.EXECUTED);
71
						info("[DCMonitor] [tick: " + tick + "] [tau: " +  tau + "] -> Observed token execution with duration " + duration + " \n"
72
								+ "\t- node: " + node.getGroundSignature() + " (" + node + ")\n");
73
					}
74
					catch (TemporalConstraintPropagationException ex) {
75
						
76
						// set token as in failure
77
						this.executive.updateNode(node, ExecutionNodeStatus.FAILURE);
78
						// create execution failure message
79
						ExecutionFailureCause cause = new NodeDurationOverflow(tick, node, tau);
80
						// throw execution exception
81
						throw new NodeObservationException(
82
								"Observed duration time does not comply with the expected one:\n"
83
								+ "\t- duration: " + duration + "\n"
84
								+ "\t- node: " + node + "\n", 
85
								cause);
86
					}
87
				}
88
				break;
89
				
90
				case UNCONTROLLABLE_TOKEN_START : 
91
				{
92
					try
93
					{
94
						// schedule the start of uncontrollable token
95
						this.executive.scheduleUncontrollableTokenStart(node, tau);
96
						info("{Monitor} {tick: " + tick + "} {tau: " + tau + "} -> Observed token execution start at time " + tau + "\n"
97
								+ "\t- node: " + node.getGroundSignature() + " (" + node + ")\n");
98
					}
99
					catch (TemporalConstraintPropagationException ex) {
100
						
101
						// the node can be considered as in execution
102
						this.executive.updateNode(node, ExecutionNodeStatus.FAILURE);
103
						// create execution cause
104
						ExecutionFailureCause cause = new NodeStartOverflow(tick, node, tau);
105
						// throw execution exception
106
						throw new NodeObservationException(
107
								"The observed start time of the token does not comply with the expected one:\n"
108
								+ "\t- start: " + tau + "\n"
109
								+ "\t- node: " + node + "\n", 
110
								cause);
111
					}
112
				}
113
				break;
114
				
115
				case TOKEN_EXECUTION_FAILURE : {
116
					
117
					// update node status
118
					this.executive.updateNode(node, ExecutionNodeStatus.FAILURE);
119
					// execution failure
120
					ExecutionFailureCause cause = new NodeExecutionError(tick, node); 
121
					// throw execution exception
122
					throw new NodeExecutionErrorException(
123
							"Node execution error:\n\t- node: " + node + "\n", 
124
							cause);
125
				}
126
			}
127
		}

src/main/java/it/cnr/istc/pst/platinum/ai/executive/monitor/ConditionCheckingMonitor.java 1 location

@@ 50-116 (lines=67) @@
47
			// get node 
48
			ExecutionNode node = feedback.getNode();
49
			// check execution result
50
			switch (feedback.getType()) {
51
			
52
				case PARTIALLY_CONTROLLABLE_TOKEN_COMPLETE : 
53
				case UNCONTROLLABLE_TOKEN_COMPLETE :  {
54
					
55
					// compute node duration of the token in execution 
56
					long duration = Math.max(1, tau - node.getStart()[0]);
57
					try {
58
						
59
						// schedule token duration
60
						this.executive.scheduleTokenDuration(node, duration);
61
						// update node status
62
						this.executive.updateNode(node, ExecutionNodeStatus.EXECUTED);
63
						info("{Monitor} {tick: " + tick + "} {tau: " +  tau + "} -> Observed token execution with duration " + duration + " \n"
64
								+ "\t- node: " + node.getGroundSignature() + " (" + node + ")\n");
65
					}
66
					catch (TemporalConstraintPropagationException ex) {
67
						
68
						// update node state
69
						this.executive.updateNode(node, ExecutionNodeStatus.FAILURE);
70
						// create failure cause
71
						ExecutionFailureCause cause = new NodeDurationOverflow(tick, node, duration);
72
						// throw execution exception
73
						throw new NodeObservationException(
74
								"The observed duration of the token does not comply with the expected one:\n"
75
								+ "\t- duration: " + duration + "\n"
76
								+ "\t- node: " + node + "\n", 
77
								cause);
78
					}
79
				}
80
				break;
81
				
82
				case UNCONTROLLABLE_TOKEN_START : {
83
					
84
					try {
85
						
86
						// schedule the start of uncontrollable token
87
						this.executive.scheduleUncontrollableTokenStart(node, tau);
88
						info("{Monitor} {tick: " + tick + "} {tau: " + tau + "} -> Observed token execution start at time " + tau + "\n"
89
								+ "\t- node: " + node.getGroundSignature() + " (" + node + ")\n");
90
					}
91
					catch (TemporalConstraintPropagationException ex) {
92
						
93
						// update node state
94
						this.executive.updateNode(node, ExecutionNodeStatus.FAILURE);
95
						// create failure cause
96
						ExecutionFailureCause cause = new NodeStartOverflow(tick, node, tau);
97
						// throw execution exception
98
						throw new NodeObservationException(
99
								"The observed start time of the token does not comply with the expected one:\n"
100
								+ "\t- start: " + tau + "\n"
101
								+ "\t- node: " + node + "\n", 
102
								cause);
103
					}
104
				}
105
				break;
106
				
107
				case TOKEN_EXECUTION_FAILURE : {
108
					
109
					// update node status
110
					this.executive.updateNode(node, ExecutionNodeStatus.FAILURE);
111
					// execution failure
112
					ExecutionFailureCause cause = new NodeExecutionError(tick, node); 
113
					// throw execution exception
114
					throw new NodeExecutionErrorException(
115
							"Node execution error:\n\t- node: " + node + "\n", 
116
							cause);
117
				}
118
			}
119
		}