JXTA

net.jxta.impl.endpoint
Class LoopbackMessenger

java.lang.Object
  extended by net.jxta.util.AbstractSimpleSelectable
      extended by net.jxta.endpoint.AbstractMessenger
          extended by net.jxta.impl.endpoint.BlockingMessenger
              extended by net.jxta.impl.endpoint.LoopbackMessenger
All Implemented Interfaces:
Messenger, SimpleSelectable
Direct Known Subclasses:
TlsTransport.TlsLoopbackMessenger

public class LoopbackMessenger
extends BlockingMessenger

This class implements local delivery of messages (for example when the InputPipe and the OutputPipe are located on the same peer)

The reason this class is useful is that it may not always be possible to connect to oneself without actually through the relay. i.e. A peer with outgoing only http transport, can not possibly connect to self through the transport.

Since transports cannot be relied on to perform a loopback, some layer above has to figure out that a message is looping back. Since peerid loopback does not explicitly request to go through a real transport, and since peerid addressing is the job of the router, it is the router that performs loopback.

The router could probably perform the loopback by delivering the message to its own input queue, that would take a special transport instead of a special messenger, which is the same kind of deal but would imply some incoming message processing by the router for every message. In contrast, the loopback messenger is setup once and the router will never sees the messages. That's a good optimization.

Alternatively, the endpoint service itself could figure out the loopback, but since the API wants to give a messenger to the requestor rather than just sending a message, the endpoint would have to setup a loopback messenger anyway. So it is pretty much the same.


Nested Class Summary
 
Nested classes/interfaces inherited from interface net.jxta.util.SimpleSelectable
SimpleSelectable.IdentityReference
 
Field Summary
 
Fields inherited from class net.jxta.endpoint.AbstractMessenger
DEFAULT_MTU, dstAddress
 
Fields inherited from class net.jxta.util.AbstractSimpleSelectable
identityReference
 
Fields inherited from interface net.jxta.endpoint.Messenger
ANYSTATE, BREAKING, BROKEN, CLOSED, CLOSING, CONNECTED, DISCONNECTED, DISCONNECTING, IDLE, RECONCLOSING, RECONNECTING, RECONSATURATED, RESOLCLOSING, RESOLPENDING, RESOLSATURATED, RESOLVED, RESOLVING, SATURATED, SENDING, SENDINGSATURATED, TERMINAL, UNRESOLVABLE, UNRESOLVED, UNRESOLVING, USABLE
 
Constructor Summary
LoopbackMessenger(PeerGroup group, EndpointService ep, EndpointAddress src, EndpointAddress dest, EndpointAddress logicalDest)
          Create a new loopback messenger.
 
Method Summary
 void closeImpl()
          Close connection.
 EndpointAddress getLogicalDestinationImpl()
          Obtain the logical destination address from the implementer (a transport for example).
 long getMTU()
          Returns the maximum message size that this messenger can be used to send.
 boolean isIdleImpl()
          return true if this messenger has not been used for a long time.
 void sendMessageBImpl(Message message, String service, String serviceParam)
          Send a message blocking as needed until the message is sent.
 
Methods inherited from class net.jxta.impl.endpoint.BlockingMessenger
close, getChannelMessenger, getDestAddressToUse, getLogicalDestinationAddress, getState, isClosed, resolve, sendMessageB, sendMessageN, setOwner, shutdown
 
Methods inherited from class net.jxta.endpoint.AbstractMessenger
flush, getDestinationAddress, getDestinationAddressObject, isIdle, isSynchronous, itemChanged, sendMessage, sendMessage, sendMessage, setStateLock, toString, waitState
 
Methods inherited from class net.jxta.util.AbstractSimpleSelectable
getIdentityReference, haveListeners, notifyChange, register, registerListener, unregister, unregisterListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.jxta.util.SimpleSelectable
getIdentityReference, register, unregister
 

Constructor Detail

LoopbackMessenger

public LoopbackMessenger(PeerGroup group,
                         EndpointService ep,
                         EndpointAddress src,
                         EndpointAddress dest,
                         EndpointAddress logicalDest)
Create a new loopback messenger.

Parameters:
group - The group context.
ep - where messages go
src - who messages should be addressed from
dest - who messages should be addressed to
logicalDest - The logical destination address.
Method Detail

getLogicalDestinationImpl

public EndpointAddress getLogicalDestinationImpl()
Obtain the logical destination address from the implementer (a transport for example).

Specified by:
getLogicalDestinationImpl in class BlockingMessenger

getMTU

public long getMTU()
Returns the maximum message size that this messenger can be used to send. The limit refers to the cumulative size of application level elements. The various sendMessage() variants will refuse to send messages that exceed this limit.

It is not always enforced. At least this much can always be sent.

Specified by:
getMTU in interface Messenger
Overrides:
getMTU in class AbstractMessenger
Returns:
the limit.

isIdleImpl

public boolean isIdleImpl()
return true if this messenger has not been used for a long time. The definition of long time is: "sufficient such that closing it is worth the cost of having to re-open". A messenger should self close if it thinks it meets the definition of idle. BlockingMessenger leaves the evaluation to the transport but does the work automatically. Important: if self destruction is used, this method must work; not just return false. See the constructor. In general, if closeImpl does not need to do anything, then self destruction is not needed.

Specified by:
isIdleImpl in class BlockingMessenger
Returns:
true if theis messenger is, by it's own definition, idle.

closeImpl

public void closeImpl()
Close connection. May fail current send.

Specified by:
closeImpl in class BlockingMessenger

sendMessageBImpl

public void sendMessageBImpl(Message message,
                             String service,
                             String serviceParam)
                      throws IOException
Send a message blocking as needed until the message is sent.

Specified by:
sendMessageBImpl in class BlockingMessenger
Parameters:
message - The message to send.
service - The destination service.
serviceParam - The destination serivce param.
Throws:
IOException - Thrown for errors encountered while sending the message.

JXSE