com.h3c.dist.bus

## Class BusMessage

- java.lang.Object
- - com.h3c.dist.bus.BusMessage

- All Implemented Interfaces:
    Serializable

      public class BusMessage
      extends Object
      implements Serializable

  Applications and `Bus` use `BusMessage` to exchange messages.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `BusMessage.AckPolicy`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BusMessage(int t, byte[] d, BusListenerId c)`
    `BusMessage(int t, byte[] d, BusListenerId c, BusMessage.AckPolicy a)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static BusMessage` | `fromBytes(byte[] serialized, long msgId, long t)` Create BusMessage from serialized data
    `BusMessage.AckPolicy` | `getAckPolicy()` Get ack policy for message
    `long` | `getMessageId()` Get the Identifier assigned to the BusMessage.
    `int` | `getMessageType()` Get the type of the BusMessage.
    `BusListenerId` | `getMsgCreatorId()` Get Message creator ID
    `byte[]` | `getPayload()` Get message's payload
    `long` | `getPushTime()` Get time in milliseconds from epoch to when this message was pushed
    `byte[]` | `serialize()` Serialize the message to a byte array
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### BusMessage

          public BusMessage(int t,
                    byte[] d,
                    BusListenerId c)

      Parameters:
        `t` - message type
        `d` - pay load in byte array
        `c` - message creator id
      Throws:
        `IllegalArgumentException` - if pay load size is larger than `BusFactory.maxBusMsgPayloadSize`

    - #### BusMessage

          public BusMessage(int t,
                    byte[] d,
                    BusListenerId c,
                    BusMessage.AckPolicy a)

      Parameters:
        `t` - message type
        `d` - pay load in byte array
        `c` - message creator id
        `a` - ack policy to set
      Throws:
        `IllegalArgumentException` - if pay load size is larger than `BusFactory.maxBusMsgPayloadSize`

  - ### Method Detail

    - #### getMessageType

          public int getMessageType()

      Get the type of the BusMessage.
      Returns:
        message type

    - #### getMessageId

          public long getMessageId()

      Get the Identifier assigned to the BusMessage.
      Returns:
        message id

    - #### getMsgCreatorId

          public BusListenerId getMsgCreatorId()

      Get Message creator ID
      Returns:
        message creator id

    - #### getPushTime

          public long getPushTime()

      Get time in milliseconds from epoch to when this message was pushed
      Returns:
        long object which has message push time

    - #### getPayload

          public byte[] getPayload()

      Get message's payload
      Returns:
        payload in byte array

    - #### getAckPolicy

          public BusMessage.AckPolicy getAckPolicy()

      Get ack policy for message
      Returns:
        ack policy

    - #### serialize

          public byte[] serialize()
                           throws IOException

      Serialize the message to a byte array
      Returns:
        serialized object
      Throws:
        `IOException` - on serialization error

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### fromBytes

          public static BusMessage fromBytes(byte[] serialized,
                             long msgId,
                             long t)
                                      throws IOException,
                                             ClassNotFoundException

      Create BusMessage from serialized data
      Parameters:
        `serialized` - serialized bus message
        `msgId` - message id
        `t` - message type
      Returns:
        Deserialized bus message
      Throws:
        `IOException` - on decode error
        `ClassNotFoundException` - on decode error

Copyright © 2014. All Rights Reserved.