Can I stop a set of actors without a "poison pill"

40 views
Skip to first unread message

Jason Pell

unread,
Mar 15, 2013, 9:13:35 AM3/15/13
to kilimt...@googlegroups.com
Hi,

In my application I have a GenericActor which is a common super class
of all other actors. Every GenericActor has a Mailbox<T> getInbox()
method. Each GenericActor has a List<GenericActor<?>> of all other
actors that I directly reference by their mailboxes. I know the point
is to only reference mailboxes, but my children list is just for
collecting Mailbox size metrics and also for stopping my actor tree.

I do not want to use a poison pill if I can help it, but I would like
these actors to be garbage collected.

Is it enough to remove the Msg available and space available listeners
from the Inbox in each GenericActor?

I have a list of all actors for which I have a mailbox reference:

private final List<GenericActor<?>> childActors = new
ArrayList<GenericActor<?>>();

My stop method in GenericActor currently looks like this:

public void stop() {
getInbox().removeMsgAvailableListener(this);
getInbox().removeSpaceAvailableListener(this);

for (GenericActor<?> child : childActors) {
child.stop();
}
}


Should this be enough to allow garbage collection of the Actors and
mailboxes that are now dormant because I won't be posting any more
messages to this particular actor tree?

Jason Pell

unread,
Mar 15, 2013, 9:21:56 AM3/15/13
to kilimt...@googlegroups.com, ja...@pellcorp.com
I understand that I can use 'exit', but I don't want to use a pausable method.  I just want to
ensure that a dormant Task object will be garbaged collected.  I figure since I am removing the listeners,
that should hopefully be the only thing referencing the task, as there are no messages in the mailboxes,
it's never going to appear on the scheduler again.

Is this a valid understanding?

Jason Pell

unread,
Mar 15, 2013, 9:25:02 AM3/15/13
to kilimt...@googlegroups.com, ja...@pellcorp.com
I just realised that removing the removeSpaceAvailableListener is not valid, as the listener on this object is not actually my GenericActor, it will be a producer.

So I really need to remove all listeners from the mailbox in order to hopefully allow it to be garbaged collected.

Any further suggestions will be welcome
Reply all
Reply to author
Forward
0 new messages