com.hazelcast.nio

## Class Packet

- java.lang.Object
- - com.hazelcast.internal.serialization.impl.HeapData
  - - com.hazelcast.nio.Packet

- All Implemented Interfaces:
    com.hazelcast.internal.networking.OutboundFrame, Data

      @PrivateApi
      public final class Packet
      extends com.hazelcast.internal.serialization.impl.HeapData
      implements com.hazelcast.internal.networking.OutboundFrame

  A Packet is a piece of data sent over the wire. The Packet is used for member to member communication. The Packet extends HeapData instead of wrapping it. From a design point of view this is often not the preferred solution (prefer composition over inheritance), but in this case that would mean more object litter. Since the Packet isn't used throughout the system, this design choice is visible locally.

- - ### Nested Class Summary

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

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `FLAG_JET_FLOW_CONTROL` Marks a Jet packet as Flow control
    `static int` | `FLAG_OP_CONTROL` Marks an Operation packet as Operation control (like invocation-heartbeats)
    `static int` | `FLAG_OP_RESPONSE` Marks an Operation packet as Response
    `static int` | `FLAG_URGENT` Marks the packet as Urgent
    `static byte` | `VERSION`

    - ### Fields inherited from class com.hazelcast.internal.serialization.impl.HeapData

      `DATA_OFFSET, HEAP_DATA_OVERHEAD, PARTITION_HASH_OFFSET, payload, TYPE_OFFSET`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Packet()`
    `Packet(byte[] payload)`
    `Packet(byte[] payload, int partitionId)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object o)`
    `Connection` | `getConn()` Gets the Connection this Packet was send with.
    `char` | `getFlags()`
    `int` | `getFrameLength()` Returns the frame length.
    `Packet.Type` | `getPacketType()`
    `int` | `getPartitionId()` Returns the partition ID of this packet.
    `int` | `hashCode()`
    `boolean` | `isFlagRaised(int flagsToCheck)` Returns `true` if any of the flags supplied in the argument are set.
    `boolean` | `isUrgent()` Checks if this Frame is urgent.
    `Packet` | `raiseFlags(int flagsToRaise)` Raises all the flags raised in the argument.
    `Packet` | `resetFlagsTo(int flagsToSet)` Resets the entire `flags` bitfield to the supplied value.
    `Packet` | `setConn(Connection conn)` Sets the Connection this Packet is send with.
    `Packet` | `setPacketType(Packet.Type type)` Sets the packet type by updating the packet type bits in the `flags` bitfield.
    `String` | `toString()`

    - ### Methods inherited from class com.hazelcast.internal.serialization.impl.HeapData

      `copyTo, dataSize, getHeapCost, getPartitionHash, getType, hash64, hasPartitionHash, isJson, isPortable, toByteArray, totalSize`

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

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

- - ### Field Detail

    - #### VERSION

          public static final byte VERSION

      See Also:
        Constant Field Values

    - #### FLAG_URGENT

          public static final int FLAG_URGENT

      Marks the packet as Urgent
      See Also:
        Constant Field Values

    - #### FLAG_OP_RESPONSE

          public static final int FLAG_OP_RESPONSE

      Marks an Operation packet as Response
      See Also:
        Constant Field Values

    - #### FLAG_OP_CONTROL

          public static final int FLAG_OP_CONTROL

      Marks an Operation packet as Operation control (like invocation-heartbeats)
      See Also:
        Constant Field Values

    - #### FLAG_JET_FLOW_CONTROL

          public static final int FLAG_JET_FLOW_CONTROL

      Marks a Jet packet as Flow control
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Packet

          public Packet()

    - #### Packet

          public Packet(byte[] payload)

    - #### Packet

          public Packet(byte[] payload,
                        int partitionId)

  - ### Method Detail

    - #### getConn

          public Connection getConn()

      Gets the Connection this Packet was send with.
      Returns:
        the Connection. Could be null.

    - #### setConn

          public Packet setConn(Connection conn)

      Sets the Connection this Packet is send with.

      This is done on the reading side of the Packet to make it possible to retrieve information about the sender of the Packet.
      Parameters:
        `conn` - the connection.
      Returns:
        `this` (for fluent interface)

    - #### getPacketType

          public Packet.Type getPacketType()

    - #### setPacketType

          public Packet setPacketType(Packet.Type type)

      Sets the packet type by updating the packet type bits in the `flags` bitfield. Other bits are unaffected.
      Parameters:
        `type` - the type to set
      Returns:
        `this` (for fluent interface)

    - #### raiseFlags

          public Packet raiseFlags(int flagsToRaise)

      Raises all the flags raised in the argument. Does not lower any flags.
      Parameters:
        `flagsToRaise` - the flags to raise
      Returns:
        `this` (for fluent interface)

    - #### resetFlagsTo

          public Packet resetFlagsTo(int flagsToSet)

      Resets the entire `flags` bitfield to the supplied value. This also affects the packet type bits.
      Parameters:
        `flagsToSet` - the flags. Only the least significant two bytes of the argument are used.
      Returns:
        `this` (for fluent interface)

    - #### isFlagRaised

          public boolean isFlagRaised(int flagsToCheck)

      Returns `true` if any of the flags supplied in the argument are set.
      Parameters:
        `flagsToCheck` - the flags to check
      Returns:
        `true` if any of the flags is set, `false` otherwise.

    - #### getFlags

          public char getFlags()

      Returns:
        the complete flags bitfield as a `char`.

    - #### getPartitionId

          public int getPartitionId()

      Returns the partition ID of this packet. If this packet is not for a particular partition, -1 is returned.
      Returns:
        the partition ID.

    - #### isUrgent

          public boolean isUrgent()

      Description copied from interface: `com.hazelcast.internal.networking.OutboundFrame`
      Checks if this Frame is urgent. Frames that are urgent, have priority above regular frames. This is useful to implement System Operations so that they can be send faster than regular operations; especially when the system is under load you want these operations have precedence.
      Specified by:
        `isUrgent` in interface `com.hazelcast.internal.networking.OutboundFrame`
      Returns:
        true if urgent, false otherwise.

    - #### getFrameLength

          public int getFrameLength()

      Description copied from interface: `com.hazelcast.internal.networking.OutboundFrame`
      Returns the frame length. This includes header and payload size.
      Specified by:
        `getFrameLength` in interface `com.hazelcast.internal.networking.OutboundFrame`
      Returns:
        The frame length.

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `com.hazelcast.internal.serialization.impl.HeapData`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `com.hazelcast.internal.serialization.impl.HeapData`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `com.hazelcast.internal.serialization.impl.HeapData`

Copyright © 2019. All rights reserved.