|
Sun Java(tm) System Message Queue v4.1 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sun.messaging.jmq.io.Packet
public class Packet
Encapsulation of an iMQ packet. A packet consists of three parts: 1) A fixed sized header (size HEADER_SIZE bytes) 2) A variable sized header (for holding strings, and optional packet fields) 3) A serialized java.util.Hashtable (for holding message properties) 4) the packet body (a bag of bytes) This class directly manages #1, uses PacketVariableHeader to manage #2, and uses PacketPayload to manage #3 and #4. This class also employs the use of a buffer pool to manager reuse of direct ByteBuffers. Direct ByteBuffers are an order of magnitude more expensive to allocate than normal ByteBuffers, so keeping a pool of them around is a big win (which is not typically the case for memory allocated off of the Java heap).
| Field Summary | |
|---|---|
protected ArrayList |
allocatedBuffers
|
protected static ByteBufferPool |
bbPool
|
protected int |
bitFlags
|
protected ByteBuffer |
bodyBuf
|
protected boolean |
bufferDirty
|
protected int |
bytesWritten
|
protected long |
consumerID
|
static boolean |
DEBUG
|
static int |
DEFAULT_POOL_BLOCKSIZE
|
static int |
DEFAULT_POOL_SIZE
|
protected byte |
encryption
|
protected long |
expiration
|
protected ByteBuffer |
fixedBuf
|
protected boolean |
genSequenceNumber
|
protected boolean |
genTimestamp
|
static int |
HEADER_SIZE
|
protected int |
headerBytesRead
|
protected int |
magic
|
static int |
MAGIC
|
protected static long |
maxPacketSize
|
protected int |
nBufs
|
protected PacketPayload |
packetPayload
|
protected int |
packetSize
|
protected short |
packetType
|
protected PacketVariableHeader |
packetVariableHeader
|
protected byte |
priority
|
protected ByteBuffer |
propBuf
|
protected int |
propertyOffset
|
protected int |
propertySize
|
protected ByteBuffer[] |
readBufs
|
protected int[] |
readBufsLimits
|
protected boolean |
readInProgress
|
protected int |
ropBytesRead
|
protected static int |
sequenceNumber
|
protected static long |
SIZE_LOWER_BOUND
|
protected static long |
SIZE_UPPER_BOUND
|
protected SysMessageID |
sysMessageID
|
protected long |
transactionID
|
protected boolean |
useDirect
|
protected ByteBuffer |
varBuf
|
protected short |
version
|
static short |
VERSION1
|
static short |
VERSION2
|
static short |
VERSION3
|
protected boolean |
versionMismatch
|
protected ByteBuffer[] |
writeBufs
|
protected boolean |
writeInProgress
|
| Constructor Summary | |
|---|---|
Packet()
Constructs an empty packet that will use direct buffers |
|
Packet(boolean useDirect)
Construct a packet indicating whether or not to use direct ByteBuffers. |
|
| Method Summary | |
|---|---|
void |
destroy()
Destroy a packet and put all direct buffers back into the buffer pool. |
void |
dump(PrintStream os)
|
void |
dump(PrintStream os,
String prefix)
Dump the contents of the packet in human readable form to the specified OutputStream. |
static void |
dumpBody(PrintStream os,
int pType,
InputStream is,
int bodySize,
Hashtable props)
Dump the body of the packet. |
static void |
dumpBufs(ByteBuffer[] bufs)
|
String |
dumpPacketString()
|
String |
dumpPacketString(String prefix)
Return a string containing the contents of the packet in a human readable form. |
void |
fill(Packet sourcePacket)
Fill this packet with the contents of sourcePacket. |
void |
generateSequenceNumber(boolean generate)
Disable (and enable) sequence number generation. |
void |
generateTimestamp(boolean generate)
Disable (and enable) timestamp generation. |
static ByteBufferPool |
getBufferPool()
|
boolean |
getConsumerFlow()
|
long |
getConsumerID()
|
String |
getCorrelationID()
|
String |
getDestination()
|
String |
getDestinationClass()
|
int |
getEncryption()
|
long |
getExpiration()
|
boolean |
getFlag(int flag)
|
boolean |
getFlowPaused()
|
protected ByteBuffer |
getHeaderBytes()
|
boolean |
getIndempontent()
|
byte[] |
getIP()
|
String |
getIPString()
|
boolean |
getIsLast()
|
boolean |
getIsQueue()
|
boolean |
getIsTransacted()
|
int |
getMagic()
|
static long |
getMaxPacketSize()
|
ByteBuffer |
getMessageBody()
Return the message body as a ByteBuffer. |
int |
getMessageBodySize()
Return the size of the message body in bytes |
InputStream |
getMessageBodyStream()
Return an InputStream that contains the contents of the message body. |
String |
getMessageID()
Get the MessageID for the packet. |
String |
getMessageType()
|
protected PacketPayload |
getPacketPayload()
|
int |
getPacketSize()
|
int |
getPacketType()
|
protected PacketVariableHeader |
getPacketVariableHeader()
|
boolean |
getPersistent()
|
int |
getPort()
|
int |
getPriority()
|
long |
getProducerID()
|
Hashtable |
getProperties()
Return the property hashtable for this packet. |
int |
getPropertyOffset()
|
int |
getPropertySize()
|
boolean |
getRedelivered()
|
String |
getReplyTo()
|
String |
getReplyToClass()
|
boolean |
getSelectorsProcessed()
|
boolean |
getSendAcknowledge()
|
int |
getSequence()
|
static long |
getSizeLowerBound()
|
SysMessageID |
getSysMessageID()
Get the system message ID. |
long |
getTimestamp()
|
long |
getTransactionID()
|
int |
getVersion()
|
String |
headerToString()
Return a string representation of the data in the fixed header portion of the packet. |
static long |
myChannelRead(ScatteringByteChannel channel,
ByteBuffer[] bufs,
int offset,
int length)
|
static long |
myChannelWrite(GatheringByteChannel channel,
ByteBuffer[] bufs,
int offset,
int length)
myChannelRead and myChannelWrite are used to work-around an nio bug. |
void |
readPacket(InputStream is)
Read packet from an InputStream. |
boolean |
readPacket(ScatteringByteChannel channel,
boolean block)
Read a packet from a ReadableByteChannel. |
void |
reset()
Reset packet to initial values. |
static boolean |
setBufferPool(ByteBufferPool p)
Set the ByteBufferPool that will be used to facilitate reuse of direct ByteBuffers. |
void |
setConsumerFlow(boolean b)
|
void |
setConsumerID(long n)
|
void |
setCorrelationID(String s)
|
void |
setDestination(String s)
|
void |
setDestinationClass(String s)
|
void |
setEncryption(int e)
|
void |
setExpiration(long e)
|
void |
setFlag(int flag,
boolean on)
|
void |
setFlowPaused(boolean b)
|
void |
setIndempontent(boolean b)
|
void |
setIP(byte[] ip)
|
void |
setIP(byte[] ip,
byte[] mac)
|
void |
setIsLast(boolean b)
|
void |
setIsQueue(boolean b)
|
void |
setIsTransacted(boolean b)
|
static long |
setMaxPacketSize(long n)
Set the max packet size that should be read. |
void |
setMessageBody(byte[] body)
Set the message body. |
void |
setMessageBody(byte[] body,
int off,
int len)
Set the message body. |
void |
setMessageBody(ByteBuffer body)
Set the message body. |
void |
setMessageType(String s)
|
void |
setPacketType(int pType)
Set the packet type. |
void |
setPersistent(boolean b)
|
void |
setPort(int p)
|
void |
setPriority(int p)
|
void |
setProducerID(long n)
|
void |
setProperties(Hashtable props)
Set the message properties. |
void |
setRedelivered(boolean b)
|
void |
setReplyTo(String s)
|
void |
setReplyToClass(String s)
|
void |
setSelectorsProcessed(boolean b)
|
void |
setSendAcknowledge(boolean b)
|
void |
setSequence(int n)
|
static void |
setSizeLowerBound(long n)
|
void |
setTimestamp(long t)
|
void |
setTransactionID(long n)
|
void |
setVersion(int n)
|
String |
toString()
Return a unique string that identifies the packet |
void |
updateSequenceNumber()
Update the sequence number on the packet. |
void |
updateTimestamp()
Update the timestamp on the packet. |
boolean |
writePacket(GatheringByteChannel channel,
boolean block)
Write a packet to a WritableByteChannel. |
void |
writePacket(OutputStream os)
Write the packet to an OutputStream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static boolean DEBUG
public static final int MAGIC
public static final short VERSION1
public static final short VERSION2
public static final short VERSION3
public static final int HEADER_SIZE
public static final int DEFAULT_POOL_SIZE
public static final int DEFAULT_POOL_BLOCKSIZE
protected static int sequenceNumber
protected static ByteBufferPool bbPool
protected static long SIZE_LOWER_BOUND
protected static long SIZE_UPPER_BOUND
protected static long maxPacketSize
protected boolean genTimestamp
protected boolean genSequenceNumber
protected ByteBuffer fixedBuf
protected boolean bufferDirty
protected boolean useDirect
protected ByteBuffer varBuf
protected ByteBuffer propBuf
protected ByteBuffer bodyBuf
protected ByteBuffer[] writeBufs
protected ByteBuffer[] readBufs
protected int[] readBufsLimits
protected int nBufs
protected ArrayList allocatedBuffers
protected short version
protected int magic
protected short packetType
protected int packetSize
protected long expiration
protected int propertyOffset
protected int propertySize
protected byte encryption
protected long transactionID
protected byte priority
protected int bitFlags
protected long consumerID
protected SysMessageID sysMessageID
protected PacketVariableHeader packetVariableHeader
protected PacketPayload packetPayload
protected boolean readInProgress
protected boolean writeInProgress
protected boolean versionMismatch
protected int headerBytesRead
protected int ropBytesRead
protected int bytesWritten
| Constructor Detail |
|---|
public Packet()
public Packet(boolean useDirect)
| Method Detail |
|---|
public static boolean setBufferPool(ByteBufferPool p)
public static long setMaxPacketSize(long n)
public static long getMaxPacketSize()
public static void setSizeLowerBound(long n)
public static long getSizeLowerBound()
public static ByteBufferPool getBufferPool()
public void fill(Packet sourcePacket)
throws IOException
IOExceptionpublic boolean getFlag(int flag)
public int getVersion()
public int getMagic()
public int getPacketType()
public int getPacketSize()
public long getTransactionID()
public long getProducerID()
public long getTimestamp()
public long getExpiration()
public int getPort()
public String getIPString()
public byte[] getIP()
public int getSequence()
public int getPropertyOffset()
public int getPropertySize()
public int getEncryption()
public int getPriority()
public long getConsumerID()
public boolean getPersistent()
public boolean getRedelivered()
public boolean getIsQueue()
public boolean getSelectorsProcessed()
public boolean getSendAcknowledge()
public boolean getIsLast()
public boolean getFlowPaused()
public boolean getIsTransacted()
public boolean getConsumerFlow()
public boolean getIndempontent()
public String getMessageID()
public SysMessageID getSysMessageID()
WARNING! This returns a references to the Packet's SysMessageID not a copy.
public String getDestination()
public String getDestinationClass()
public String getCorrelationID()
public String getReplyTo()
public String getReplyToClass()
public String getMessageType()
public Hashtable getProperties()
throws IOException,
ClassNotFoundException
IOException
ClassNotFoundExceptionpublic int getMessageBodySize()
public ByteBuffer getMessageBody()
public InputStream getMessageBodyStream()
public void reset()
public void setPacketType(int pType)
pType - The type of packetpublic void setTimestamp(long t)
public void setExpiration(long e)
public void setPort(int p)
public void setIP(byte[] ip)
public void setIP(byte[] ip,
byte[] mac)
public void setSequence(int n)
public void setVersion(int n)
public void setTransactionID(long n)
public void setProducerID(long n)
public void setEncryption(int e)
public void setPriority(int p)
public void setConsumerID(long n)
public void setPersistent(boolean b)
public void setRedelivered(boolean b)
public void setIsQueue(boolean b)
public void setSelectorsProcessed(boolean b)
public void setSendAcknowledge(boolean b)
public void setIsLast(boolean b)
public void setFlowPaused(boolean b)
public void setIsTransacted(boolean b)
public void setConsumerFlow(boolean b)
public void setIndempontent(boolean b)
public void setFlag(int flag,
boolean on)
public void setDestination(String s)
public void setDestinationClass(String s)
public void setCorrelationID(String s)
public void setReplyTo(String s)
public void setReplyToClass(String s)
public void setMessageType(String s)
public void setProperties(Hashtable props)
props - The message properties.public void setMessageBody(ByteBuffer body)
body - The message body.public void setMessageBody(byte[] body)
body - The message body.
public void setMessageBody(byte[] body,
int off,
int len)
body - The message body.off - Offset into body that data startslen - Size of message bodyprotected ByteBuffer getHeaderBytes()
protected PacketPayload getPacketPayload()
protected PacketVariableHeader getPacketVariableHeader()
public void generateSequenceNumber(boolean generate)
generate - true to have the packet automatically generate
sequence numbers for you, false to not. Default
is "true".public void generateTimestamp(boolean generate)
generate - true to have the packet automatically generate
a timestamp on each packet sent, false to not.
Default is "true".public void updateTimestamp()
public void updateSequenceNumber()
public boolean readPacket(ScatteringByteChannel channel,
boolean block)
throws IOException
IOException
public boolean writePacket(GatheringByteChannel channel,
boolean block)
throws IOException
IOExceptionpublic String toString()
toString in class Objectpublic String dumpPacketString(String prefix)
prefix - String to prefix string with. By default "********"public String dumpPacketString()
public static void dumpBody(PrintStream os,
int pType,
InputStream is,
int bodySize,
Hashtable props)
public void dump(PrintStream os)
public String headerToString()
public void dump(PrintStream os,
String prefix)
os - OutputStream to write packet contents toprefix - String prefix to print before the packet.
If null "********" is used.
public void readPacket(InputStream is)
throws IOException,
EOFException,
StreamCorruptedException,
IllegalArgumentException
is - the InputStream to read the packet from
IOException
EOFException
StreamCorruptedException
IllegalArgumentException
public void writePacket(OutputStream os)
throws IOException
os - The OutputStream to write the packet to
IOExceptionpublic void destroy()
public static void dumpBufs(ByteBuffer[] bufs)
public static long myChannelWrite(GatheringByteChannel channel,
ByteBuffer[] bufs,
int offset,
int length)
throws IOException
IOException
public static long myChannelRead(ScatteringByteChannel channel,
ByteBuffer[] bufs,
int offset,
int length)
throws IOException
IOException
|
Sun Java(tm) System Message Queue v4.1 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||