org.glassfish.grizzly
Interface Transformer<K,L>

All Known Subinterfaces:
SmartMemberTransformer<K,L>, SmartTransformer<K,L>
All Known Implementing Classes:
AbstractSmartMemberDecoder, AbstractSmartMemberEncoder, AbstractTransformer, ArrayDecoder, ArrayEncoder, ByteDecoder, ByteEncoder, CharDecoder, CharEncoder, DefaultDecoderTransformer, DefaultEncoderTransformer, DoubleDecoder, DoubleEncoder, FloatDecoder, FloatEncoder, IntegerDecoder, IntegerEncoder, LongDecoder, LongEncoder, PrimitiveDecoder, PrimitiveEncoder, SequenceDecoder, SequenceEncoder, ShortDecoder, ShortEncoder, SmartDecoderTransformer, SmartEncoderTransformer, SmartStringDecoder, SmartStringEncoder, SSLDecoderTransformer, SSLEncoderTransformer, SSLHandshakeDecoder, SSLHandshakeEncoder, StringDecoder, StringEncoder

public interface Transformer<K,L>

Transformer interface, which knows how to transform the original data to some custom representation. A Transformer implementation could be stateful or stateless. However it's very easy to write stateful Transformer, which actaully doesn't save any state internally, but uses AttributeStorage as an external state storage. Please note, that AttributeStorage is being passed as the parameter to all Transformer methods. This way it's possible to reuse single instance of a stateful Transformer to process lots of concurrent transformations.

Author:
Alexey Stashok

Method Summary
 K getInput(AttributeStorage storage)
          Gets the input data, which Transformer will work with.
 TransformationResult<L> getLastResult(AttributeStorage storage)
          Gets the last returned Transformer result.
 L getOutput(AttributeStorage storage)
          Gets the output, which Transformer will use for transformed data.
 AttributeHolder getProperties(AttributeStorage storage)
          Gets the property storage, using which it's possible to read or update Transformer properties.
 void hibernate(AttributeStorage storage)
          Method could be called by framework to let Transformer know, that transformation will be postponed and probably continued in separate Thread, so all resources, which are associated with the current Thread should be detached and stored internally or in the external storage.
 void release(AttributeStorage storage)
          The Transformer has done its work and can release all associated resource.
 void setInput(AttributeStorage storage, K input)
          Sets the input data, which Transformer will work with.
 void setOutput(AttributeStorage storage, L output)
          Gets the output, which Transformer will use for transformed data.
 TransformationResult<L> transform(AttributeStorage storage)
          Transforms an input data to some custom representation.
 TransformationResult<L> transform(AttributeStorage storage, K input, L output)
          Transforms an input data to some custom representation.
 

Method Detail

transform

TransformationResult<L> transform(AttributeStorage storage)
                                  throws TransformationException
Transforms an input data to some custom representation. Input and output are not passed implicitly, which means that Transformer is able to retrieve input and output from its internal state or from external storage (AttributeStorage).

Parameters:
storage - the external state storage, where Transformer could get/put a state.
Returns:
the result TransformationResult
Throws:
TransformationException

transform

TransformationResult<L> transform(AttributeStorage storage,
                                  K input,
                                  L output)
                                  throws TransformationException
Transforms an input data to some custom representation.

Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.
Returns:
the result TransformationResult
Throws:
TransformationException

getInput

K getInput(AttributeStorage storage)
Gets the input data, which Transformer will work with. Very often Transformers are used together with I/O operations. When Transformer is used with read operation, this method may return a Buffer, where "reader" will read the data to. But note, the returned Buffer should always represent READY data.In other words, if there is no data to be transformed - the Buffer should have 0 remaining bytes.

Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.
Returns:
the Transformer input.

setInput

void setInput(AttributeStorage storage,
              K input)
Sets the input data, which Transformer will work with. Very often Transformers are used together with I/O operations. When Transformer is used with read operation, the input Buffer will be used by "reader" to read the data to. But note, the input Buffer should always represent READY data.In other words, if there is no data to be transformed - the Buffer should have 0 remaining bytes.

Parameters:
input - Input data
storage - the external state storage, where Transformer could retrieve or store its state.

getOutput

L getOutput(AttributeStorage storage)
Gets the output, which Transformer will use for transformed data. Although output could be used to get a result of transformation, it is recommended to return transformation result directly from transform method within TransformationResult.

Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.
Returns:
the Transformer output.

setOutput

void setOutput(AttributeStorage storage,
               L output)
Gets the output, which Transformer will use for transformed data. Although output could be used to get a result of transformation, it is recommended to return transformation result directly from transform method within TransformationResult.

Parameters:
output - Output
storage - the external state storage, where Transformer could retrieve or store its state.

getLastResult

TransformationResult<L> getLastResult(AttributeStorage storage)
Gets the last returned Transformer result. Last result could be either retrieved from internal state, or external storage, which is passed as the parameter.

Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.
Returns:
the last returned Transformer result.

getProperties

AttributeHolder getProperties(AttributeStorage storage)
Gets the property storage, using which it's possible to read or update Transformer properties.

Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.
Returns:
the property storage.

hibernate

void hibernate(AttributeStorage storage)
Method could be called by framework to let Transformer know, that transformation will be postponed and probably continued in separate Thread, so all resources, which are associated with the current Thread should be detached and stored internally or in the external storage.

Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.

release

void release(AttributeStorage storage)
The Transformer has done its work and can release all associated resource.

Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.


Copyright © 2009 SUN Microsystems. All Rights Reserved.