|
27 | 27 |
|
28 | 28 | import java.lang.reflect.Method;
|
29 | 29 | import java.util.HashMap;
|
| 30 | +import java.util.Map; |
30 | 31 | import java.util.Timer;
|
31 | 32 | import java.util.TimerTask;
|
32 | 33 | import java.util.Vector;
|
33 | 34 | import java.util.concurrent.TimeUnit;
|
| 35 | +import java.util.Collection; |
| 36 | +import java.util.Iterator; |
| 37 | +import java.util.concurrent.ConcurrentHashMap; |
34 | 38 |
|
35 | 39 | /**
|
36 |
| - * Class to encapsulate the actiolib server's communication and goal management. |
| 40 | + * Class to encapsulate the actionlib server's communication and goal management. |
37 | 41 | *
|
38 | 42 | * @author Ernesto Corbellini [email protected]
|
39 | 43 | */
|
@@ -64,8 +68,9 @@ private class ServerGoal {
|
64 | 68 | private String actionName;
|
65 | 69 | private ActionServerListener callbackTarget = null;
|
66 | 70 | private Timer statusTick = new Timer();
|
67 |
| - private HashMap<String, ServerGoal> goalTracker = new HashMap<String, |
68 |
| - ServerGoal>(1); |
| 71 | + private ConcurrentHashMap<String,ServerGoal> goalTracker = new ConcurrentHashMap<String,ServerGoal>(1); |
| 72 | + //private HashMap<String, ServerGoal> goalTracker = new HashMap<String, |
| 73 | + // ServerGoal>(1); |
69 | 74 |
|
70 | 75 | /**
|
71 | 76 | * Constructor.
|
@@ -151,9 +156,9 @@ public void run() {
|
151 | 156 | * Stop publishing the action server topics.
|
152 | 157 | */
|
153 | 158 | private void unpublishServer() {
|
154 |
| - // Stop the task run by the Timer. |
155 |
| - statusTick.cancel(); |
156 |
| - statusTick.purge(); |
| 159 | + // stop the task run by the Timer. |
| 160 | + statusTick.cancel(); |
| 161 | + statusTick.purge(); |
157 | 162 |
|
158 | 163 | if (statusPublisher != null) {
|
159 | 164 | statusPublisher.shutdown(5, TimeUnit.SECONDS);
|
@@ -259,12 +264,32 @@ public void sendStatusTick() {
|
259 | 264 | GoalStatus goalStatus;
|
260 | 265 | Vector<GoalStatus> goalStatusList = new Vector<GoalStatus>();
|
261 | 266 |
|
262 |
| - for (ServerGoal sg : goalTracker.values()) { |
| 267 | + Iterator it = goalTracker.entrySet().iterator(); |
| 268 | + while (it.hasNext()) { |
| 269 | + Map.Entry pair = (Map.Entry) it.next(); |
| 270 | + ServerGoal sg = (ServerGoal) pair.getValue(); |
263 | 271 | goalStatus = node.getTopicMessageFactory().newFromType(GoalStatus._TYPE);
|
264 | 272 | goalStatus.setGoalId(getGoalId(sg.goal));
|
265 | 273 | goalStatus.setStatus((byte) sg.state.getState());
|
266 | 274 | goalStatusList.add(goalStatus);
|
267 | 275 | }
|
| 276 | + |
| 277 | + /* Collection<ServerGoal> serverGoals = goalTracker.values(); |
| 278 | +
|
| 279 | + for (Iterator<ServerGoal> it = serverGoals.iterator(); it.hasNext();) { |
| 280 | + ServerGoal sg = it.next(); |
| 281 | + goalStatus = node.getTopicMessageFactory().newFromType(GoalStatus._TYPE); |
| 282 | + goalStatus.setGoalId(getGoalId(sg.goal)); |
| 283 | + goalStatus.setStatus((byte) sg.state.getState()); |
| 284 | + goalStatusList.add(goalStatus); |
| 285 | + } */ |
| 286 | + |
| 287 | + /* for (ServerGoal sg : goalTracker.values()) { |
| 288 | + goalStatus = node.getTopicMessageFactory().newFromType(GoalStatus._TYPE); |
| 289 | + goalStatus.setGoalId(getGoalId(sg.goal)); |
| 290 | + goalStatus.setStatus((byte) sg.state.getState()); |
| 291 | + goalStatusList.add(goalStatus); |
| 292 | + } */ |
268 | 293 | status.setStatusList(goalStatusList);
|
269 | 294 | sendStatus(status);
|
270 | 295 | }
|
|
0 commit comments