org.otfeed.support
Class CommonDelegate<T>

java.lang.Object
  extended by org.otfeed.support.CommonDelegate<T>
Type Parameters:
T - delegate type (the type of event object).
All Implemented Interfaces:
ICompletionDelegate, IDataDelegate<T>

public class CommonDelegate<T>
extends java.lang.Object
implements IDataDelegate<T>, ICompletionDelegate

Common delegate implements all delegate intefaces of the org.otfeed API. Hence, it can be passed as xxxDelegate paramater to any command object.

This object delegates actual output of the data to the dataWriter object, that defaults to SimpleDataWriter.

Arbitrary id string can be (optionally) associated with this object, allowing to use multiple instancies of this object with a single dataWriter. In this case id strings help to identify the source of the record in the dataWriter.


Constructor Summary
CommonDelegate()
          Creates new CommonDelegate, with no id, and null dataWriter.
CommonDelegate(IDataWriter writer)
          Creates new CommonDelegate with no id, and given output destination.
CommonDelegate(java.lang.String id)
          Creates new CommonDelegate with the given id string.
CommonDelegate(java.lang.String id, IDataWriter writer)
          Creates new CommonDelegate with the given id string, and given output destination.
 
Method Summary
 IDataWriter getDataWriter()
          Ouptut destination.
 java.lang.String getId()
          Arbitrary string, identifying this listener.
 void onData(T data)
          Handles data arrival event.
 void onDataEnd(OTError error)
          Handles end-of-stream event.
 void setDataWriter(IDataWriter val)
          Sets output writer.
 void setId(java.lang.String val)
          Sets id string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommonDelegate

public CommonDelegate()
Creates new CommonDelegate, with no id, and null dataWriter.


CommonDelegate

public CommonDelegate(java.lang.String id)
Creates new CommonDelegate with the given id string.

Parameters:
id - arbitrary id string. Identifies this listener.

CommonDelegate

public CommonDelegate(java.lang.String id,
                      IDataWriter writer)
Creates new CommonDelegate with the given id string, and given output destination.

Parameters:
id - id string.
writer - output destination.

CommonDelegate

public CommonDelegate(IDataWriter writer)
Creates new CommonDelegate with no id, and given output destination.

Parameters:
writer - destination.
Method Detail

getId

public java.lang.String getId()
Arbitrary string, identifying this listener. If set, it will be passed to the output writer. This allows to use a single output writer for multiple listener instencies, and still be able to distinguish which listener produced a particular record.

Returns:
id string.

setId

public void setId(java.lang.String val)
Sets id string.

Parameters:
val - id string.

getDataWriter

public IDataWriter getDataWriter()
Ouptut destination.

Returns:
output writer.

setDataWriter

public void setDataWriter(IDataWriter val)
Sets output writer.

Parameters:
val - writer.

onData

public void onData(T data)
Description copied from interface: IDataDelegate
Handles data arrival event.

Specified by:
onData in interface IDataDelegate<T>
Parameters:
data - Data event.

onDataEnd

public void onDataEnd(OTError error)
Description copied from interface: ICompletionDelegate
Handles end-of-stream event.

If data stream is ended with error (because server returned an error, or driver encountered an error condition), error parameter will be not null. On normal stream completion, error parameter is null.

It is guarnteed, that this method will be called before request completes.

Specified by:
onDataEnd in interface ICompletionDelegate
Parameters:
error - error code, if stream completion was abnormal. Null otherwise.


Copyright © 2007 Mike Kroutikov. All Rights Reserved.