|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.instantreality.InstantIO.Codec
public final class Codec
Contains meta information about Encoders and Decoders.
Encoders
and Decoders
are
used by the NetworkNode
to transfer
data values between software components on the network. Before any
data value can be transferred via the network, Encoders and
Decoders have to be written that transform data values to
system and hardware independent byte streams and vice versa.
For some frequently used data types, Encoders and Decoders
already exist in this package, but when you need to
transfer your own data types, you have to implement Encoders
and Decoders, and you have to create an instance of the Codec
class that contains meta information about these Encoders and
Decoders and registers them in the system. The meta information
consists of:
For example, let's say you want to transfer Integer
values via the network (a Codec for
Integer
of course already exists in this package,
but for the sake of demonstrating the procedure whe
nevertheless demonstrate how to create your own). First, you
have to create classes that inherit from the Encoder and
Decoder classes and implement the encoding and decoding of
data values (see the documentation for these classes to get
more information about how to do that). Then, you have to
create an instance of the Codec class that specifies the
meta information and registers the Encoder and the Decoder
in the system:
static Codec myIntCodec = new Codec( "Integer", Integer.class, MyIntEncoder.class, MyIntDecoder.class, "Patrick Dähne");
NetworkNode
,
Encoder
,
Decoder
Constructor Summary | |
---|---|
Codec(java.lang.String label,
java.lang.Class type,
java.lang.Class encoder,
java.lang.Class decoder,
java.lang.String author)
Creates a new Codec object. |
Method Summary | |
---|---|
java.lang.String |
getAuthor()
Returns the name of the person who wrote the codec. |
static java.util.Enumeration |
getCodecs()
Returns all codecs currently available. |
java.lang.String |
getLabel()
Returns the label of the codec. |
java.lang.Class |
getType()
Returns the data type that is handled by the codec. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Codec(java.lang.String label, java.lang.Class type, java.lang.Class encoder, java.lang.Class decoder, java.lang.String author)
The following example demonstrates how to create a codec that handles Integer data values:
static Codec myIntCodec = new Codec( "Integer", Integer.class, MyIntEncoder.class, MyIntDecoder.class, "Patrick Dähne");
label
- The unique label of the Codec. This label is used
to identify the Codec. Case does not matter.type
- The data type that is handled by the Codec.encoder
- The Encoder class used to encode data values.decoder
- The Decoder class used to decode data values.author
- The name of the person who wrote the codec. This
information is not used by the system in any way, it
simply serves documentation purposes.Method Detail |
---|
public java.lang.String getLabel()
The following example demonstrates how to print the label of a codec to the console:
Codec codec = ...; System.out.println("label = " + codec.getLabel());
public java.lang.Class getType()
The following example demonstrates how to print the type of a codec to the console:
Codec codec = ...; System.out.println("type = " + codec.getType().getName());
public java.lang.String getAuthor()
The following example demonstrates how to print the author of a codec to the console:
Codec codec = ...; System.out.println("author = " + codec.getAuthor());
public static java.util.Enumeration getCodecs()
The following example demonstrates how to get an Enumeration
of all codecs currently registered in the system, and prints
information about all these codecs to the console:
for (Enumeration e = Codec.getCodecs(); e.hasMoreElements(); ) { Codec codec = (Codec) e.nextElement(); System.out.println("label = " + codec.getLabel()); System.out.println("type = " + codec.getType().getName()); System.out.println("author = " + codec.getAuthor()); }
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |