eneter.messaging.messagingsystems.connectionprotocols
Class EneterProtocolFormatter

java.lang.Object
  extended by eneter.messaging.messagingsystems.connectionprotocols.EneterProtocolFormatter
All Implemented Interfaces:
IProtocolFormatter

public class EneterProtocolFormatter
extends java.lang.Object
implements IProtocolFormatter

Default Eneter encoding/decoding. This is the default protocol formatter which can be used in all types of communication.

Here is how this formatter encodes messages between channels:
Open connection message:
6 bytes - header: ENETER
1 byte - endianess: 10 little endian, 20 big endian
1 byte - string encoding: 10 UTF8, 20 UTF16
1 byte - message type: 10 for open connection
4 bytes - length: 32 bit integer indicating the size (in bytes) of the following string
x bytes - responseReceiverId: client id string

Close connection message:
6 bytes - header: ENETER
1 byte - endianess: 10 little endian, 20 big endian
1 byte - string encoding: 10 UTF8, 20 UTF16
1 byte - message type: 20 for close connection
4 bytes - length: 32 bit integer indicating the size (in bytes) of the following string
x bytes - responseReceiverId: client id string

Data message:
6 bytes - header: ENETER
1 byte - endianess: 10 little endian, 20 big endian
1 byte - string encoding: 10 UTF8, 20 UTF16
1 byte - message type: 40 for data message
4 bytes - length: 32 bit integer indicating the size (in bytes) of the following string
x bytes - responseReceiverId: client id string
1 byte - message data type: 10 bytes, 20 string
4 bytes - length: 32 bit integer indicating the size (in bytes) of the following data.
y bytes - message data: message data


Constructor Summary
EneterProtocolFormatter()
           
 
Method Summary
 ProtocolMessage decodeMessage(java.io.InputStream readStream)
          Decodes message from the stream.
 ProtocolMessage decodeMessage(java.lang.Object readMessage)
          Decodes message from the given object.
 java.lang.Object encodeCloseConnectionMessage(java.lang.String responseReceiverId)
          Encodes the close connection request message.
 void encodeCloseConnectionMessage(java.lang.String responseReceiverId, java.io.OutputStream outputSream)
          Encodes the close connection request message to the stream.
 java.lang.Object encodeMessage(java.lang.String responseReceiverId, java.lang.Object message)
          Encodes the data message.
 void encodeMessage(java.lang.String responseReceiverId, java.lang.Object message, java.io.OutputStream outputSream)
          Encodes the data message into the stream.
 java.lang.Object encodeOpenConnectionMessage(java.lang.String responseReceiverId)
          Encodes the open connection request message.
 void encodeOpenConnectionMessage(java.lang.String responseReceiverId, java.io.OutputStream outputSream)
          Encodes the open connection request message to the stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EneterProtocolFormatter

public EneterProtocolFormatter()
Method Detail

encodeOpenConnectionMessage

public java.lang.Object encodeOpenConnectionMessage(java.lang.String responseReceiverId)
                                             throws java.lang.Exception
Description copied from interface: IProtocolFormatter
Encodes the open connection request message. The message is used by the output channel to open the connection with the input channel.
If the open connection message is not used it shall return null.

Specified by:
encodeOpenConnectionMessage in interface IProtocolFormatter
Parameters:
responseReceiverId - id of the client opening the connection.
Returns:
encoded open connection message.
Throws:
java.lang.Exception

encodeOpenConnectionMessage

public void encodeOpenConnectionMessage(java.lang.String responseReceiverId,
                                        java.io.OutputStream outputSream)
                                 throws java.lang.Exception
Description copied from interface: IProtocolFormatter
Encodes the open connection request message to the stream. The message is used by the output channel to open the connection with the input channel.
If the open connection message is not used it shall just return without writing to the stream.

Specified by:
encodeOpenConnectionMessage in interface IProtocolFormatter
Parameters:
responseReceiverId - id of the client opening the connection.
outputSream - output where the encoded open connection message is written
Throws:
java.lang.Exception

encodeCloseConnectionMessage

public java.lang.Object encodeCloseConnectionMessage(java.lang.String responseReceiverId)
                                              throws java.lang.Exception
Description copied from interface: IProtocolFormatter
Encodes the close connection request message. The message is used by the output channel to close the connection with the input channel. It is also used by input channel when it disconnects the output channel.
If the close connection message is not used it shall return null.

Specified by:
encodeCloseConnectionMessage in interface IProtocolFormatter
Parameters:
responseReceiverId - id of the client that wants to disconnect or that will be disconnected
Returns:
encoded close connection message
Throws:
java.lang.Exception

encodeCloseConnectionMessage

public void encodeCloseConnectionMessage(java.lang.String responseReceiverId,
                                         java.io.OutputStream outputSream)
                                  throws java.lang.Exception
Description copied from interface: IProtocolFormatter
Encodes the close connection request message to the stream. The message is used by the output channel to close the connection with the input channel. It is also used by input channel when it disconnects the output channel.
If the close connection message is not used it shall just return without writing to the stream.

Specified by:
encodeCloseConnectionMessage in interface IProtocolFormatter
Parameters:
responseReceiverId - id of the client that wants to disconnect or that will be disconnected
outputSream - output where the encoded close connection message is written
Throws:
java.lang.Exception

encodeMessage

public java.lang.Object encodeMessage(java.lang.String responseReceiverId,
                                      java.lang.Object message)
                               throws java.lang.Exception
Description copied from interface: IProtocolFormatter
Encodes the data message. The message is used by the output as well as input channel to send the data message.

Specified by:
encodeMessage in interface IProtocolFormatter
Parameters:
responseReceiverId - client id.
message - serialized message to be sent.
Returns:
encoded data message
Throws:
java.lang.Exception

encodeMessage

public void encodeMessage(java.lang.String responseReceiverId,
                          java.lang.Object message,
                          java.io.OutputStream outputSream)
                   throws java.lang.Exception
Description copied from interface: IProtocolFormatter
Encodes the data message into the stream. The message is used by the output as well as input channel to send the data message.

Specified by:
encodeMessage in interface IProtocolFormatter
Parameters:
responseReceiverId - id of the client that wants to send the message.
message - serialized message to be sent.
outputSream - output where the encoded message is written
Throws:
java.lang.Exception

decodeMessage

public ProtocolMessage decodeMessage(java.io.InputStream readStream)
Description copied from interface: IProtocolFormatter
Decodes message from the stream.

Specified by:
decodeMessage in interface IProtocolFormatter
Parameters:
readStream - stream to be read
Returns:
decoded message

decodeMessage

public ProtocolMessage decodeMessage(java.lang.Object readMessage)
Description copied from interface: IProtocolFormatter
Decodes message from the given object.

Specified by:
decodeMessage in interface IProtocolFormatter
Parameters:
readMessage - reference to the object.
Returns:
decoded message