Class
Tree
          
SUMMARY: INNER | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD
 

com.newstep.solid.netio.slip
Class SlipFramingElement
com.newstep.solid.netio.ProtocolElement
  |
  +--com.newstep.solid.netio.slip.SlipFramingElement
All Implemented Interfaces:
       StreamListener

public class SlipFramingElement      
The framing element reads and writes SLIP messages over the configured
transport channel. The SLIP messages have the simple structure of header
containing a length indicator, optionally the header may also contain a
configurable number of blank padding bytes followed by the payload bytes of
the specified length.


The SLIP framing element leverages the scattering/gathering optimation of the
transport com.newstep.solid.netio.StreamChannel implementation
in order to read as much data on each
read as possible. Since the payload size is unknown prior to reading the
header, the most efficient scheme involves priming the read by reading a
header and then attempting to read both the payload and the header of the
next message. As such the Slip framing element leverages a java.nio.ByteBuffer array
structures as the payload ByteBuffer first followed by the fixed
(preallocated) header ByteBuffer.


In addition, the SlipFramingElement must empty the buffer on each read
notification. As such, the framing element continues to read until it is
unable to completely read either a full header or a full payload.


In processing the header, the framing element allocates the prescribed
payload buffer and proceeds to read the payload (and next header). In
processing the payload the framing element constructs a SlipMessage and
pushes it to the its associated com.newstep.solid.netio.ProtocolListener
(SlipChannel).


The header may be encoded as BYTE, UNSIGNED_BYTE, SHORT, UNSIGNED_SHORT,
or INT. In addition the header may be padded with empty bytes based on the
access point configuration. The framing element uses an associated
com.newstep.solid.netio.slip.codec.SlipMessageHeaderCodec
to provide the length encode/decode to and from the
scatter/gather ByteBuffers.

Implements:
StreamListener
 
Links:
Kernel Association Association Link
to Interface SlipMessageHeaderCodec
The message header encoding/decoding utility
Associates type:
association
Client cardinality:
1
Client navigability:
NOT NAVIGABLE
Client visibility:
private
Supplier cardinality:
1
Supplier navigability:
NAVIGABLE
Supplier visibility:
private
 
Kernel Association Association Link
to Interface StreamChannel
Associates type:
association
Client cardinality:
1
Client navigability:
NOT NAVIGABLE
Client visibility:
private
Supplier cardinality:
1
Supplier navigability:
NAVIGABLE
Supplier visibility:
private
 
Generalization Generalization Link
to Class ProtocolElement
The framing element reads and writes SLIP messages over the configured
transport channel. The SLIP messages have the simple structure of header
containing a length indicator, optionally the header may also contain a
configurable number of blank padding bytes followed by the payload bytes of
the specified length.


The SLIP framing element leverages the scattering/gathering optimation of the
transport com.newstep.solid.netio.StreamChannel implementation
in order to read as much data on each
read as possible. Since the payload size is unknown prior to reading the
header, the most efficient scheme involves priming the read by reading a
header and then attempting to read both the payload and the header of the
next message. As such the Slip framing element leverages a java.nio.ByteBuffer array
structures as the payload ByteBuffer first followed by the fixed
(preallocated) header ByteBuffer.


In addition, the SlipFramingElement must empty the buffer on each read
notification. As such, the framing element continues to read until it is
unable to completely read either a full header or a full payload.


In processing the header, the framing element allocates the prescribed
payload buffer and proceeds to read the payload (and next header). In
processing the payload the framing element constructs a SlipMessage and
pushes it to the its associated com.newstep.solid.netio.ProtocolListener
(SlipChannel).


The header may be encoded as BYTE, UNSIGNED_BYTE, SHORT, UNSIGNED_SHORT,
or INT. In addition the header may be padded with empty bytes based on the
access point configuration. The framing element uses an associated
com.newstep.solid.netio.slip.codec.SlipMessageHeaderCodec
to provide the length encode/decode to and from the
scatter/gather ByteBuffers.

 
Implementation Implementation Link
to Interface StreamListener
The framing element reads and writes SLIP messages over the configured
transport channel. The SLIP messages have the simple structure of header
containing a length indicator, optionally the header may also contain a
configurable number of blank padding bytes followed by the payload bytes of
the specified length.


The SLIP framing element leverages the scattering/gathering optimation of the
transport com.newstep.solid.netio.StreamChannel implementation
in order to read as much data on each
read as possible. Since the payload size is unknown prior to reading the
header, the most efficient scheme involves priming the read by reading a
header and then attempting to read both the payload and the header of the
next message. As such the Slip framing element leverages a java.nio.ByteBuffer array
structures as the payload ByteBuffer first followed by the fixed
(preallocated) header ByteBuffer.


In addition, the SlipFramingElement must empty the buffer on each read
notification. As such, the framing element continues to read until it is
unable to completely read either a full header or a full payload.


In processing the header, the framing element allocates the prescribed
payload buffer and proceeds to read the payload (and next header). In
processing the payload the framing element constructs a SlipMessage and
pushes it to the its associated com.newstep.solid.netio.ProtocolListener
(SlipChannel).


The header may be encoded as BYTE, UNSIGNED_BYTE, SHORT, UNSIGNED_SHORT,
or INT. In addition the header may be padded with empty bytes based on the
access point configuration. The framing element uses an associated
com.newstep.solid.netio.slip.codec.SlipMessageHeaderCodec
to provide the length encode/decode to and from the
scatter/gather ByteBuffers.

 
 

Nested Class Summary
private class
ReadType
Field Summary
private ByteBuffer
private final static String
private final static int
private ByteBuffer
private int
private int
private LengthEncoding
protected static Logger
private int
private ReadType
ReadType
HEADER
ReadType
PAYLOAD
private final static int
private final static int
private final static int
private final static int
Constructor Summary
void
SlipFramingElement(LengthEncoding lengthEncoding, Integer maxPayload, Integer headerPadding)
Method Summary
void
void
boolean
public void
boolean
void
public void
Field Detail
buffers
private ByteBuffer buffers
Multiplicity:
1
 

className
private final static String className
Final.
Multiplicity:
1
Static.
 

GATHER_ARRAY_SIZE
private final static int GATHER_ARRAY_SIZE
The number of elements used for scatter/gather style read/write. In the case of
SLIP, two elements are used, one for the header and one for the payload
Final.
Multiplicity:
1
Static.
 

header
private ByteBuffer header
Multiplicity:
1
 

headerCodec
private SlipMessageHeaderCodec headerCodec
The message header encoding/decoding utility
Multiplicity:
1
 

headerPadding
private int headerPadding
The number of blank (zero filled) byted to pad at the end of the header
Multiplicity:
1
 

headerSize
private int headerSize
The number of bytes per header calculated based on the length encoding
type plus the header padding value
Multiplicity:
1
 

lengthEncoding
private LengthEncoding lengthEncoding
The type of encoding applied to the slip message protocol.


Valid encodings are:




NOTE: values greater than those represented by signed integer are
not supported by the buffer allocation system and therefor not by the
SLIP protocol.

Multiplicity:
1
 

logger
protected static Logger logger
Multiplicity:
1
Static.
 

maxPayload
private int maxPayload
The maximum payload length. This must be valid based on the encoding
mechanism. E.g. a maxPayload of 65535 will is NOT valid with the BYTE
encoding scheme.
Multiplicity:
1
 

readType
private ReadType readType
Multiplicity:
1
 

READ_HEADER_INDEX
private final static int READ_HEADER_INDEX
Final.
Multiplicity:
1
Static.
 

READ_PAYLOAD_INDEX
private final static int READ_PAYLOAD_INDEX
Final.
Multiplicity:
1
Static.
 

transportChannel
private StreamChannel transportChannel
Multiplicity:
1
 

WRITE_HEADER_INDEX
private final static int WRITE_HEADER_INDEX
Final.
Multiplicity:
1
Static.
 

WRITE_PAYLOAD_INDEX
private final static int WRITE_PAYLOAD_INDEX
Final.
Multiplicity:
1
Static.
 
Constructor Detail
SlipFramingElement
void SlipFramingElement (LengthEncoding lengthEncoding, Integer maxPayload, Integer headerPadding)
 
Initializes the SLIP framing element and defines the maximum SLIP payload
size
Parameters:
lengthEncoding The encoding scheme to be applied to the SLIP
Channel messages
maxPayload The maximum size of SLIP message payload (in bytes)
headerPadding The number of blank byte with which the header
should be padded
Stereotype:
create
 
Method Detail
getTransportChannel
StreamChannel getTransportChannel ()
 
Gets the StreamChannel associated with the framing element
Return:
The StreamChannel associated with the framing element
 

processHeader
void processHeader ()
 
Processes the header by allocating a new payload buffer of the specified
length and setting the readType to PAYLOAD
 

processPayload
void processPayload ()
 
Processes the payload by creating a SlipMessage and notifying the
listener. The readType is set to header after the payload processing
 

readHeader
boolean readHeader ()
 
Reads just the header in order to prime the pump. The framing element
first reads a header indication (payload length) and then allocates a
buffer of the specified size. This function reads only the header.
Throws:
IOException
 

readNotify
public void readNotify ()
 
Reads the next available SLIP data and processes it based on the parsing
state machine of readType HEADER or PAYLOAD
 

readPayload
boolean readPayload ()
 
Reads the payload (and the next header if available) and processes each
Throws:
IOException
 

setTransportChannel
void setTransportChannel (StreamChannel transportChannel)
 
Assigns the specified transport channel for SLIP message read/write


NOTE: this does not set the framing element as a listener because this is
done by the SlipAccessPoint on openChannel

Parameters:
transportChannel the Transport channel overwhich the framing element
propagates read/write to the remote end point
 

write
public void write (ProtocolMessage message)
 
Writes the specified message to the transport channel. If an error occurs
during the write than the transport is closed which results in the
SlipChannel closing.
Parameters:
message The SlipMessage protocol message to write the transport
channel
 

Class
Tree
          
SUMMARY: INNER | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD