Skip to content
Snippets Groups Projects
Commit fcae1c97 authored by Dan Ambrosio's avatar Dan Ambrosio
Browse files

This closes rosjava/rosjava_core#233. Adds fix for shutting down...

This closes rosjava/rosjava_core#233. Adds fix for shutting down DefaultNodeMainExecutor ListenerGroup to prevent leak in android when activities are destroyed. Added ability to remove listener from ListenerGroup to fix android_core issue #254.
parent 389b657e
No related branches found
No related tags found
No related merge requests found
......@@ -42,4 +42,9 @@ public class EventDispatcher<T> extends CancellableLoop {
SignalRunnable<T> signalRunnable = events.takeFirst();
signalRunnable.run(listener);
}
public T getListener()
{
return listener;
}
}
\ No newline at end of file
......@@ -101,6 +101,25 @@ public class ListenerGroup<T> {
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
*/
......@@ -151,5 +170,6 @@ public class ListenerGroup<T> {
for (EventDispatcher<T> eventDispatcher : eventDispatchers) {
eventDispatcher.cancel();
}
eventDispatchers.clear();
}
}
......@@ -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.
* <p>
......
......@@ -213,6 +213,7 @@ public class DefaultNodeMainExecutor implements NodeMainExecutor {
* the {@link Node} to unregister
*/
private void unregisterNode(Node node) {
node.removeListeners();
connectedNodes.get(node.getName()).remove(node);
nodeMains.remove(node);
}
......
......@@ -126,4 +126,10 @@ public interface Node {
* Shut the node down.
*/
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