Class Message


  • 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.
    Author:
    Simon Thoresen Hult
    • Constructor Summary

      Constructors 
      Constructor Description
      Message()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Message

        public Message()
    • Method Detail

      • swapState

        public void swapState​(Routable rhs)
        Description copied from class: Routable
        Swaps the state that makes this routable unique to another routable. The state is what identifies a routable for message bus, so only one message can ever have the same state. This function must be called explicitly when cloning and copying messages.
        Overrides:
        swapState in class Routable
        Parameters:
        rhs - The routable to swap state with.
      • getRoute

        public com.yahoo.messagebus.routing.Route getRoute()

        Return the route of this routable.

        Returns:
        The route.
      • setRoute

        public Message setRoute​(com.yahoo.messagebus.routing.Route route)

        Set a new route for this routable.

        Parameters:
        route - The new route.
        Returns:
        This, to allow chaining.
      • getTimeReceived

        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.

        Returns:
        The timestamp this was last seen.
      • setTimeReceived

        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.

        Parameters:
        timeReceived - The time received in milliseconds.
        Returns:
        This, to allow chaining.
      • setTimeReceivedNow

        public Message setTimeReceivedNow()

        This is a convenience method to call setTimeReceived(long) passing the current time as argument.

        Returns:
        This, to allow chaining.
      • getTimeRemaining

        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.

        Returns:
        The remaining time in milliseconds.
      • setTimeRemaining

        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.

        Parameters:
        timeRemaining - The number of milliseconds until expiration.
        Returns:
        This, to allow chaining.
      • getTimeRemainingNow

        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.

        Returns:
        The remaining time in milliseconds.
      • isExpired

        public boolean isExpired()

        Returns whether or not this message has expired.

        Returns:
        True if getTimeRemainingNow() is less than or equal to zero.
      • hasSequenceId

        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.

        Returns:
        True to enable sequencing.
        See Also:
        getSequenceId()
      • 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.

        Returns:
        The sequence identifier.
      • hasBucketSequence

        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.

        Returns:
        True to enable bucket sequencing.
        See Also:
        getBucketSequence()
      • 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.

        Returns:
        The bucket sequence.
      • getApproxSize

        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.

        Returns:
        1
      • setRetryEnabled

        public void setRetryEnabled​(boolean enabled)

        Sets whether or not this message can be resent.

        Parameters:
        enabled - Resendable flag.
      • getRetryEnabled

        public boolean getRetryEnabled()

        Returns whether or not this message can be resent.

        Returns:
        True if this can be resent.
      • setRetry

        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.

        Parameters:
        retry - The retry count.
        Returns:
        This, to allow chaining.