Package com.rabbitmq.client.impl
Class AMQCommand
- java.lang.Object
-
- com.rabbitmq.client.impl.AMQCommand
-
- All Implemented Interfaces:
Command
public class AMQCommand extends java.lang.Object implements Command
AMQP 0-9-1-specific implementation ofCommand
which accumulates method, header and body from a series of frames, unless these are supplied at construction time.Concurrency
This class is thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description private CommandAssembler
assembler
The assembler for this command - synchronised on - contains all the stateprivate java.util.concurrent.locks.Lock
assemblerLock
static int
EMPTY_FRAME_SIZE
EMPTY_FRAME_SIZE = 8 = 1 + 2 + 4 + 1 1 byte of frame type 2 bytes of channel number 4 bytes of frame payload length 1 byte of payload trailer FRAME_END byte SeecheckEmptyFrameSize()
, an assertion checked at startup.
-
Constructor Summary
Constructors Constructor Description AMQCommand()
Construct a command ready to fill in by reading framesAMQCommand(int maxBodyLength)
AMQCommand(Method method)
Construct a command with just a method, and without header or body.AMQCommand(Method method, AMQContentHeader contentHeader, byte[] body)
Construct a command with a specified method, header and body.AMQCommand(Method method, AMQContentHeader contentHeader, byte[] body, int maxBodyLength)
Construct a command with a specified method, header and body.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
checkEmptyFrameSize()
Since we're using a pre-computed value for EMPTY_FRAME_SIZE we check this is actually correct when run against the framing code in Frame.static void
checkPreconditions()
Called to check internal code assumptions.private static java.lang.StringBuilder
contentBodyStringBuilder(byte[] body, boolean suppressBody)
byte[]
getContentBody()
Public API - Retrieves the body byte array that travelled as part of this Command, if any.AMQContentHeader
getContentHeader()
Public API - Retrieves the ContentHeader subclass instance held as part of this Command, if any.Method
getMethod()
Public API - Retrieves theMethod
held within this Command.boolean
handleFrame(Frame f)
java.lang.String
toString()
java.lang.String
toString(boolean suppressBody)
void
transmit(AMQChannel channel)
Sends this command down the named channel on the channel's connection, possibly in multiple frames.
-
-
-
Field Detail
-
EMPTY_FRAME_SIZE
public static final int EMPTY_FRAME_SIZE
EMPTY_FRAME_SIZE = 8 = 1 + 2 + 4 + 1- 1 byte of frame type
- 2 bytes of channel number
- 4 bytes of frame payload length
- 1 byte of payload trailer FRAME_END byte
checkEmptyFrameSize()
, an assertion checked at startup.- See Also:
- Constant Field Values
-
assembler
private final CommandAssembler assembler
The assembler for this command - synchronised on - contains all the state
-
assemblerLock
private final java.util.concurrent.locks.Lock assemblerLock
-
-
Constructor Detail
-
AMQCommand
AMQCommand(int maxBodyLength)
-
AMQCommand
public AMQCommand()
Construct a command ready to fill in by reading frames
-
AMQCommand
public AMQCommand(Method method)
Construct a command with just a method, and without header or body.- Parameters:
method
- the wrapped method
-
AMQCommand
public AMQCommand(Method method, AMQContentHeader contentHeader, byte[] body)
Construct a command with a specified method, header and body.- Parameters:
method
- the wrapped methodcontentHeader
- the wrapped content headerbody
- the message body data
-
AMQCommand
public AMQCommand(Method method, AMQContentHeader contentHeader, byte[] body, int maxBodyLength)
Construct a command with a specified method, header and body.- Parameters:
method
- the wrapped methodcontentHeader
- the wrapped content headerbody
- the message body datamaxBodyLength
- the maximum size for an inbound message body
-
-
Method Detail
-
getMethod
public Method getMethod()
Public API - Retrieves theMethod
held within this Command. Downcast to concrete (implementation-specific!) subclasses as necessary.
-
getContentHeader
public AMQContentHeader getContentHeader()
Public API - Retrieves the ContentHeader subclass instance held as part of this Command, if any. Downcast to one of the inner classes of AMQP, for instanceAMQP.BasicProperties
, as appropriate.- Specified by:
getContentHeader
in interfaceCommand
- Returns:
- the Command's
ContentHeader
, or null if none
-
getContentBody
public byte[] getContentBody()
Public API - Retrieves the body byte array that travelled as part of this Command, if any.- Specified by:
getContentBody
in interfaceCommand
- Returns:
- the Command's content body, or null if none
-
handleFrame
public boolean handleFrame(Frame f) throws java.io.IOException
- Throws:
java.io.IOException
-
transmit
public void transmit(AMQChannel channel) throws java.io.IOException
Sends this command down the named channel on the channel's connection, possibly in multiple frames.- Parameters:
channel
- the channel on which to transmit the command- Throws:
java.io.IOException
- if an error is encountered
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toString
public java.lang.String toString(boolean suppressBody)
-
contentBodyStringBuilder
private static java.lang.StringBuilder contentBodyStringBuilder(byte[] body, boolean suppressBody)
-
checkPreconditions
public static void checkPreconditions()
Called to check internal code assumptions.
-
checkEmptyFrameSize
private static void checkEmptyFrameSize()
Since we're using a pre-computed value for EMPTY_FRAME_SIZE we check this is actually correct when run against the framing code in Frame.
-
-