public abstract class Message extends Routable
A message is a child of Routable, it is not a reply, and it has a sequencing identifier. Furthermore, a message
contains a retry counter that holds what retry the message is currently on. See the method comment getRetry()
for more information.
Constructor and Description |
---|
Message() |
Modifier and Type | Method and Description |
---|---|
int |
getApproxSize()
Obtain the approximate size of this message object in bytes.
|
long |
getBucketSequence()
Returns the identifier used to order message buckets.
|
int |
getRetry()
Returns the number of times the sending of this message has been retried.
|
boolean |
getRetryEnabled()
Returns whether or not this message can be resent.
|
com.yahoo.messagebus.routing.Route |
getRoute()
Return the route of this routable.
|
long |
getSequenceId()
Returns the identifier used to order messages.
|
long |
getTimeReceived()
Returns the timestamp for when this message was last seen by message bus.
|
long |
getTimeRemaining()
Returns the number of milliseconds that remain before this message times out.
|
long |
getTimeRemainingNow()
Returns the number of milliseconds that remain right now before this message times out.
|
boolean |
hasBucketSequence()
Returns whether or not this message contains a sequence bucket that should be respected, i.e.
|
boolean |
hasSequenceId()
Returns whether or not this message contains a sequence identifier that should be respected, i.e.
|
boolean |
isExpired()
Returns whether or not this message has expired.
|
Message |
setRetry(int retry)
Sets the number of times the sending of this message has been retried.
|
void |
setRetryEnabled(boolean enabled)
Sets whether or not this message can be resent.
|
Message |
setRoute(com.yahoo.messagebus.routing.Route route)
Set a new route for this routable.
|
Message |
setTimeReceived(long timeReceived)
Sets the timestamp for when this message was last seen by message bus to the given time in milliseconds since
epoch.
|
Message |
setTimeReceivedNow()
This is a convenience method to call
setTimeReceived(long) passing the current time as argument. |
Message |
setTimeRemaining(long timeRemaining)
Sets the numer of milliseconds that remain before this message times out.
|
void |
swapState(Routable rhs)
Swaps the state that makes this routable unique to another routable.
|
discard, getCallStack, getContext, getProtocol, getTrace, getType, popHandler, pushHandler, setContext
public void swapState(Routable rhs)
Routable
public com.yahoo.messagebus.routing.Route getRoute()
Return the route of this routable.
public Message setRoute(com.yahoo.messagebus.routing.Route route)
Set a new route for this routable.
route
- The new route.public long getTimeReceived()
Returns the timestamp for when this message was last seen by message bus. If you are using this to determine
message expiration, you should use isExpired()
instead.
public Message setTimeReceived(long timeReceived)
Sets the timestamp for when this message was last seen by message bus to the given time in milliseconds since
epoch. Please see comment on isExpired()
for more information on how to determine whether or not a
message has expired. You should never need to call this method yourself, as it is touched automatically whenever
message bus encounters a new message.
timeReceived
- The time received in milliseconds.public Message setTimeReceivedNow()
This is a convenience method to call setTimeReceived(long)
passing the current time as argument.
public long getTimeRemaining()
Returns the number of milliseconds that remain before this message times out. This value is only updated by
the network layer, and is therefore not current. If you are trying to determine message expiration, use isExpired()
instead.
public Message setTimeRemaining(long timeRemaining)
Sets the numer of milliseconds that remain before this message times out. Please see comment on isExpired()
for more information on how to determine whether or not a message has expired.
timeRemaining
- The number of milliseconds until expiration.public long getTimeRemainingNow()
Returns the number of milliseconds that remain right now before this message times out. This is a function of
getTimeReceived()
, getTimeRemaining()
and current time. Whenever a message is transmitted by
message bus, a new remaining time is calculated and serialized as timeRemaining = timeRemaining -
(currentTime - timeReceived)
. This means that we are doing an over-estimate of remaining time, as we are
only factoring in the time used by the application above message bus.
public boolean isExpired()
Returns whether or not this message has expired.
getTimeRemainingNow()
is less than or equal to zero.public boolean hasSequenceId()
Returns whether or not this message contains a sequence identifier that should be respected, i.e. whether or not this message requires sequencing.
getSequenceId()
public long getSequenceId()
Returns the identifier used to order messages. Any two messages that have the same sequence id are ensured to
arrive at the recipient in the order they were sent by the client. This value is only respected if the hasSequenceId()
method returns true.
public boolean hasBucketSequence()
Returns whether or not this message contains a sequence bucket that should be respected, i.e. whether or not this message requires bucket-level sequencing.
getBucketSequence()
public long getBucketSequence()
Returns the identifier used to order message buckets. Any two messages that have the same bucket sequence are
ensured to arrive at the NEXT peer in the order they were sent by THIS peer. This value is only respected if the
hasBucketSequence()
method returns true.
public int getApproxSize()
Obtain the approximate size of this message object in bytes. This enables messagebus to track the size of the send queue in both memory usage and item count. This method returns 1 by default, and must be overridden to enable message size tracking.
public void setRetryEnabled(boolean enabled)
Sets whether or not this message can be resent.
enabled
- Resendable flag.public boolean getRetryEnabled()
Returns whether or not this message can be resent.
public int getRetry()
Returns the number of times the sending of this message has been retried. This is available for inspection so that clients may implement logic to control resending.
This method can be used to request resending that differs from the default.
public Message setRetry(int retry)
Sets the number of times the sending of this message has been retried. This method only makes sense to modify BEFORE sending it, since its value is not serialized back into any reply that it may create.
retry
- The retry count.Copyright © 2018. All rights reserved.