Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

net.jxta.impl.endpoint
Class LoopbackMessenger  view LoopbackMessenger download LoopbackMessenger.java

java.lang.Object
  extended bynet.jxta.util.AbstractSimpleSelectable
      extended bynet.jxta.endpoint.AbstractMessenger
          extended bynet.jxta.impl.endpoint.BlockingMessenger
              extended bynet.jxta.impl.endpoint.LoopbackMessenger
All Implemented Interfaces:
net.jxta.endpoint.Messenger, net.jxta.util.SimpleSelectable

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 going to a relay. If your peer is an http client, it is not able to connect to self through the normal http 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 lookback 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.

Anyone with a better way, speak up. J-C


Nested Class Summary
 
Nested classes inherited from class net.jxta.impl.endpoint.BlockingMessenger
 
Nested classes inherited from class net.jxta.util.SimpleSelectable
net.jxta.util.SimpleSelectable.IdentityReference
 
Field Summary
(package private)  net.jxta.endpoint.EndpointService endpoint
          The endpoint we are working for, ie.
private static org.apache.log4j.Logger LOG
           
private  net.jxta.endpoint.EndpointAddress logicalDestination
           
private  net.jxta.endpoint.EndpointAddress srcAddress
          The source address of messages sent on this messenger.
private  net.jxta.endpoint.MessageElement srcAddressElement
           
 
Fields inherited from class net.jxta.impl.endpoint.BlockingMessenger
 
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(net.jxta.endpoint.EndpointService ep, net.jxta.endpoint.EndpointAddress src, net.jxta.endpoint.EndpointAddress dest, net.jxta.endpoint.EndpointAddress logicalDest)
          Create a new loopback messenger.
 
Method Summary
 void closeImpl()
          null
 net.jxta.endpoint.EndpointAddress getLogicalDestinationImpl()
          null
 boolean isIdleImpl()
          null
 boolean sendMessageBImpl(net.jxta.endpoint.Message message, java.lang.String service, java.lang.String serviceParam)
          Sends a message to the destination
 
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, getMTU, isIdle, isSynchronous, itemChanged, sendMessage, sendMessage, sendMessage, setStateLock, 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, toString, wait, wait, wait
 
Methods inherited from interface net.jxta.util.SimpleSelectable
getIdentityReference, register, unregister
 

Field Detail

LOG

private static final org.apache.log4j.Logger LOG

srcAddress

private net.jxta.endpoint.EndpointAddress srcAddress
The source address of messages sent on this messenger.


srcAddressElement

private net.jxta.endpoint.MessageElement srcAddressElement

logicalDestination

private net.jxta.endpoint.EndpointAddress logicalDestination

endpoint

net.jxta.endpoint.EndpointService endpoint
The endpoint we are working for, ie. that we will loop back to.

Constructor Detail

LoopbackMessenger

public LoopbackMessenger(net.jxta.endpoint.EndpointService ep,
                         net.jxta.endpoint.EndpointAddress src,
                         net.jxta.endpoint.EndpointAddress dest,
                         net.jxta.endpoint.EndpointAddress logicalDest)
Create a new loopback messenger.

Method Detail

getLogicalDestinationImpl

public net.jxta.endpoint.EndpointAddress getLogicalDestinationImpl()
null

Specified by:
getLogicalDestinationImpl in class BlockingMessenger

isIdleImpl

public boolean isIdleImpl()
null

Specified by:
isIdleImpl in class BlockingMessenger

closeImpl

public void closeImpl()
null

Specified by:
closeImpl in class BlockingMessenger

sendMessageBImpl

public boolean sendMessageBImpl(net.jxta.endpoint.Message message,
                                java.lang.String service,
                                java.lang.String serviceParam)
                         throws java.io.IOException
Sends a message to the destination

Specified by:
sendMessageBImpl in class BlockingMessenger