Skip to content
Snippets Groups Projects
Commit 5ff54ed6 authored by Julian Cerruti's avatar Julian Cerruti Committed by GitHub
Browse files

Merge pull request #234 from stratomda/indigo

This closes rosjava/rosjava_core#233. Adds fix for shutting down Defa…
parents 389b657e fcae1c97
No related branches found
No related tags found
No related merge requests found
...@@ -42,4 +42,9 @@ public class EventDispatcher<T> extends CancellableLoop { ...@@ -42,4 +42,9 @@ public class EventDispatcher<T> extends CancellableLoop {
SignalRunnable<T> signalRunnable = events.takeFirst(); SignalRunnable<T> signalRunnable = events.takeFirst();
signalRunnable.run(listener); signalRunnable.run(listener);
} }
public T getListener()
{
return listener;
}
} }
\ No newline at end of file
...@@ -101,6 +101,25 @@ public class ListenerGroup<T> { ...@@ -101,6 +101,25 @@ public class ListenerGroup<T> {
return addAll(listeners, DEFAULT_QUEUE_CAPACITY); return addAll(listeners, DEFAULT_QUEUE_CAPACITY);
} }
/**
* Removes and cancels the {@EventDispatcher} specified by the listener
* from the {@link ListenerGroup}.
* @param listener the listener to remove
* @return flag indicating successful removal
*/
public boolean remove(T listener)
{
for (EventDispatcher<T> eventDispatcher : eventDispatchers) {
if(listener.equals(eventDispatcher.getListener()))
{
eventDispatcher.cancel();
eventDispatchers.remove(eventDispatcher);
return true;
}
}
return false;
}
/** /**
* @return the number of listeners in the group * @return the number of listeners in the group
*/ */
...@@ -151,5 +170,6 @@ public class ListenerGroup<T> { ...@@ -151,5 +170,6 @@ public class ListenerGroup<T> {
for (EventDispatcher<T> eventDispatcher : eventDispatchers) { for (EventDispatcher<T> eventDispatcher : eventDispatchers) {
eventDispatcher.cancel(); eventDispatcher.cancel();
} }
eventDispatchers.clear();
} }
} }
...@@ -493,6 +493,11 @@ public class DefaultNode implements ConnectedNode { ...@@ -493,6 +493,11 @@ public class DefaultNode implements ConnectedNode {
}); });
} }
@Override
public void removeListeners() {
nodeListeners.shutdown();
}
/** /**
* SignalRunnable all {@link NodeListener}s that the {@link Node} has started. * SignalRunnable all {@link NodeListener}s that the {@link Node} has started.
* <p> * <p>
......
...@@ -213,6 +213,7 @@ public class DefaultNodeMainExecutor implements NodeMainExecutor { ...@@ -213,6 +213,7 @@ public class DefaultNodeMainExecutor implements NodeMainExecutor {
* the {@link Node} to unregister * the {@link Node} to unregister
*/ */
private void unregisterNode(Node node) { private void unregisterNode(Node node) {
node.removeListeners();
connectedNodes.get(node.getName()).remove(node); connectedNodes.get(node.getName()).remove(node);
nodeMains.remove(node); nodeMains.remove(node);
} }
......
...@@ -126,4 +126,10 @@ public interface Node { ...@@ -126,4 +126,10 @@ public interface Node {
* Shut the node down. * Shut the node down.
*/ */
void shutdown(); void shutdown();
/**
* Stops and Clears node listeners.
*/
void removeListeners();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment