|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.fudgemsg.FudgeContext
public class FudgeContext
The primary entry-point for code to interact with the rest of the Fudge system. For performance reasons, there are many options that are passed around as parameters inside static methods for encoding and decoding, and many lightweight objects that ideally don't know of their configuration context. However, in a large application, it is often desirable to collect all configuration parameters in one location and inject options into it.
FudgeContext
allows application developers to have a single location
to inject dependent parameters and instances, and make them available through
simple method invocations. In addition, because it wraps all checked exceptions
into instances of FudgeRuntimeException
, it is the ideal way to use
the Fudge encoding system from within Spring applications.
While most applications will have a single instance of FudgeContext
,
some applications will have one instance per unit of encoding/decoding parameters.
For example, if an application is consuming data from two messaging feeds, each
of which reuses the same taxonomy ID to represent a different
FudgeTaxonomy
, it would configure two different instances of
FudgeContext
, one per feed.
Field Summary | |
---|---|
static FudgeFieldContainer |
EMPTY_MESSAGE
A global empty FudgeFieldContainer . |
static FudgeMsgEnvelope |
EMPTY_MESSAGE_ENVELOPE
A global empty FudgeMsgEnvelope . |
static FudgeContext |
GLOBAL_DEFAULT
A default global FudgeContext for getting code up and running quickly. |
Constructor Summary | |
---|---|
FudgeContext()
Constructs a new FudgeContext with a default type and object dictionary. |
|
FudgeContext(FudgeContext other)
Constructs a new FudgeContext with copies of the supplied context's type and object dictionaries. |
Method Summary | ||
---|---|---|
FudgeMsgReader |
createMessageReader(DataInput dataInput)
Creates a new reader for extracting whole Fudge messages from a DataInput source. |
|
FudgeMsgReader |
createMessageReader(InputStream inputStream)
Creates a new reader for extracting whole Fudge messages from a InputStream source. |
|
FudgeMsgWriter |
createMessageWriter(DataOutput dataOutput)
Creates a new writer for sending whole Fudge messages to a DataOutput target. |
|
FudgeMsgWriter |
createMessageWriter(OutputStream outputStream)
Creates a new writer for sending whole Fudge messages to a OutputStream target. |
|
FudgeObjectReader |
createObjectReader(DataInput dataInput)
Creates a new reader for deserialising Java objects from a Fudge data source. |
|
FudgeObjectReader |
createObjectReader(InputStream inputStream)
Creates a new reader for deserialising Java objects from a Fudge data source. |
|
FudgeObjectWriter |
createObjectWriter(DataOutput dataOutput)
Creates a new writer for serialising Java objects to a Fudge stream. |
|
FudgeObjectWriter |
createObjectWriter(OutputStream outputStream)
Creates a new writer for serialising Java objects to a Fudge stream. |
|
FudgeStreamReader |
createReader(DataInput di)
Creates a new reader for extracting Fudge stream elements from a DataInput . |
|
FudgeStreamReader |
createReader(InputStream is)
Creates a new reader for extracting Fudge stream elements from an InputStream . |
|
FudgeStreamWriter |
createWriter(DataOutput dataOutput)
Creates a new writer for encoding Fudge stream elements to a DataOutput . |
|
FudgeStreamWriter |
createWriter(OutputStream outputStream)
Creates a new writer for encoding Fudge stream elements to a OutputStream . |
|
FudgeMsgEnvelope |
deserialize(byte[] bytes)
Decodes a Fudge message from a byte array. |
|
FudgeMsgEnvelope |
deserialize(InputStream is)
Decodes a Fudge message from an InputStream . |
|
|
fromFudgeMsg(Class<T> clazz,
FudgeFieldContainer message)
Deserializes a FudgeFieldContainer message to a Java object of type clazz . |
|
Object |
fromFudgeMsg(FudgeFieldContainer message)
Deserializes a FudgeFieldContainer message to a Java object, trying to determine the
type of the object automatically. |
|
|
getFieldValue(Class<T> clazz,
FudgeField field)
Type conversion for secondary types using information registered in the current type dictionary. |
|
FudgeObjectDictionary |
getObjectDictionary()
Returns the current FudgeObjectDictionary used by the context for object/Fudge message serialisation and deserialisation. |
|
TaxonomyResolver |
getTaxonomyResolver()
Returns the current TaxonomyResolver used by this context. |
|
FudgeTypeDictionary |
getTypeDictionary()
Returns the current FudgeTypeDictionary used by this context and any messages created or decoded through it. |
|
MutableFudgeFieldContainer |
newMessage()
Creates an initially empty message. |
|
MutableFudgeFieldContainer |
newMessage(FudgeFieldContainer fromMessage)
Creates a new message initially populated with the supplied message. |
|
|
readObject(Class<T> objectClass,
InputStream inputStream)
Reads a Java object from an InputStream using the Fudge serialization framework. |
|
void |
serialize(FudgeFieldContainer msg,
OutputStream os)
Encodes a Fudge message object to an OutputStream without any
taxonomy reference. |
|
void |
serialize(FudgeFieldContainer msg,
Short taxonomyId,
OutputStream os)
Encodes a Fudge message object to an OutputStream with an
optional taxonomy reference. |
|
void |
setConfiguration(FudgeContextConfiguration... configurations)
Passes this context to the configuration objects supplied to update the type and object dictionaries. |
|
void |
setObjectDictionary(FudgeObjectDictionary objectDictionary)
Sets the current FudgeObjectDictionary to be used for object/Fudge message serialisation and deserialisation. |
|
void |
setTaxonomyResolver(TaxonomyResolver taxonomyResolver)
Sets the TaxonomyResolver to be used by this context when expanding field names for incoming Fudge messages. |
|
void |
setTypeDictionary(FudgeTypeDictionary typeDictionary)
Sets the current FudgeTypeDictionary to be used by the context and any messages created or decoded through it. |
|
byte[] |
toByteArray(FudgeFieldContainer msg)
Returns the Fudge encoded form of a FudgeFieldContainer as a byte array without a taxonomy reference. |
|
byte[] |
toByteArray(FudgeFieldContainer msg,
Short taxonomyId)
Returns the Fudge encoded form of a FudgeFieldContainer as a byte array
with a taxonomy reference. |
|
|
toFudgeMsg(T obj)
Converts a Java object to a FudgeMsgEnvelope using the Fudge serialization framework. |
|
void |
writeObject(Object object,
OutputStream outputStream)
Writes a Java object to an OutputStream using the Fudge serialization framework. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final FudgeContext GLOBAL_DEFAULT
FudgeContext
for getting code up and running quickly. The context cannot be modified
in any way so can only be used for the core Fudge data types and will not support a taxonomy resolver. This
should be used for trivial projects and code only.
public static final FudgeFieldContainer EMPTY_MESSAGE
FudgeFieldContainer
.
public static final FudgeMsgEnvelope EMPTY_MESSAGE_ENVELOPE
FudgeMsgEnvelope
.
Constructor Detail |
---|
public FudgeContext()
public FudgeContext(FudgeContext other)
other
- the context to copy the type and object dictionaries fromMethod Detail |
---|
public TaxonomyResolver getTaxonomyResolver()
TaxonomyResolver
used by this context. A new FudgeContext
starts with its own, default,
taxonomy resolver. Any custom taxonomies must be registered with a resolver before they can be used.
public void setTaxonomyResolver(TaxonomyResolver taxonomyResolver)
TaxonomyResolver
to be used by this context when expanding field names for incoming Fudge messages.
taxonomyResolver
- the TaxonomyResolver
to setpublic FudgeTypeDictionary getTypeDictionary()
FudgeTypeDictionary
used by this context and any messages created or decoded through it. A new
FudgeContext
starts with its own, default, type dictionary. Any custom types must be registered with the dictionary
before they can be used.
FudgeTypeDictionary
public void setTypeDictionary(FudgeTypeDictionary typeDictionary)
FudgeTypeDictionary
to be used by the context and any messages created or decoded through it.
typeDictionary
- the new FudgeTypeDictionary
public FudgeObjectDictionary getObjectDictionary()
FudgeObjectDictionary
used by the context for object/Fudge message serialisation and deserialisation.
A new FudgeContext
starts with its own, default, object dictionary. Any custom object or message builders must be
registered with the dictionary before they can be used.
FudgeObjectDictionary
public void setObjectDictionary(FudgeObjectDictionary objectDictionary)
FudgeObjectDictionary
to be used for object/Fudge message serialisation and deserialisation.
objectDictionary
- the new FudgeObjectDictionary
public MutableFudgeFieldContainer newMessage()
newMessage
in interface FudgeMessageFactory
public MutableFudgeFieldContainer newMessage(FudgeFieldContainer fromMessage)
newMessage
in interface FudgeMessageFactory
fromMessage
- the source message to copy fields from, not null
public void serialize(FudgeFieldContainer msg, OutputStream os)
OutputStream
without any
taxonomy reference.
msg
- the FudgeFieldContainer
to writeos
- the OutputStream
to write topublic void serialize(FudgeFieldContainer msg, Short taxonomyId, OutputStream os)
OutputStream
with an
optional taxonomy reference. If a taxonomy is supplied it may be used to
optimize the output by writing ordinals instead of field names.
msg
- the FudgeMsg
to writetaxonomyId
- the identifier of the taxonomy to use. Specify null
for no
taxonomy.os
- the OutputStream
to write topublic byte[] toByteArray(FudgeFieldContainer msg, Short taxonomyId)
FudgeFieldContainer
as a byte
array
with a taxonomy reference. The encoding includes an envelope header.
msg
- the FudgeFieldContainer
to encodetaxonomyId
- the identifier of the taxonomy to use. Specify null
or 0
for no taxonomy
public byte[] toByteArray(FudgeFieldContainer msg)
FudgeFieldContainer
as a byte
array without a taxonomy reference.
The encoding includes an envelope header.
msg
- the FudgeFieldContainer
to encode
public FudgeMsgEnvelope deserialize(InputStream is)
InputStream
.
is
- the InputStream
to read encoded data from
FudgeMsgEnvelope
encoded on the streampublic FudgeMsgEnvelope deserialize(byte[] bytes)
byte
array. If the array is
larger than the Fudge envelope, any additional data is ignored.
bytes
- an array containing the encoded Fudge message including its envelope
FudgeMsgEnvelope
public FudgeStreamReader createReader(InputStream is)
InputStream
.
is
- the InputStream
to read from
FudgeStreamReader
public FudgeStreamReader createReader(DataInput di)
DataInput
.
di
- the DataInput
to read from
FudgeStreamReader
public FudgeStreamWriter createWriter(OutputStream outputStream)
OutputStream
.
outputStream
- the OutputStream
to write to
FudgeStreamWriter
public FudgeStreamWriter createWriter(DataOutput dataOutput)
DataOutput
.
dataOutput
- the DataOutput
to write to
FudgeStreamWriter
public FudgeMsgReader createMessageReader(DataInput dataInput)
DataInput
source.
dataInput
- the source of data
FudgeMsgReader
public FudgeMsgReader createMessageReader(InputStream inputStream)
InputStream
source.
inputStream
- the source of data
FudgeMsgReader
public FudgeMsgWriter createMessageWriter(DataOutput dataOutput)
DataOutput
target.
dataOutput
- the target to write to
FudgeMsgWriter
public FudgeMsgWriter createMessageWriter(OutputStream outputStream)
OutputStream
target.
outputStream
- the target to write to
FudgeMsgWriter
public FudgeObjectReader createObjectReader(DataInput dataInput)
dataInput
- the DataInput
to read from
FudgeObjectReader
public FudgeObjectReader createObjectReader(InputStream inputStream)
inputStream
- the InputStream
to read from
FudgeObjectReader
public FudgeObjectWriter createObjectWriter(DataOutput dataOutput)
dataOutput
- the target to write to
FudgeObjectWriter
public FudgeObjectWriter createObjectWriter(OutputStream outputStream)
outputStream
- the target to write to
FudgeObjectWriter
public void writeObject(Object object, OutputStream outputStream)
OutputStream
using the Fudge serialization framework. The
current FudgeObjectDictionary
will be used to identify any custom message builders or apply
default serialization behavior. Either a new serialization context will be used or an existing
one reset for this operation.
object
- the Object
to writeoutputStream
- the OutputStream
to write the Fudge encoded form of the object topublic <T> T readObject(Class<T> objectClass, InputStream inputStream)
InputStream
using the Fudge serialization framework. The
current FudgeObjectDictionary
will be used to identify any custom object builders or apply
default deserialization behavior. Always reads the next available Fudge message from the
stream even if the message cannot be converted to the requested Object. Either a new deserialization
context will be used or an existing one reset for this operation.
T
- the target type to decode the message toobjectClass
- the target Class
to decode a message of. If an object of this or a sub-class is not available, an exception will be thrown.inputStream
- the InputStream
to read the next Fudge message from
public <T> FudgeMsgEnvelope toFudgeMsg(T obj)
FudgeMsgEnvelope
using the Fudge serialization framework. Note
that for repeated operations, it would be more efficient to maintain a FudgeSerializationContext
instance and use that.
T
- Java typeobj
- object to serialize
public Object fromFudgeMsg(FudgeFieldContainer message)
FudgeFieldContainer
message to a Java object, trying to determine the
type of the object automatically. Note that for repeated operations, it would be more efficient to maintain
a FudgeDeserializationContext
instance and use that.
message
- the Fudge message to deserialize
public <T> T fromFudgeMsg(Class<T> clazz, FudgeFieldContainer message)
FudgeFieldContainer
message to a Java object of type clazz
. Note that for
repeated operations, it would be more efficient to maintain a FudgeDeserializationContext
instance and use that.
T
- Java typeclazz
- the target type to deserializemessage
- the message to process
public <T> T getFieldValue(Class<T> clazz, FudgeField field)
FudgeTypeDictionary.getFieldValue(java.lang.Class, org.fudgemsg.FudgeField)
for more information.
T
- type to convert toclazz
- target class for the converted valuefield
- field containing the value to convert
public void setConfiguration(FudgeContextConfiguration... configurations)
configurations
- the configuration objects to use
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |