com.neeve.pkt
Class PktFactory

java.lang.Object
  extended by com.neeve.root.RootObject
      extended by com.neeve.pkt.PktFactory

public final class PktFactory
extends RootObject

Factory class used to instantiate packets and packet bodies.

This class is a singleton class used to instantiate packets. Packets are classified by type. Type information is loaded at class load time from a deployment's default configuration repository and also can be registered by the user programattically.

Threading:
This packet factory is not safe for concurrent access by multiple threads.

Nested Class Summary
static class PktFactory.PktType
          Stores packet type information.
 
Method Summary
 PktPacket createPacket(int pktTypeId)
          Create a packet using a packet type id.
 PktPacket createPacket(PktSerializable.DeserializeContext context)
          Create a packet from a byte buffer This method invokes createPacket(context, null)
 PktPacket createPacket(PktSerializable.DeserializeContext context, Tracer tracer)
          Create a packet from a byte buffer
 PktPacket createPacket(String pktTypeName)
          Create a packet using a packet type name.
 PktBody createPacketBody(int pktTypeId)
          Create a packet body using a packet type id
 PktBody createPacketBody(String pktTypeName)
          Create a packet body using the packet type name.
 PktPacket createPacketNonPooled(int pktTypeId)
          Create a packet using a packet type id.
static PktFactory getInstance()
          Return the singleton packet factory instance
 PktFactory.PktType getPacketType(int pktTypeId)
          Get a packet type by packet type id.
 PktFactory.PktType getPacketType(String pktTypeName)
          Get a packet type by packet type name.
 String getPacketTypeNameFromId(int pktTypeId)
          Get the packet type name by id
 void registerPacketType(PktFactory.PktType pktType)
          Register a packet type with the factory.
 
Methods inherited from class com.neeve.root.RootObject
getChecked, getThreaded, getTracer, setChecked, setTracer
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static PktFactory getInstance()
Return the singleton packet factory instance

Returns:
Returns the packet factory
Threading:
This method is safe for concurrent access by multiple threads

registerPacketType

public final void registerPacketType(PktFactory.PktType pktType)
Register a packet type with the factory.

Throws:
IllegalArgumentException - Thrown in case the supplied packet type is null.
Threading:
This method is not safe for concurrent acces by multiple threads with itself or any other method in this class.

This method is supplied for programmatic registration of packet types with the packet factory. This method should be used with caution since the underlying packet type table is not managed in a thread safe manner and invoking this method while messaging is in progress can corrupt the table. The recommended practice is to register all packet types in the local configuration repository. The factory loads up all packet types in the local repository in its class constructor thus ensuring thread safe management of the type table. If this method is used to register packet types, the user must ensure it is done so before any messaging is started.

It is a fatal error to register a packet type with a duplicate name or id. Doing so will result in an {link hava.lang.Error} being thrown.


getPacketType

public final PktFactory.PktType getPacketType(int pktTypeId)
Get a packet type by packet type id.

Threading:
This method is safe for concurrent access by multiple threads with itself and all other methods except for registerPacketType(com.neeve.pkt.PktFactory.PktType, boolean).

getPacketType

public final PktFactory.PktType getPacketType(String pktTypeName)
Get a packet type by packet type name.

Threading:
This method is safe for concurrent access by multiple threads with itself and all other methods except for registerPacketType(com.neeve.pkt.PktFactory.PktType, boolean).

getPacketTypeNameFromId

public final String getPacketTypeNameFromId(int pktTypeId)
Get the packet type name by id

Parameters:
pktTypeId - The id for which to return the name
Threading:
This method is safe for concurrent access by multiple threads with itself and all other methods except for registerPacketType(com.neeve.pkt.PktFactory.PktType, boolean).

createPacketBody

public final PktBody createPacketBody(int pktTypeId)
                               throws EPktTypeInvalidException,
                                      EPktBodyClassLoadException,
                                      EPktBodyClassInstantiateException,
                                      EPktException
Create a packet body using a packet type id

Parameters:
pktTypeId - The packet type id
Returns:
Returns the created packet body
Throws:
EPktTypeInvalidException - Thrown if the specified id is not a valid packet body type id.
EPktBodyClassLoadException - Thrown if a failure was encountered while loading the packet body class.
EPktBodyClassInstantiateException - Thrown if a failure was encountered while instantiating the packet body class.
EPktException - Thrown if any other exception was encountered while creating the new packet body.
Threading:
This method is safe for concurrent access by multiple threads with itself and all other methods except for registerPacketType(com.neeve.pkt.PktFactory.PktType, boolean).

createPacketBody

public final PktBody createPacketBody(String pktTypeName)
                               throws EPktTypeInvalidException,
                                      EPktBodyClassLoadException,
                                      EPktBodyClassInstantiateException,
                                      EPktException
Create a packet body using the packet type name.

Parameters:
pktTypeName - The packet type name
Returns:
Returns the created packet body
Throws:
EPktTypeInvalidException - Thrown if the specified name is not a valid packet type name.
EPktBodyClassLoadException - Thrown if a failure was encountered while loading the packet body class.
EPktBodyClassInstantiateException - Thrown if a failure was encountered while instantiating the packet body class.
EPktException - Thrown if any other exception was encountered while creating the new packet.
Threading:
This method is safe for concurrent access by multiple threads with itself and all other methods except for registerPacketType(com.neeve.pkt.PktFactory.PktType, boolean).

createPacket

public final PktPacket createPacket(int pktTypeId)
                             throws EPktTypeInvalidException,
                                    EPktBodyClassLoadException,
                                    EPktBodyClassInstantiateException,
                                    EPktException
Create a packet using a packet type id.

Parameters:
pktTypeId - The packet type id.
Returns:
Returns the created packet.
Throws:
EPktTypeInvalidException - Thrown if the specified id is not a valid packet body type id.
EPktBodyClassLoadException - Thrown if a failure was encountered while loading the packet body class.
EPktBodyClassInstantiateException - Thrown if a failure was encountered while instantiating the packet body class.
EPktException - Thrown if any other exception was encountered while creating the new packet.
Threading:
This method is safe for concurrent access by multiple threads with itself and all other methods except for registerPacketType(com.neeve.pkt.PktFactory.PktType, boolean).

createPacketNonPooled

public final PktPacket createPacketNonPooled(int pktTypeId)
                                      throws EPktTypeInvalidException,
                                             EPktBodyClassLoadException,
                                             EPktBodyClassInstantiateException,
                                             EPktException
Create a packet using a packet type id.

Parameters:
pktTypeId - The packet type id.
Returns:
Returns the created packet.
Throws:
EPktTypeInvalidException - Thrown if the specified id is not a valid packet body type id.
EPktBodyClassLoadException - Thrown if a failure was encountered while loading the packet body class.
EPktBodyClassInstantiateException - Thrown if a failure was encountered while instantiating the packet body class.
EPktException - Thrown if any other exception was encountered while creating the new packet.
Threading:
This method is safe for concurrent access by multiple threads with itself and all other methods except for registerPacketType(com.neeve.pkt.PktFactory.PktType, boolean).

This method is identical to createPacket(int) except that the packet is always created fresh and not from the packet type's pool
NOTE: THIS METHOD IS INTENDED FOR X PLATFORM INTERNAL USE AND SHOULD NOT BE USED. PLEASE CONSULT NEEVE TECHNICAL SUPPORT BEFORE YOU USE THIS METHOD. THIS METHOD CAN BE DEPRECATED/REMOVED/CHANGED AT ANY TIME WIHOUT NOTICE


createPacket

public final PktPacket createPacket(String pktTypeName)
                             throws EPktTypeInvalidException,
                                    EPktBodyClassLoadException,
                                    EPktBodyClassInstantiateException,
                                    EPktException
Create a packet using a packet type name.

Parameters:
pktTypeName - The packet type name.
Returns:
Returns the created packet
Throws:
EPktTypeInvalidException - Thrown if the specified name is not a valid packet type name.
EPktBodyClassLoadException - Thrown if a failure was encountered while loading the packet body class.
EPktBodyClassInstantiateException - Thrown if a failure was encountered while instantiating the packet body class.
EPktException - Thrown if any other exception was encountered while creating the new packet.
Threading:
This method is safe for concurrent access by multiple threads with itself and all other methods except for registerPacketType(com.neeve.pkt.PktFactory.PktType, boolean).

createPacket

public final PktPacket createPacket(PktSerializable.DeserializeContext context,
                                    Tracer tracer)
                             throws EPktCorruptException,
                                    EPktVersionInvalidException,
                                    EPktTypeInvalidException,
                                    EPktBodyClassLoadException,
                                    EPktBodyClassInstantiateException,
                                    EPktException
Create a packet from a byte buffer

Parameters:
context - The context to use for the deserialization process. See PktSerializable.DeserializeContext for more information.
tracer - A trace object to use to output deserialization related trace. This parameter can be null in which case no trace is output.
Returns:
Returns the created packet. This method returns null in case there is insufficient data remaining in the provided buffer to create the packet. In such a case, the context object contains information on how much additional data would be needed to create the packet.
Throws:
EPktCorruptException - Thrown if the provided buffer does not contain a valid serialized packet.
EPktVersionInvalidException - Thrown if the provided buffer contains a packet with an unsupported header format version.
EPktTypeInvalidException - Thrown if the packet type id present in the byte buffer is invalid i.e. packet type information for such a packet type was not loaded.
EPktBodyClassLoadException - Thrown if a failure was encountered while loading the packet body as specified in the configuration file for the packet type present in the buffer.
EPktBodyClassInstantiateException - Thrown if a failure was encountered while instantiating the packet body class as specified in the configuration file for the packet type found in the buffer.
EPktException - Thrown if any other exception was encountered while creating/initializing the packet.
Threading:
This method is safe for concurrent access by multiple threads with itself and all other methods except for registerPacketType(com.neeve.pkt.PktFactory.PktType, boolean).

This method instantiates a new packet from a byte buffer. The method creates a packet header, gets the packet type from the serialized buffer and instantiates a packet body using the information contained in the configuration file for the packet type. It then initialized the header and body from the provided buffer and returns a packet to the caller containing this created header and body.


createPacket

public final PktPacket createPacket(PktSerializable.DeserializeContext context)
                             throws EPktCorruptException,
                                    EPktVersionInvalidException,
                                    EPktTypeInvalidException,
                                    EPktBodyClassLoadException,
                                    EPktBodyClassInstantiateException,
                                    EPktException
Create a packet from a byte buffer

This method invokes createPacket(context, null)

Throws:
EPktCorruptException
EPktVersionInvalidException
EPktTypeInvalidException
EPktBodyClassLoadException
EPktBodyClassInstantiateException
EPktException


Copyright © 2016 Neeve Research, LLC. All Rights Reserved.