Is calling disposable.dispose() necessary on a ChannelSubscription

13 views
Skip to first unread message

Abraham Menacherry

unread,
Dec 2, 2011, 2:11:17 AM12/2/11
to jetlang-dev
A testing library I created uses Jetlang internally. The users of this
library endup having to call disposable.dispose often. Is there a way
not to have this done by the user.

I wrote an abstract class implementing Callback interface which
"wraps" the onMessage method, so that after the onMessage method is
called, it will call dispose on the subscription and fiber. So in all
successful tests the user need not bother to call dispose. However for
messages that never arrive, the user still has to call it manually. Is
there a better way to do this? Meaning some way in which the user
never needs to call dispose.

Code in the abstract class is provided for reference. The "done"
method inturn calls the dispose method on the subscription and fiber.

public void onMessage(Message message)
{
try{
this.message = message;
if(null != message.getException()){
throw message.getException();
}
onCallback(message);
done();
}catch(Exception e){
LOG.error("Error occurred during callback execution",e);
if(null == message.getException()){
message.setException(e);
}
}
}
abstract public void onCallback(Message message);

Mike Rettig

unread,
Dec 10, 2011, 6:13:23 PM12/10/11
to jetla...@googlegroups.com
Disposing a fiber will dispose all subscriptions. Subscriptions only
need to be disposed if the subscription lifetime is shorter than the
fiber.

Calling dispose on each message delivery doesn't sound like an ideal
implementation. Channel subscriptions should be long lived and
typically exist for the lifetime of a fiber. Why are the
subscriptions disposed so often?

Mike

> --
> You received this message because you are subscribed to the Google Groups "jetlang-dev" group.
> To post to this group, send email to jetla...@googlegroups.com.
> To unsubscribe from this group, send email to jetlang-dev...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/jetlang-dev?hl=en.
>

Abraham Menacherry

unread,
Dec 11, 2011, 1:24:39 AM12/11/11
to jetlang-dev
Mike,

I have open sourced this code now (https://github.com/menacher/Test-
Tools) . The reason for frequent unsubscribe is that integration test
cases subscribe for an incoming SOAP message using callbacks, do some
logic(mostly provide appropriate reply) and since this test is over
the dispose is called to release resources.

B.t.w, I am using this for testing our product and its working fine,
but as you said it may not be optimal design.
Abraham.

Abraham Menacherry

unread,
Dec 11, 2011, 1:26:24 AM12/11/11
to jetlang-dev
Broken link in previous post.

https://github.com/menacher/Test-Tools
Wiki:
https://github.com/menacher/Test-Tools/wiki

On Dec 11, 11:24 am, Abraham Menacherry <abrahammenache...@gmail.com>
wrote:

Mike Rettig

unread,
Dec 12, 2011, 5:44:41 PM12/12/11
to jetla...@googlegroups.com
Just dispose the fiber at the end of the test. That will also remove
all the subscriptions. The garbage collector will do the rest.

Mike

Abraham Menacherry

unread,
Dec 14, 2011, 2:03:18 AM12/14/11
to jetlang-dev
Mike,
Thanks, did changes to only dispose the fiber and it worked just fine.

> > For more options, visit this group athttp://groups.google.com/group/jetlang-dev?hl=en.- Hide quoted text -
>
> - Show quoted text -

Reply all
Reply to author
Forward
0 new messages