com.sun.grizzly.filter
Class MessageBase

java.lang.Object
  extended by com.sun.grizzly.filter.MessageBase
All Implemented Interfaces:
Message
Direct Known Subclasses:
ClosedMessage, FragmentMessage, InputStreamMessage, MessageError

public abstract class MessageBase
extends Object
implements Message

Note idea taken from com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase Knows how to construct various CustomProtocol Messages out of an ByteBuffer.

Author:
John Vieten Version 1.0

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.sun.grizzly.filter.Message
Message.ErrorCode
 
Field Summary
protected  byte flags
           
protected  byte messageType
           
protected  int requestId
           
protected  int sessionId
           
protected  int uniqueMessageId
           
protected  boolean useGzip
           
 
Fields inherited from interface com.sun.grizzly.filter.Message
APPLICATION_LAYER_ERROR_BIT, CurrentVersion, GZIP_BIT, HeaderLength, Magic, MagicByteLength, Message_Error, Message_Fragment, Message_Reply, Message_Request, MessageMaxLength, MORE_FRAGMENTS_BIT
 
Constructor Summary
MessageBase()
           
 
Method Summary
static void checkMagic(ByteBuffer buf, int startPosition)
          Checks if the current byteBuffer has a message starting with the correct <@link Message#Magic>
 int getMessageSize()
           
 byte getMessageType()
           
 int getNeededBytesSize()
           
 int getRequestId()
           
 int getSessionId()
           
 int getUniqueMessageId()
           
 boolean isApplicationLayerException()
           
 boolean isClean()
           
 boolean isError()
           
 boolean isGzip()
           
 boolean moreFragmentsToFollow()
          Signals that more Messages will follow all belonging to the first Message with all the same uniqueId.
static MessageBase parseHeader(ByteBuffer buf, int startPosition, ReplyMessageFactory replyInputStreamFactory)
          Parses the Header of the Custom Protocol.
protected  void setMessageType(byte messageType)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

requestId

protected int requestId

sessionId

protected int sessionId

useGzip

protected boolean useGzip

uniqueMessageId

protected int uniqueMessageId

flags

protected byte flags

messageType

protected byte messageType
Constructor Detail

MessageBase

public MessageBase()
Method Detail

parseHeader

public static MessageBase parseHeader(ByteBuffer buf,
                                      int startPosition,
                                      ReplyMessageFactory replyInputStreamFactory)
                               throws MessageParseException
Parses the Header of the Custom Protocol. The Protocol has the following format: byte 1 Magic :Used to identify Protocol byte 2 Magic byte 3 Magic byte 4 Magic byte 5 Version : Version of protocol. byte 6 Message : RequestMessage,ReplyMessage,FragmentMessage,... byte 7 Flags : In the moment : MoreFragmentsToFollow, Gzip, ApplicationLayerError byte 8 Unique Id : Helper for Fragments (Only unique by connection) byte 9 Unique Id byte 10 Unique Id byte 11 Unique Id byte 12 Size : How many bytes the Message contains (with Header) byte 13 Size byte 14 Size byte 15 Size byte 16 Request ID : The Request Id of Message (Used to Reply to Requests) byte 17 Request ID byte 18 Request ID byte 19 Request ID byte 20 Session ID : Session Id of Message (Used to authenticate Client). byte 21 Session ID byte 22 Session ID byte 23 Session ID

Parameters:
buf - Bytebuffer with read in bytes
startPosition - the message beginning
replyInputStreamFactory - need for creating a replymessage
Returns:
a Message based on the Header bytes
Throws:
MessageParseException - Indicating a parse Exception

checkMagic

public static void checkMagic(ByteBuffer buf,
                              int startPosition)
                       throws MessageParseException
Checks if the current byteBuffer has a message starting with the correct <@link Message#Magic>

Parameters:
buf - current buffer containing message bytes
startPosition - start of current message
Throws:
MessageParseException

setMessageType

protected void setMessageType(byte messageType)

getMessageType

public byte getMessageType()
Specified by:
getMessageType in interface Message

getUniqueMessageId

public int getUniqueMessageId()

isError

public boolean isError()

isClean

public boolean isClean()

getMessageSize

public int getMessageSize()

getNeededBytesSize

public int getNeededBytesSize()

moreFragmentsToFollow

public boolean moreFragmentsToFollow()
Signals that more Messages will follow all belonging to the first Message with all the same uniqueId. The last Message will return on moreFragmentsToFollow() false.

Specified by:
moreFragmentsToFollow in interface Message
Returns:
if more fragments are expected

isGzip

public boolean isGzip()

isApplicationLayerException

public boolean isApplicationLayerException()

getRequestId

public int getRequestId()
Specified by:
getRequestId in interface Message

getSessionId

public int getSessionId()


Copyright © 2012 Oracle Corporation. All Rights Reserved.