public final class SourceSession extends Object implements ReplyHandler, MessageBus.SendBlockedMessages
A session supporting sending new messages.
Modifier and Type | Method and Description |
---|---|
void |
close()
Reject all new messages and wait until no messages are pending.
|
boolean |
destroy()
Sets the destroyed flag to true.
|
int |
getPendingCount()
Returns the number of messages sent that have not been replied to
yet.
|
ReplyHandler |
getReplyHandler()
Returns the reply handler of this session.
|
void |
handleReply(Reply reply)
This function is called when a reply arrives.
|
Result |
send(Message msg)
Sends a new message.
|
Result |
send(Message msg,
com.yahoo.messagebus.routing.Route route)
This is a convenience function to assign a given route to the given
message, and then pass it to the other
send(Message) method of
this session. |
Result |
send(Message msg,
String routeName)
This is a convenience method to call
send(Message,String,boolean) with a false value for the
'parseIfNotFound' parameter. |
Result |
send(Message msg,
String routeName,
boolean parseIfNotFound)
This is a convenience function to assign a named route to the given
message, and then pass it to the other
send(Message) method of
this session. |
Result |
sendBlocking(Message msg)
This is a blocking proxy to the
send(Message) method. |
SourceSession |
setTimeout(double timeout)
Sets the number of seconds a message can be attempted sent until it
times out.
|
boolean |
trySend()
Do what you want, but dont block.
|
public boolean destroy()
public void close()
destroy()
.public Result send(Message msg)
Sends a new message. Calling this immediately causes one of three possible results:
A source client should typically do some equivalent of:
do {
Result result = sourceSession.send(message);
if (!result.isAccepted())
// Do something else or wait a while
} while (!result.isAccepted());
msg
- the message to sendpublic boolean trySend()
MessageBus.SendBlockedMessages
trySend
in interface MessageBus.SendBlockedMessages
public Result sendBlocking(Message msg) throws InterruptedException
This is a blocking proxy to the send(Message)
method. This
method blocks until the message is accepted by the send queue. Note that
the message timeout does not activate by calling this method. This method
will also return if this session is closed or the calling thread is
interrupted.
msg
- The message to send.InterruptedException
- Thrown if the calling thread is interrupted.public void handleReply(Reply reply)
ReplyHandler
handleReply
in interface ReplyHandler
reply
- The reply that arrived.public Result send(Message msg, com.yahoo.messagebus.routing.Route route)
This is a convenience function to assign a given route to the given
message, and then pass it to the other send(Message)
method of
this session.
msg
- The message to send.route
- The route to assign to the message.public Result send(Message msg, String routeName)
This is a convenience method to call send(Message,String,boolean)
with a false
value for the
'parseIfNotFound' parameter.
msg
- The message to send.routeName
- The route to assign to the message.public Result send(Message msg, String routeName, boolean parseIfNotFound)
This is a convenience function to assign a named route to the given
message, and then pass it to the other send(Message)
method of
this session. If the route could not be found this methods returns with
an appropriate error, unless the 'parseIfNotFound' argument is true. In
that case, the route name is passed through to the Route factory method
Route.parse(java.lang.String)
.
msg
- The message to send.routeName
- The route to assign to the message.parseIfNotFound
- Whether or not to parse routeName as a route if
it could not be found.public ReplyHandler getReplyHandler()
Returns the reply handler of this session.
public int getPendingCount()
Returns the number of messages sent that have not been replied to yet.
public SourceSession setTimeout(double timeout)
Sets the number of seconds a message can be attempted sent until it times out.
timeout
- The numer of seconds allowed.Copyright © 2018. All rights reserved.