Skip to content

Commit 9c93a03

Browse files
committed
Make GoalHandleImpl inner class instead of static
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
1 parent 5e4693a commit 9c93a03

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

rcljava/src/main/java/org/ros2/rcljava/action/ActionServerImpl.java

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,37 @@
3838
import org.slf4j.LoggerFactory;
3939

4040
public class ActionServerImpl<T extends ActionDefinition> implements ActionServer<T> {
41-
static class GoalHandleImpl<T extends ActionDefinition> implements ActionServerGoalHandle {
42-
private static final Logger logger = LoggerFactory.getLogger(GoalHandleImpl.class);
41+
private static final Logger logger = LoggerFactory.getLogger(ActionServerImpl.class);
4342

44-
static {
45-
try {
46-
JNIUtils.loadImplementation(GoalHandleImpl.class);
47-
} catch (UnsatisfiedLinkError ule) {
48-
logger.error("Native code library failed to load.\n" + ule);
49-
System.exit(1);
50-
}
43+
static {
44+
try {
45+
JNIUtils.loadImplementation(ActionServerImpl.class);
46+
JNIUtils.loadImplementation(ActionServerImpl.GoalHandleImpl.class);
47+
} catch (UnsatisfiedLinkError ule) {
48+
logger.error("Native code library failed to load.\n" + ule);
49+
System.exit(1);
5150
}
51+
JNIUtils.loadImplementation(ActionServerImpl.class);
52+
}
5253

54+
class GoalHandleImpl implements ActionServerGoalHandle<T> {
5355
private long handle;
5456
private ActionServer<T> actionServer;
5557
private action_msgs.msg.GoalInfo goalInfo;
5658
private MessageDefinition goal;
5759

58-
private static native long nativeAcceptNewGoal(
60+
private native long nativeAcceptNewGoal(
5961
long actionServerHandle,
6062
long goalInfoFromJavaConverterHandle,
6163
long goalInfoDestructorHandle,
6264
MessageDefinition goalInfo);
63-
private static native int nativeGetStatus(long goalHandle);
64-
private static native void nativeGoalEventExecute(long goalHandle);
65-
private static native void nativeGoalEventCancelGoal(long goalHandle);
66-
private static native void nativeGoalEventSucceed(long goalHandle);
67-
private static native void nativeGoalEventAbort(long goalHandle);
68-
private static native void nativeGoalEventCanceled(long goalHandle);
69-
private static native void nativeDispose(long handle);
65+
private native int nativeGetStatus(long goalHandle);
66+
private native void nativeGoalEventExecute(long goalHandle);
67+
private native void nativeGoalEventCancelGoal(long goalHandle);
68+
private native void nativeGoalEventSucceed(long goalHandle);
69+
private native void nativeGoalEventAbort(long goalHandle);
70+
private native void nativeGoalEventCanceled(long goalHandle);
71+
private native void nativeDispose(long handle);
7072

7173
public GoalHandleImpl(
7274
ActionServer<T> actionServer, action_msgs.msg.GoalInfo goalInfo, MessageDefinition goal)
@@ -168,17 +170,6 @@ public synchronized final long getHandle() {
168170
}
169171
} // class GoalHandleImpl
170172

171-
private static final Logger logger = LoggerFactory.getLogger(ActionServerImpl.class);
172-
173-
static {
174-
try {
175-
JNIUtils.loadImplementation(ActionServerImpl.class);
176-
} catch (UnsatisfiedLinkError ule) {
177-
logger.error("Native code library failed to load.\n" + ule);
178-
System.exit(1);
179-
}
180-
}
181-
182173
private final WeakReference<Node> nodeReference;
183174
private final Clock clock;
184175
private final T actionTypeInstance;
@@ -190,7 +181,7 @@ public synchronized final long getHandle() {
190181

191182
private boolean[] readyEntities;
192183

193-
private Map<List<Byte>, GoalHandleImpl<T>> goalHandles;
184+
private Map<List<Byte>, GoalHandleImpl> goalHandles;
194185

195186
private boolean isGoalRequestReady() {
196187
return this.readyEntities[0];
@@ -239,7 +230,7 @@ public ActionServerImpl(
239230
this.cancelCallback = cancelCallback;
240231
this.acceptedCallback = acceptedCallback;
241232

242-
this.goalHandles = new HashMap<List<Byte>, GoalHandleImpl<T>>();
233+
this.goalHandles = new HashMap<List<Byte>, GoalHandleImpl>();
243234

244235
Node node = nodeReference.get();
245236
if (node == null) {
@@ -340,7 +331,7 @@ private ActionServerGoalHandle<T> executeGoalRequest(
340331
}
341332

342333
// Create a goal handle and add it to the list of goals
343-
GoalHandleImpl<T> goalHandle = new GoalHandleImpl<T>(
334+
GoalHandleImpl goalHandle = this.new GoalHandleImpl(
344335
this, goalInfo, requestMessage.getGoal());
345336
this.goalHandles.put(requestMessage.getGoalUuid(), goalHandle);
346337
return goalHandle;

0 commit comments

Comments
 (0)