4343import org .ros2 .rcljava .timer .Timer ;
4444
4545/**
46- * Entry point for the ROS2 Java API, similar to the rclcpp API.
46+ * Entry point for the ROS 2 Java API, similar to the rclcpp API.
4747 */
4848public final class RCLJava {
4949 private static final Logger logger = LoggerFactory .getLogger (RCLJava .class );
@@ -132,7 +132,7 @@ public static boolean isInitialized() {
132132
133133 /**
134134 * Initialize the RCLJava API. If successful, a valid RMW implementation will
135- * be loaded and accessible, enabling the creating of ROS2 entities
135+ * be loaded and accessible, enabling the creating of ROS 2 entities
136136 * (@{link Node}s, @{link Publisher}s and @{link Subscription}s.
137137 * This also initializes the default context.
138138 */
@@ -163,18 +163,18 @@ public static synchronized void rclJavaInit(String args[]) {
163163 private static native long nativeCreateContextHandle ();
164164
165165 /**
166- * Create a ROS2 node (rcl_node_t) and return a pointer to it as an integer.
166+ * Create a ROS 2 node (rcl_node_t) and return a pointer to it as an integer.
167167 *
168- * @param nodeName The name that will identify this node in a ROS2 graph.
168+ * @param nodeName The name that will identify this node in a ROS 2 graph.
169169 * @param namespace The namespace of the node.
170170 * @param contextHandle Pointer to a context (rcl_context_t) with which to associated the node.
171- * @return A pointer to the underlying ROS2 node structure.
171+ * @return A pointer to the underlying ROS 2 node structure.
172172 */
173173 private static native long nativeCreateNodeHandle (String nodeName , String namespace , long contextHandle , ArrayList <String > arguments , boolean useGlobalArguments , boolean enableRosout );
174174
175175 /**
176176 * @return The identifier of the currently active RMW implementation via the
177- * native ROS2 API.
177+ * native ROS 2 API.
178178 */
179179 private static native String nativeGetRMWIdentifier ();
180180
@@ -186,7 +186,7 @@ public static String getRMWIdentifier() {
186186 }
187187
188188 /**
189- * Call the underlying ROS2 rcl mechanism to check if ROS2 has been shut
189+ * Call the underlying ROS 2 rcl mechanism to check if ROS 2 has been shut
190190 * down.
191191 *
192192 * @return true if RCLJava hasn't been shut down, false otherwise.
@@ -222,29 +222,50 @@ public static Context createContext() {
222222 /**
223223 * Create a @{link Node}.
224224 *
225- * @param nodeName The name that will identify this node in a ROS2 graph.
226- * @return A @{link Node} that represents the underlying ROS2 node
227- * structure.
225+ * @param nodeName The name that will identify this node in a ROS 2 graph.
226+ * @return A @{link Node} that represents the underlying ROS 2 node structure.
228227 */
229228 public static Node createNode (final String nodeName ) {
230- return createNode (nodeName , "" , RCLJava . getDefaultContext (), new NodeOptions ());
229+ return createNode (nodeName , "" , new NodeOptions ());
231230 }
232231
233232 /**
234233 * Create a @{link Node}.
235234 *
236- * @param nodeName The name that will identify this node in a ROS2 graph.
235+ * @param nodeName The name that will identify this node in a ROS 2 graph.
237236 * @param namespace The namespace of the node.
238- * @return A @{link Node} that represents the underlying ROS2 node
239- * structure.
237+ * @return A @{link Node} that represents the underlying ROS 2 node structure.
240238 */
239+ public static Node createNode (final String nodeName , final String namespace ) {
240+ return createNode (nodeName , namespace , new NodeOptions ());
241+ }
242+
243+ /**
244+ * Create a @{link Node}.
245+ *
246+ * @deprecated Use `RCLJava.createNode(nodeName, namespace, new NodeOptions.setContext(context))` instead.
247+ * @param nodeName The name that will identify this node in a ROS 2 graph.
248+ * @param namespace The namespace of the node.
249+ * @param context Context used for creating the node, @link{RCLJava.getDefaultContext()} will be used if `null`.
250+ * @return A @{link Node} that represents the underlying ROS 2 node structure.
251+ */
252+ @ Deprecated
241253 public static Node createNode (final String nodeName , final String namespace , final Context context ) {
242- return createNode (nodeName , namespace , context , new NodeOptions ());
254+ return createNode (nodeName , namespace , new NodeOptions (). setContext ( context ));
243255 }
244256
245- public static Node createNode (final String nodeName , final String namespace , final Context context , final NodeOptions options ) {
257+ /**
258+ * Create a @{link Node}.
259+ *
260+ * @param nodeName The name that will identify this node in a ROS 2 graph.
261+ * @param namespace The namespace of the node.
262+ * @param options Additional options to customize the Node creation. See @link{org.ros2.rcljava.node.NodeOptions}.
263+ * @return A @{link Node} that represents the underlying ROS 2 node structure.
264+ */
265+ public static Node createNode (final String nodeName , final String namespace , final NodeOptions options ) {
266+ Context context = options .getContext () == null ? RCLJava .getDefaultContext () : options .getContext ();
246267 long nodeHandle = nativeCreateNodeHandle (nodeName , namespace , context .getHandle (), options .getCliArgs (), options .getUseGlobalArguments (), options .getEnableRosout ());
247- Node node = new NodeImpl (nodeHandle , context , options . getAllowUndeclaredParameters () );
268+ Node node = new NodeImpl (nodeHandle , options );
248269 nodes .add (node );
249270 return node ;
250271 }
0 commit comments