com.sun.grizzly
Class AbstractTransformer<K,L>

java.lang.Object
  extended by com.sun.grizzly.AbstractTransformer<K,L>
All Implemented Interfaces:
Transformer<K,L>
Direct Known Subclasses:
AbstractSmartMemberDecoder, AbstractSmartMemberEncoder, SmartDecoderTransformer, SmartEncoderTransformer, StringDecoder, StringEncoder

public abstract class AbstractTransformer<K,L>
extends Object
implements Transformer<K,L>

Author:
oleksiys

Field Summary
protected  AttributeBuilder attributeBuilder
           
protected static TransformationResult incompletedResult
           
protected  Attribute<K> inputBufferAttribute
           
protected  Attribute<TransformationResult<L>> lastResultAttribute
           
protected  Attribute<L> outputBufferAttribute
           
 
Constructor Summary
AbstractTransformer()
           
 
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.
 MemoryManager getMemoryManager()
           
 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.
static
<T> T
getValue(AttributeStorage storage, Attribute<T> attribute, T defaultValue)
           
 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.
protected  MemoryManager obtainMemoryManager(AttributeStorage 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 setMemoryManager(MemoryManager memoryManager)
           
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.grizzly.Transformer
transform
 

Field Detail

incompletedResult

protected static TransformationResult incompletedResult

attributeBuilder

protected AttributeBuilder attributeBuilder

inputBufferAttribute

protected Attribute<K> inputBufferAttribute

outputBufferAttribute

protected Attribute<L> outputBufferAttribute

lastResultAttribute

protected Attribute<TransformationResult<L>> lastResultAttribute
Constructor Detail

AbstractTransformer

public AbstractTransformer()
Method Detail

transform

public TransformationResult<L> transform(AttributeStorage storage)
                                  throws TransformationException
Description copied from interface: Transformer
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).

Specified by:
transform in interface Transformer<K,L>
Parameters:
storage - the external state storage, where Transformer could get/put a state.
Returns:
the result TransformationResult
Throws:
TransformationException

getInput

public K getInput(AttributeStorage storage)
Description copied from interface: Transformer
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.

Specified by:
getInput in interface Transformer<K,L>
Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.
Returns:
the Transformer input.

setInput

public void setInput(AttributeStorage storage,
                     K input)
Description copied from interface: Transformer
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.

Specified by:
setInput in interface Transformer<K,L>
Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.
input - Input data

getOutput

public L getOutput(AttributeStorage storage)
Description copied from interface: Transformer
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.

Specified by:
getOutput in interface Transformer<K,L>
Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.
Returns:
the Transformer output.

setOutput

public void setOutput(AttributeStorage storage,
                      L output)
Description copied from interface: Transformer
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.

Specified by:
setOutput in interface Transformer<K,L>
Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.
output - Output

getLastResult

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

Specified by:
getLastResult in interface Transformer<K,L>
Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.
Returns:
the last returned Transformer result.

getProperties

public AttributeHolder getProperties(AttributeStorage storage)
Description copied from interface: Transformer
Gets the property storage, using which it's possible to read or update Transformer properties.

Specified by:
getProperties in interface Transformer<K,L>
Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.
Returns:
the property storage.

hibernate

public void hibernate(AttributeStorage storage)
Description copied from interface: Transformer
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.

Specified by:
hibernate in interface Transformer<K,L>
Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.

release

public void release(AttributeStorage storage)
Description copied from interface: Transformer
The Transformer has done its work and can release all associated resource.

Specified by:
release in interface Transformer<K,L>
Parameters:
storage - the external state storage, where Transformer could retrieve or store its state.

obtainMemoryManager

protected MemoryManager obtainMemoryManager(AttributeStorage storage)

getMemoryManager

public MemoryManager getMemoryManager()

setMemoryManager

public void setMemoryManager(MemoryManager memoryManager)

getValue

public static <T> T getValue(AttributeStorage storage,
                             Attribute<T> attribute,
                             T defaultValue)


Copyright © 2009 SUN Microsystems. All Rights Reserved.