Project JXTA

net.jxta.impl.endpoint.servlethttp
Class HttpServletMessenger

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

public class HttpServletMessenger
extends BlockingMessenger

Simple messenger that waits for a message to give back to the requesting client

This messenger is not entirely thread-safe. You should not use any of the sendMessage methods from more than one thread.


Nested Class Summary
 
Nested classes inherited from class 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
HttpServletMessenger(PeerGroupID peerGroupID, EndpointAddress srcAddress, EndpointAddress logicalAddress)
           
 
Method Summary
 void closeImpl()
          Close connection. May fail current send.
 EndpointAddress getLogicalDestinationImpl()
          Obtain the logical destination address from the implementer (a transport for example).
 boolean isIdleImpl()
          return true if this messenger has not been used for a long time. The definition of long time is: "so long that closing it is worth the risk 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 anyhing, then self destruction is not needed.
protected  void messageSent(boolean wasSuccessful)
           
 boolean sendMessageBImpl(Message message, String service, String serviceParam)
          Send messages.
 String toString()
          

An implementation for debugging.

protected  Message waitForMessage(long timeout)
          Retrieve a message from the "queue" of messages for the servlet.
 
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, wait, wait, wait
 
Methods inherited from interface net.jxta.util.SimpleSelectable
getIdentityReference, register, unregister
 

Constructor Detail

HttpServletMessenger

public HttpServletMessenger(PeerGroupID peerGroupID,
                            EndpointAddress srcAddress,
                            EndpointAddress logicalAddress)
Method Detail

getLogicalDestinationImpl

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

Specified by:
getLogicalDestinationImpl in class BlockingMessenger

isIdleImpl

public boolean isIdleImpl()
return true if this messenger has not been used for a long time. The definition of long time is: "so long that closing it is worth the risk 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 anyhing, then self destruction is not needed.

Specified by:
isIdleImpl in class BlockingMessenger

sendMessageBImpl

public boolean sendMessageBImpl(Message message,
                                String service,
                                String serviceParam)
                         throws IOException
Send messages. Messages are queued and processed by a thread running HttpClientConnection.

Specified by:
sendMessageBImpl in class BlockingMessenger
Throws:
IOException

closeImpl

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

Specified by:
closeImpl in class BlockingMessenger

waitForMessage

protected Message waitForMessage(long timeout)
                          throws InterruptedException
Retrieve a message from the "queue" of messages for the servlet.

Parameters:
timeout - Number of milliseconds to wait for a message. Per Java convention 0 (zero) means wait forever.
Returns:
the message or null if no message was available before the timeout was reached.
Throws:
InterruptedException - If the thread is interrupted while waiting.

messageSent

protected void messageSent(boolean wasSuccessful)

toString

public String toString()

An implementation for debugging. Do not depend on the format.


JXTA J2SE