Package org.gearman.common
Class GearmanPacketImpl
- java.lang.Object
-
- org.gearman.common.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.gearman.common.GearmanPacket
GearmanPacket.DataComponentName
-
-
Constructor Summary
Constructors Constructor Description GearmanPacketImpl(InputStream in)
GearmanPacketImpl(GearmanPacketMagic magic, GearmanPacketType type, byte[] data)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static byte[]
generatePacketData(byte[]... data)
byte[]
getData()
Retrieves the payload, if any, associated with this packet.byte[]
getDataComponentValue(GearmanPacket.DataComponentName component)
The data or payload of a packet can contain different set of components depending on the type of packet.int
getDataSize()
GearmanPacketMagic
getMagic()
Retrieves the magic type for this packet.GearmanPacketType
getPacketType()
Retrieves the event type for this packet.GearmanPacketType
getType()
boolean
requiresResponse()
Determine if the packet represents a request message that requires a responses from the server.byte[]
toBytes()
Retrieves the Packet as a series of bytes.String
toString()
void
write(OutputStream os)
Writes the complete packet to the specified OutputStream.
-
-
-
Constructor Detail
-
GearmanPacketImpl
public GearmanPacketImpl(GearmanPacketMagic magic, GearmanPacketType type, byte[] data)
-
GearmanPacketImpl
public GearmanPacketImpl(InputStream in)
-
-
Method Detail
-
getData
public byte[] getData()
Description copied from interface:GearmanPacket
Retrieves the payload, if any, associated with this packet.- Specified by:
getData
in interfaceGearmanPacket
- Returns:
- a copy of the array
-
getDataSize
public int getDataSize()
- Returns:
- the length in bytes of the data
-
getPacketType
public GearmanPacketType getPacketType()
Description copied from interface:GearmanPacket
Retrieves the event type for this packet.- Specified by:
getPacketType
in interfaceGearmanPacket
- Returns:
- event type.
-
getMagic
public GearmanPacketMagic getMagic()
Description copied from interface:GearmanPacket
Retrieves the magic type for this packet.- Specified by:
getMagic
in interfaceGearmanPacket
- Returns:
- The
GearmanPacketMagic
for this packet.
-
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 aGearmanJobServerConnection
.- Specified by:
toBytes
in interfaceGearmanPacket
- Returns:
- a byte array representing the packet.
-
write
public void write(OutputStream os)
Writes the complete packet to the specified OutputStream.- Parameters:
os
-
-
getType
public GearmanPacketType getType()
-
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 interfaceGearmanPacket
- 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 interfaceGearmanPacket
- 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)
-
-