|
Project JXTA | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.jxta.util.AbstractSimpleSelectable
net.jxta.endpoint.AbstractMessenger
net.jxta.endpoint.ThreadedMessenger
public abstract class ThreadedMessenger
This is a messenger meant to be shared by multiple channels and automatically distribute the available bandwith among the channels. This one is implemented with a dedicated background thread.
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 | |
---|---|
ThreadedMessenger(PeerGroupID homeGroupID,
EndpointAddress destination,
EndpointAddress logicalDestination,
int channelQueueSize)
Create a new ThreadedMessenger. |
Method Summary | |
---|---|
void |
close()
Close this messenger after processing any pending messages. |
protected abstract void |
closeImpl()
Close underlying connection. |
protected abstract boolean |
connectImpl()
Make underlying connection. |
Messenger |
getChannelMessenger(PeerGroupID redirection,
String service,
String serviceParam)
If applicable, returns another messenger that will send messages to the same destination address than this one, but with the specified default service and serviceParam, possibly rewriting addresses to ensure delivery through the specified redirection. |
EndpointAddress |
getLogicalDestinationAddress()
Returns the logical destination of this messenger. |
protected abstract EndpointAddress |
getLogicalDestinationImpl()
Obtain the logical destination address from the implementer (which likely gets it from the transport messenger). |
int |
getState()
Returns the current state. |
void |
resolve()
Force the messenger to start resolving if it is not resolved yet. |
void |
run()
Runs the state machine until there's nothing left to do. |
void |
sendMessageB(Message msg,
String service,
String serviceParam)
Simple sending: blocks until the message was accepted for sending or the messenger is not Messenger.USABLE ; whichever occurs
first. |
protected abstract void |
sendMessageBImpl(Message msg,
String service,
String param)
Sends message through underlying connection. |
boolean |
sendMessageN(Message msg,
String service,
String serviceParam)
Sends a message to the destination specified at construction. In this case, this method is here out of principle but is not really expected to be invoked. |
protected void |
shutdown()
The endpoint service may call this to cause an orderly closure of its messengers. |
Methods inherited from class net.jxta.endpoint.AbstractMessenger |
---|
flush, getDestinationAddress, getDestinationAddressObject, getMTU, isClosed, 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 |
Constructor Detail |
---|
public ThreadedMessenger(PeerGroupID homeGroupID, EndpointAddress destination, EndpointAddress logicalDestination, int channelQueueSize)
homeGroupID
- the group that this messenger works for. This is the group of the endpoint service or transport
that created this messenger.destination
- where messages should be addressed tologicalDestination
- the expected logical address of the destination. Pass null if unknown/irrelevantchannelQueueSize
- the queue size that channels should have.Method Detail |
---|
public void run()
run
in interface Runnable
protected final void shutdown()
public EndpointAddress getLogicalDestinationAddress()
getDestinationAddress
and refers to
the entity which is located at the destination address.
By analogy, a telephone number would be the destination address, and
the owner of that telephone number would be the logical destination.
Each logical destination may be known by one or more destination
addresses.
getLogicalDestinationAddress
in interface Messenger
Messenger.getDestinationAddress()
public void close()
Messenger.USABLE
states, which means that no message may be sent through it. Any other effect of this
method, such as an underlying connection being closed, or all pending messages being processed, may be deferred
indefinitely. When the messenger has completely processed the closure request, it will be in one of the Messenger.TERMINAL
states (which are also Messenger.IDLE
states). Therefore, if one is interrested in the outcome of the closure, one may wait
for the messenger to be in a Messenger.TERMINAL
or Messenger.IDLE
state, and check which it is. Messenger.CLOSED
denotes success
(all outstanding messages have been sent), as opposed to Messenger.UNRESOLVABLE
or Messenger.BROKEN
.
close
in interface Messenger
public final boolean sendMessageN(Message msg, String service, String serviceParam)
Messenger.sendMessage(Message, String, String)
, except that it does not throw an exception. The invoker
has to retrieve a detailed status from the message if needed.
Error Handling:
false
indicates that the message was not accepted to be sent. This may be due to
local resource limits being reached or to the messenger being in a state that is not Messenger.USABLE
or to the message
being invalid. The exact cause of the failure can be retrieved from the message by using
Message.getMessageProperty(Messenger.class)
. If appropriate,
another attempt at sending the message, may be made after waiting for the congestion to clear (for example by using
Messenger.waitState(int, long)
).true
indicates that the message was accepted for sending. It does not imply that
the message will be sent or that the destination will receive the message. There will be no indication by this method
of any errors in sending the message. If this messenger subsequently reaches an Messenger.IDLE
state that is either Messenger.CLOSED
or a Messenger.USABLE
state, then it may be inferred that all outsdanding messages have been processed without this
messenger detecting an error.Message.getMessageProperty(Messenger.class)
will return an object of class OutgoingMessageEvent
. Changes in a message's set of properties may be tracked by
selecting the message.
Messenger.sendMessageN(net.jxta.endpoint.Message, java.lang.String, java.lang.String)
:
messenger.sendMessageN( (Message) myMessage.clone(), theService, theParam );
There is no guarantee that a message successfully sent will actually be received.
In this case, this method is here out of principle but is not really expected to be invoked. The normal way
of using a ThreadedMessenger is through its channels. We do provide a default channel that all invokers that go around
channels will share. That could be usefull to send rare out of band messages for example.
sendMessageN
in interface Messenger
msg
- The message to send.service
- Optionally replaces the service in the destination
address. If null
then the destination address's default
service will be used. If the empty string ("") is used then
no service is included in the destination address.serviceParam
- Optionally replaces the service param in the
destination address. If null
then the destination address's
default service parameter will be used. If the empty string ("") is used
then no service param is included in the destination address.
true
if the message has been accepted for sending, otherwise false
.public final void sendMessageB(Message msg, String service, String serviceParam) throws IOException
Messenger
Messenger.USABLE
; whichever occurs
first. If a service name and service param are specified, they will replace those specified at construction for the
purpose of sending this message only.
Error Handling:
IOException
means that this message is invalid or that this messenger is now in one of the non Messenger.USABLE
states and may no longer send new messages, and means that the message was not sent. The exact state of the
messenger may be obtained from the Messenger.getState()
method. If no exception is thrown, the message is accepted for
sending and may or may not be fully processed.Message#getMessageProperty(Messenger.class)
will return an
object of class OutgoingMessageEvent
. Changes in a message's set of properties may be tracked by selecting the
message. If an exception was thrown, the message's properties will not be modified
Messenger.IDLE
state that is either Messenger.CLOSED
or a Messenger.USABLE
state, then it may be inferred
that all outsdanding messages have been processed without this messenger detecting an error.Messenger.sendMessageB(net.jxta.endpoint.Message, java.lang.String, java.lang.String)
:
messenger.sendMessageB( (Message) myMessage.clone(), theService, theParam );
There is no guarantee that a message successfully sent will actually be received.
sendMessageB
in interface Messenger
service
- Optionally replaces the service in the destination
address. If null
then the destination address's default
service will be used. If the empty string ("") is used then
no service is included in the destination address.serviceParam
- Optionally replaces the service param in the
destination address. If null
then the destination address's
default service parameter will be used. If the empty string ("") is used
then no service param is included in the destination address.
IOException
- Thrown if the message cannot be sent.public final void resolve()
Messenger
resolve
in interface Messenger
public final int getState()
Messenger
getState
in interface Messenger
public Messenger getChannelMessenger(PeerGroupID redirection, String service, String serviceParam)
Messenger
Messenger.sendMessage(Message, String, String,
OutgoingMessageEventListener)
legacy method. If use of this method is desired, ChannelMessenger.setMessageWatcher(net.jxta.endpoint.ListenerAdaptor)
must be used first.
getChannelMessenger
in interface Messenger
redirection
- The requested redirection. The resulting channel messenger will use this to force
delivery of the message only in the specified group (or possibly decendants, but not parents). If null the local
group is assumed. This redirection is applied only to messages that are sent to a service name and service param that
do not imply a group redirection.service
- The service to which the resulting channel will send messages, when they are not sent to a
specified service.serviceParam
- The service parameter that the resulting channel will use to send messages, when no parameter is
specified.
MessageSender.getMessenger(EndpointAddress, Object)
protected abstract void closeImpl()
protected abstract boolean connectImpl()
protected abstract void sendMessageBImpl(Message msg, String service, String param) throws IOException
IOException
protected abstract EndpointAddress getLogicalDestinationImpl()
|
JXTA J2SE | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |