|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jarol.messages.MessageFactory
public abstract class MessageFactory
Message factory interface.
Each application message should define its own. It defines factory methods to instantiate messages, message headers and footer.
Field Summary | |
---|---|
java.nio.ByteOrder |
BYTE_ORDER
Byte order used by this factory. |
int |
FOOTER_SIZE
Footer size for messages of this factory (0 if a message factory uses no footers) |
int |
HEADER_SIZE
Header size for messages of this factory (0 if a message factory uses no headers) |
SerializationHandle |
slzHandle
Checksum procedure If null, no checksum is performed and considered for message footers. |
Constructor Summary | |
---|---|
protected |
MessageFactory(int headerSize,
int footerSize,
java.nio.ByteOrder byteOrder,
SerializationHandle slzHandle)
Constructor |
Method Summary | |
---|---|
abstract void |
checkMessageType(Message msg)
Abstract method that tests if this message is handled by this factory or not. |
Message |
fromDataArray(byte[] data)
|
abstract MessageFooter |
newFooter()
Footer instance factory method. |
abstract MessageHeader |
newHeader()
Header instance factory method. |
abstract Message |
newMessage(int id)
Message creation by serial id. |
abstract Message |
newMessage(java.lang.String name)
Message creation by name. |
void |
serialize(Message msg,
byte[] buf)
Equivalent to 'factory.serialize(msg,buf,0,buf.length)'. |
void |
serialize(Message msg,
byte[] buf,
int off,
int len)
Method to serialize a message onto an array of bytes. |
byte[] |
toByteArray(Message msg)
Convert message to byte array. |
Message |
unserialize(byte[] buf)
Convenience deserialization method for when buffer offset is 0 and usable length equals the buffer's length. |
Message |
unserialize(byte[] buf,
int off,
int len)
Method to deserialize messages from an array of bytes. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public final int HEADER_SIZE
public final int FOOTER_SIZE
public final java.nio.ByteOrder BYTE_ORDER
public final SerializationHandle slzHandle
Constructor Detail |
---|
protected MessageFactory(int headerSize, int footerSize, java.nio.ByteOrder byteOrder, SerializationHandle slzHandle)
headerSize
- header sizefooterSize
- footer sizebyteOrder
- byte order to use (BIG_ENDIAN or LITTLE_ENDIAN)slzHandle
- SerializationHandle instanceMethod Detail |
---|
public abstract Message newMessage(int id) throws InvalidMessageException
id
- Message serial id
InvalidMessageException
- when the id supplied is invalidpublic abstract Message newMessage(java.lang.String name) throws InvalidMessageException
name
- Message name
InvalidMessageException
- when the name supplied is invalidpublic abstract void checkMessageType(Message msg) throws InvalidMessageException
msg
- Message
InvalidMessageException
- if the message is not handled
by this factory.public void serialize(Message msg, byte[] buf) throws InvalidMessageException
InvalidMessageException
public void serialize(Message msg, byte[] buf, int off, int len) throws InvalidMessageException
msg
- the messagebuf
- the output bufferoff
- the output buffer offsetlen
- the usable length of the output buffer
(with at least HEADER_SIZE+msg.serialSize()+FOOTER_SIZE capacity)
InvalidMessageException
- if the message is not handled
by this message factory, or is invalid according to the
Message.validate() method
BufferException
- if the given buffer has less than
the required space (this is an instance of RuntimeException)public Message unserialize(byte[] buf) throws InvalidMessageException
InvalidMessageException
public Message unserialize(byte[] buf, int off, int len) throws InvalidMessageException
buf
- the source bufferoff
- the source buffer offsetlen
- the source buffer usable length
InvalidMessageException
- if a message was found invalid
(according to validate() method or if checksum fails)public abstract MessageHeader newHeader()
public abstract MessageFooter newFooter()
public byte[] toByteArray(Message msg) throws InvalidMessageException
msg
- message to convert
InvalidMessageException
public Message fromDataArray(byte[] data) throws InvalidMessageException
InvalidMessageException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |