Skip to content
This repository has been archived by the owner on Aug 11, 2023. It is now read-only.

Commit

Permalink
rosnode kill support (shut down the node)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojciech Młynarczyk committed Feb 11, 2019
1 parent 1f2ec3e commit 34764c5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public DefaultNode(NodeConfiguration nodeConfiguration, Collection<NodeListener>
nodeConfiguration.getTcpRosAdvertiseAddress(),
nodeConfiguration.getXmlRpcBindAddress(),
nodeConfiguration.getXmlRpcAdvertiseAddress(), masterClient, topicParticipantManager,
serviceManager, parameterManager, scheduledExecutorService);
serviceManager, parameterManager, scheduledExecutorService, this);
slaveServer.start();

NodeIdentifier nodeIdentifier = slaveServer.toNodeIdentifier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.ros.address.AdvertiseAddress;
import org.ros.address.BindAddress;
import org.ros.internal.node.DefaultNode;
import org.ros.internal.node.client.MasterClient;
import org.ros.internal.node.parameter.ParameterManager;
import org.ros.internal.node.service.ServiceManager;
Expand Down Expand Up @@ -52,12 +53,15 @@ public class SlaveServer extends XmlRpcServer {
private final TopicParticipantManager topicParticipantManager;
private final ParameterManager parameterManager;
private final TcpRosServer tcpRosServer;
private final DefaultNode defaultNode;
private boolean shutdownStarted;

public SlaveServer(GraphName nodeName, BindAddress tcpRosBindAddress,
AdvertiseAddress tcpRosAdvertiseAddress, BindAddress xmlRpcBindAddress,
AdvertiseAddress xmlRpcAdvertiseAddress, MasterClient master,
TopicParticipantManager topicParticipantManager, ServiceManager serviceManager,
ParameterManager parameterManager, ScheduledExecutorService executorService) {
ParameterManager parameterManager, ScheduledExecutorService executorService,
DefaultNode defaultNode) {
super(xmlRpcBindAddress, xmlRpcAdvertiseAddress);
this.nodeName = nodeName;
this.masterClient = master;
Expand All @@ -66,6 +70,7 @@ public SlaveServer(GraphName nodeName, BindAddress tcpRosBindAddress,
this.tcpRosServer =
new TcpRosServer(tcpRosBindAddress, tcpRosAdvertiseAddress, topicParticipantManager,
serviceManager, executorService);
this.defaultNode = defaultNode;
}

public AdvertiseAddress getTcpRosAdvertiseAddress() {
Expand All @@ -81,13 +86,22 @@ public void start() {
super.start(org.ros.internal.node.xmlrpc.SlaveXmlRpcEndpointImpl.class,
new SlaveXmlRpcEndpointImpl(this));
tcpRosServer.start();
shutdownStarted = false;
}

// TODO(damonkohler): This should also shut down the Node.
@Override
public void shutdown() {
// prevent recursive call of this method
if (shutdownStarted) {
return;
}
shutdownStarted = true;
super.shutdown();
tcpRosServer.shutdown();
if (defaultNode != null) {
defaultNode.shutdown();
}
}

public List<Object> getBusStats(String callerId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void setUp() {
new SlaveServer(GraphName.of("/foo"), BindAddress.newPrivate(),
AdvertiseAddress.newPrivate(), BindAddress.newPrivate(), AdvertiseAddress.newPrivate(),
masterClient, topicParticipantManager, serviceManager, parameterManager,
executorService);
executorService, null);
slaveServer.start();
slaveClient = new SlaveClient(GraphName.of("/bar"), slaveServer.getUri());
}
Expand Down

0 comments on commit 34764c5

Please sign in to comment.