Class GearmanPacketImpl

  • All Implemented Interfaces:
    GearmanPacket

    public class GearmanPacketImpl
    extends Object
    implements GearmanPacket
    Requests and responses sent between workers or clients and job servers are contained in binary packets. The packet header begins with a magic code that indicates whether a packet is a request or a response. The packet also has a type, which the receiver uses to determine what additional data should be in the packet, as well as how to interpret the data.
    • Method Detail

      • getData

        public byte[] getData()
        Description copied from interface: GearmanPacket
        Retrieves the payload, if any, associated with this packet.
        Specified by:
        getData in interface GearmanPacket
        Returns:
        a copy of the array
      • getDataSize

        public int getDataSize()
        Returns:
        the length in bytes of the data
      • toBytes

        public byte[] toBytes()
        Description copied from interface: GearmanPacket
        Retrieves the Packet as a series of bytes. Typicall called when about to send the packet over a GearmanJobServerConnection.
        Specified by:
        toBytes in interface GearmanPacket
        Returns:
        a byte array representing the packet.
      • write

        public void write​(OutputStream os)
        Writes the complete packet to the specified OutputStream.
        Parameters:
        os -
      • requiresResponse

        public boolean requiresResponse()
        Description copied from interface: GearmanPacket
        Determine if the packet represents a request message that requires a responses from the server. There are certain request messages that logically require a response, for example the GRAB_JOB message should result in a JOB_ASSIGN or NO_JOB reply from the server. While there are other messages that do not, such as CAN_DO.
        Specified by:
        requiresResponse in interface GearmanPacket
        Returns:
        true if this packet represents a request message that requires a response, else returns false.
      • getDataComponentValue

        public byte[] getDataComponentValue​(GearmanPacket.DataComponentName component)
        Description copied from interface: GearmanPacket
        The data or payload of a packet can contain different set of components depending on the type of packet. Clients of the packet class may want to extract these components from the message payload. This method provides a means for clients to extract the component without requiring knowledge of the format of the payload.
        Specified by:
        getDataComponentValue in interface GearmanPacket
        Parameters:
        component - The name of the component to be extracted.
        Returns:
        the value of the specified component. Should return an empty array if the component is not contained the packet.
      • generatePacketData

        public static byte[] generatePacketData​(byte[]... data)