fulmine.protocol.specification
Class FrameReader

java.lang.Object
  extended by fulmine.protocol.specification.FrameReader
All Implemented Interfaces:
IFrameReader

public final class FrameReader
extends Object
implements IFrameReader

A utility class for reading fulmine delta (FD) protocol frames. Thread safe.

Please refer to the "Fulmine Delta Transmission Protocol" specification for a complete description of the fulmine serialisation technique.

Author:
Ramon Servadei
See Also:
IFrameConstants

Field Summary
static ThreadLocal<Boolean> inContext
          Allows a thread to signal it is executing in a FrameReader context.
 
Constructor Summary
FrameReader()
          Standard constructor
 
Method Summary
static void debug(byte[] frame)
          Reads an FD frame holding the state of a container.
static void findHeaderAndDataBufferPositions(byte[] frame, int start, int[] headerStart, int[] headerLength, int[] dataStart, int[] dataLength)
          Identify the header and data buffers within the frame.
 IAddressable getRemoteContainerDetailsFromFrame(byte[] frame, String remoteContextIdentity)
          Get the identity, type and domain of the container in the frame
 IContainer getRemoteContainerForFrame(byte[] frame, String remoteContextIdentity, IFrameworkContext context)
          Get the remote container for the frame.
static boolean inContext()
          Determine if the thread is executing in a FrameReader context.
 IContainer read(byte[] frame, String remoteContextIdentity, IFrameworkContext context)
          Reads an FD frame holding the state of a container.
static void readNestedIWF(IOperationScope scope, byte[] buffer, int start, int numberOfBytes, FieldReader.IFieldReaderTask readerTask)
          Read a nested FD frame that is composed of IWF fields/fields.
static void readNestedSWF(IOperationScope scope, byte[] buffer, int start, int numberOfBytes, FieldReader.IFieldReaderTask readerTask)
          Read a nested FD frame that is composed of SWF fields/fields.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inContext

public static final ThreadLocal<Boolean> inContext
Allows a thread to signal it is executing in a FrameReader context. This allows remote containers to be altered by applying changes from frames.

Constructor Detail

FrameReader

public FrameReader()
Standard constructor

Method Detail

inContext

public static boolean inContext()
Determine if the thread is executing in a FrameReader context. Only in this context can remote containers be mutated as they are being updated from a wire frame.

Returns:
true if the executing thread in a FrameReader context.

debug

public static void debug(byte[] frame)
Reads an FD frame holding the state of a container. The container to process the frame is located or created by this method.

Parameters:
frame - the byte[] holding the wire state of a container.

getRemoteContainerDetailsFromFrame

public IAddressable getRemoteContainerDetailsFromFrame(byte[] frame,
                                                       String remoteContextIdentity)
Description copied from interface: IFrameReader
Get the identity, type and domain of the container in the frame

Specified by:
getRemoteContainerDetailsFromFrame in interface IFrameReader
Parameters:
frame - the byte[] holding the wire state of a container.
remoteContextIdentity - the identity of the remote context this frame is from
Returns:
an IAddressable object identifying the identity, type and domain of the container this frame is for

getRemoteContainerForFrame

public IContainer getRemoteContainerForFrame(byte[] frame,
                                             String remoteContextIdentity,
                                             IFrameworkContext context)
Get the remote container for the frame. The container to process the frame is located or created by this method.

Specified by:
getRemoteContainerForFrame in interface IFrameReader
Parameters:
frame - the byte[] holding the wire state of a container.
remoteContextIdentity - the identity of the remote context this frame is from
context - the context to use to create the remote IContainer
Returns:
the remote IContainer for the frame.

read

public IContainer read(byte[] frame,
                       String remoteContextIdentity,
                       IFrameworkContext context)
Reads an FD frame holding the state of a container. The container to process the frame is located or created by this method.

Specified by:
read in interface IFrameReader
Parameters:
frame - the byte[] holding the wire state of a container.
remoteContextIdentity - the identity of the remote context this frame is from
context - the context to use to create the remote IContainer
Returns:
the remote IContainer with the state in the frame applied

readNestedSWF

public static void readNestedSWF(IOperationScope scope,
                                 byte[] buffer,
                                 int start,
                                 int numberOfBytes,
                                 FieldReader.IFieldReaderTask readerTask)
Read a nested FD frame that is composed of SWF fields/fields.

Parameters:
scope - the scope of the read operation
buffer - the buffer holding the nested FD frame
start - the start in the buffer for the nested FD frame
numberOfBytes - the length of the nested FD frame
readerTask - the task to invoke for each component/component in the nested FD frame as it is parsed

readNestedIWF

public static void readNestedIWF(IOperationScope scope,
                                 byte[] buffer,
                                 int start,
                                 int numberOfBytes,
                                 FieldReader.IFieldReaderTask readerTask)
Read a nested FD frame that is composed of IWF fields/fields.

Parameters:
scope - the scope of the read operation
buffer - the buffer holding the nested FD frame
start - the start in the buffer for the nested FD frame
numberOfBytes - the length of the nested FD frame
readerTask - the task to invoke for each component/component in the nested FD frame as it is parsed

findHeaderAndDataBufferPositions

public static void findHeaderAndDataBufferPositions(byte[] frame,
                                                    int start,
                                                    int[] headerStart,
                                                    int[] headerLength,
                                                    int[] dataStart,
                                                    int[] dataLength)
Identify the header and data buffers within the frame.

Parameters:
frame - the byte[] holding the header and data buffers
start - the position in the byte[] where the frame starts
headerStart - headerStart[0] will hold the position where the header buffer starts in the frame
headerLength - headerLength[0] will hold the length of the header
dataStart - dataStart[0] will hold the position where the data buffer starts in the frame
dataLength - dataLength[0] will hold the length of the data


Copyright © 2007-2009. All Rights Reserved.