JXTA

net.jxta.endpoint
Class ListenerAdaptor

java.lang.Object
  extended by net.jxta.endpoint.ListenerAdaptor
All Implemented Interfaces:
Runnable

public class ListenerAdaptor
extends Object
implements Runnable

The legacy getMessenger asynchronous API never returns any object to the invoker until a messenger could actually be made, allowing the application to supply a listener to be invoked when the operation completes. The legacy Messenger API also provides a method to send messages that calls a listener to report the outcome of the operation.

The model has changed, so that an asynchronous messenger is made unresolved and returned immediately to the invoker, which can then request opening or even just send a message to force the opening. Subsequently, the messenger can be used as a control block to monitor progress with SimpleSelectable.register(net.jxta.util.SimpleSelector) and Messenger.waitState(int, long).

Likewise, the outcome of sending a message is a property of that message. Messages can be selected to monitor property changes with AbstractSimpleSelectable.register(net.jxta.util.SimpleSelector) and Message.getMessageProperty(Object) (the outcome property key is Messenger.class).

This class here provides the legacy listener model on top of the new model for applications that prefer listeners. This class is used internally to emulate the legacy listener behaviour, so that applications do not need to be adapted.

Note: one instance of this class gets instantiated by each EndpointService interface. However, it does not start using any resources until it first gets used.


Constructor Summary
ListenerAdaptor(ThreadGroup threadGroup)
          Standard Constructor
ListenerAdaptor(ThreadGroup threadGroup, Executor executor)
          Creates a ListenerAdaptor with a threadpool for notification callback.
 
Method Summary
 void run()
          
 void shutdown()
           
 boolean watchMessage(OutgoingMessageEventListener listener, Message message)
          Select the given message and invoke the given listener when the message sending is complete.
 boolean watchMessenger(MessengerEventListener listener, Messenger messenger)
          Select the given messenger and invoke the given listener when the messenger is resolved.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListenerAdaptor

public ListenerAdaptor(ThreadGroup threadGroup)
Standard Constructor

Parameters:
threadGroup - The ThreadGroup in which this adaptor will run.

ListenerAdaptor

public ListenerAdaptor(ThreadGroup threadGroup,
                       Executor executor)
Creates a ListenerAdaptor with a threadpool for notification callback.

Parameters:
threadGroup - The ThreadGroup in which this adaptor will run.
executor - the excutor to use for notification callback
Method Detail

shutdown

public void shutdown()

watchMessage

public boolean watchMessage(OutgoingMessageEventListener listener,
                            Message message)
Select the given message and invoke the given listener when the message sending is complete.

Parameters:
listener - The listener to invoke. If null the resolution will take place, but obviously no listener will be invoked.
message - The message being sent.
Returns:
true if the message was registered successfully or the listener is null. If true it is guaranteed that the listener will be invoked unless null. If false, it is guaranteed that the listener will not be invoked.

watchMessenger

public boolean watchMessenger(MessengerEventListener listener,
                              Messenger messenger)
Select the given messenger and invoke the given listener when the messenger is resolved.

Parameters:
listener - The listener to invoke. If null the resolution will take place, but obviously no listener will be invoked.
messenger - The messenger being resolved.
Returns:
true if the messenger was registered successfully or the listener is null. If true it is guaranteed that the listener will be invoked unless null. If false, it is guaranteed that the listener will not be invoked.

run

public void run()

Specified by:
run in interface Runnable

JXSE