| Conditions | 8 |
| Total Lines | 67 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | package it.cnr.istc.pst.platinum.control.acting; |
||
| 108 | protected void doHandle(Goal goal) |
||
| 109 | throws InterruptedException, ExecutionException, ExecutionPreparationException, PlatformException { |
||
| 110 | |||
| 111 | // get solution plan |
||
| 112 | SolutionPlan plan = goal.getPlan(); |
||
| 113 | // build executive |
||
| 114 | Executive exec = ExecutiveBuilder.createAndSet(this.eClass, 0, plan.getHorizon()); |
||
| 115 | // export plan |
||
| 116 | PlanProtocolDescriptor desc = plan.export(); |
||
| 117 | System.out.println("\n\nREADY TO EXECUTE PLAN:\n" + desc + "\n\n"); |
||
| 118 | // set the executive according to the plan being executed |
||
| 119 | exec.initialize(desc); |
||
| 120 | |||
| 121 | // bind simulator if any |
||
| 122 | if (this.agent.proxy != null) { |
||
| 123 | // bind simulator |
||
| 124 | exec.link(this.agent.proxy); |
||
| 125 | } |
||
| 126 | |||
| 127 | |||
| 128 | try { |
||
| 129 | |||
| 130 | // run the executive starting at a given tick |
||
| 131 | boolean complete = exec.execute(goal.getExecutionTick(), goal); |
||
| 132 | // check execution result |
||
| 133 | if (!complete) { |
||
| 134 | |||
| 135 | // get failure cause |
||
| 136 | ExecutionFailureCause cause = exec.getFailureCause(); |
||
| 137 | // set failure cause |
||
| 138 | goal.setFailureCause(cause); |
||
| 139 | // set repaired |
||
| 140 | goal.setRepaired(false); |
||
| 141 | // set goal interruption tick |
||
| 142 | goal.setExecutionTick(cause.getInterruptionTick()); |
||
| 143 | // set execution trace by taking into account executed nodes |
||
| 144 | for (ExecutionNode node : exec.getNodes(ExecutionNodeStatus.EXECUTED)) { |
||
| 145 | // add the node to the goal execution trace |
||
| 146 | goal.addNodeToExecutionTrace(node); |
||
| 147 | } |
||
| 148 | |||
| 149 | // get the name of of goal components |
||
| 150 | Set<String> components = new HashSet<>(); |
||
| 151 | for (TokenDescription t : goal.getTaskDescription().getGoals()) { |
||
| 152 | components.add(t.getComponent()); |
||
| 153 | } |
||
| 154 | |||
| 155 | // set execution trace by taking into account also (virtual) nodes in-execution |
||
| 156 | for (ExecutionNode node : exec.getNodes(ExecutionNodeStatus.IN_EXECUTION)) { |
||
| 157 | // do not consider nodes belonging to "goal component" |
||
| 158 | if (!components.contains(node.getComponent())) { |
||
| 159 | // add the node to the goal execution trace |
||
| 160 | goal.addNodeToExecutionTrace(node); |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | // throw exception |
||
| 165 | throw new ExecutionException("Execution failure... try to repair the plan through replanning... \n" |
||
| 166 | + "\t- cause: " + cause + "\n", cause); |
||
| 167 | } |
||
| 168 | |||
| 169 | } finally { |
||
| 170 | |||
| 171 | // stop simulator if any |
||
| 172 | if (this.agent.proxy != null) { |
||
| 173 | // unlink from simulator |
||
| 174 | exec.unlink(); |
||
| 175 | } |
||
| 180 |