Top Description Fields Constructors Methods
org.apache.coyote.ajp

public Class AjpMessage

extends Object
Class Inheritance
Imports
java.nio.ByteBuffer, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.buf.ByteChunk, .HexUtils, .MessageBytes, org.apache.tomcat.util.res.StringManager

A single packet for communication between the web server and the container. Designed to be reused many times with no creation of garbage. Understands the format of data types for these packets. Can be used (somewhat confusingly) for both incoming and outgoing packets.
Authors
Henri Gomez, Dan Milstein, Keith Wannamaker, Kevin Seguin, Costin Manolache

Field Summary

Modifier and TypeField and Description
protected final byte[]
buf

Fixed size buffer.

protected int
len

This actually means different things depending on whether the packet is read or write.

private static final Log
protected int
pos

The current read or write position in the buffer.

protected static final StringManager
sm

The string manager for this package.

Constructor Summary

AccessConstructor and Description
public
AjpMessage(int packetSize)

Method Summary

Modifier and TypeMethod and Description
public void
appendByte(int
The byte value to append
val
)

Append a byte (1 byte) to the message.

public void
appendByteChunk(ByteChunk
The data to write
bc
)

Write a ByteChunk out at the current write position.

public void
appendBytes(MessageBytes
The data to write
mb
)

Write a MessageBytes out at the current write position.

public void
appendBytes(byte[]
The array from which to copy bytes.
b
,
int
The offset into the array at which to start copying
off
,
int
The number of bytes to copy.
numBytes
)

Copy a chunk of bytes into the packet, starting at the current write position.

public void
appendBytes(ByteBuffer
The ByteBuffer from which to copy bytes.
b
)

Copy a chunk of bytes into the packet, starting at the current write position.

public void
appendInt(int
The integer to append
val
)

Add a short integer (2 bytes) to the message.

private boolean
checkOverflow(int numBytes)

private void
doGetBytes(MessageBytes mb, boolean terminated)

private void
dump(String prefix)

public void
end()

For a packet to be sent to the web server, finish the process of accumulating data and write the length of the data payload into the header.

public void
public byte[]

Returns:

The buffer
getBuffer
()

Return the underlying byte buffer.

public byte
public void
public int

Returns:

The integer value read from the message
getInt
()

Read an integer from packet, and advance the read position past it.

public int

Returns:

For read, it's the length of the payload (excluding the header). For write, it's the length of the packet as a whole (counting the header).
getLen
()

Return the current message length.

public int

Returns:

The long value read from the message
getLongInt
()

Read a 32 bits integer from packet, and advance the read position past it.

protected static String
hex(int x)

protected static String
hexLine(byte[] buf, int start, int len)

public int
public int
processHeader(boolean toContainer)

public void
reset()

Prepare this packet for accumulating a message from the container to the web server.

private void
validatePos(int posToTest)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufback to summary
protected final byte[] buf

Fixed size buffer.

lenback to summary
protected int len

This actually means different things depending on whether the packet is read or write. For read, it's the length of the payload (excluding the header). For write, it's the length of the packet as a whole (counting the header). Oh, well.

logback to summary
private static final Log log
posback to summary
protected int pos

The current read or write position in the buffer.

smback to summary
protected static final StringManager sm

The string manager for this package.

Constructor Detail

AjpMessageback to summary
public AjpMessage(int packetSize)

Method Detail

appendByteback to summary
public void appendByte(int val)

Append a byte (1 byte) to the message.

Parameters
val:int

The byte value to append

appendByteChunkback to summary
public void appendByteChunk(ByteChunk bc)

Write a ByteChunk out at the current write position. A null ByteChunk is encoded as a string with length 0.

Parameters
bc:ByteChunk

The data to write

appendBytesback to summary
public void appendBytes(MessageBytes mb)

Write a MessageBytes out at the current write position. A null MessageBytes is encoded as a string with length 0.

Parameters
mb:MessageBytes

The data to write

appendBytesback to summary
public void appendBytes(byte[] b, int off, int numBytes)

Copy a chunk of bytes into the packet, starting at the current write position. The chunk of bytes is encoded with the length in two bytes first, then the data itself, and finally a terminating \0 (which is not included in the encoded length).

Parameters
b:byte[]

The array from which to copy bytes.

off:int

The offset into the array at which to start copying

numBytes:int

The number of bytes to copy.

appendBytesback to summary
public void appendBytes(ByteBuffer b)

Copy a chunk of bytes into the packet, starting at the current write position. The chunk of bytes is encoded with the length in two bytes first, then the data itself, and finally a terminating \0 (which is not included in the encoded length).

Parameters
b:ByteBuffer

The ByteBuffer from which to copy bytes.

appendIntback to summary
public void appendInt(int val)

Add a short integer (2 bytes) to the message.

Parameters
val:int

The integer to append

checkOverflowback to summary
private boolean checkOverflow(int numBytes)
doGetBytesback to summary
private void doGetBytes(MessageBytes mb, boolean terminated)
dumpback to summary
private void dump(String prefix)
endback to summary
public void end()

For a packet to be sent to the web server, finish the process of accumulating data and write the length of the data payload into the header.

getBodyBytesback to summary
public void getBodyBytes(MessageBytes mb)
getBufferback to summary
public byte[] getBuffer()

Return the underlying byte buffer.

Returns:byte[]

The buffer

getByteback to summary
public byte getByte()
getBytesback to summary
public void getBytes(MessageBytes mb)
getIntback to summary
public int getInt()

Read an integer from packet, and advance the read position past it. Integers are encoded as two unsigned bytes with the high-order byte first, and, as far as I can tell, in little-endian order within each byte.

Returns:int

The integer value read from the message

getLenback to summary
public int getLen()

Return the current message length.

Returns:int

For read, it's the length of the payload (excluding the header). For write, it's the length of the packet as a whole (counting the header).

getLongIntback to summary
public int getLongInt()

Read a 32 bits integer from packet, and advance the read position past it. Integers are encoded as four unsigned bytes with the high-order byte first, and, as far as I can tell, in little-endian order within each byte.

Returns:int

The long value read from the message

hexback to summary
protected static String hex(int x)
hexLineback to summary
protected static String hexLine(byte[] buf, int start, int len)
peekIntback to summary
public int peekInt()
processHeaderback to summary
public int processHeader(boolean toContainer)
resetback to summary
public void reset()

Prepare this packet for accumulating a message from the container to the web server. Set the write position to just after the header (but leave the length unwritten, because it is as yet unknown).

validatePosback to summary
private void validatePos(int posToTest)