com.devexperts.qd
Interface DataVisitor

All Known Implementing Classes:
AbstractByteArrayComposer, BlobByteArrayComposer, BufferedDataVisitor, ByteArrayComposer, DataBuffer, DataSink, RecordBuffer, TextByteArrayComposer

public interface DataVisitor

The DataVisitor defines protocol of serial access to the data using Visitor pattern. It allows data provider with complicated data storage effectively give away data to external data consumer.

Specifically, DataVisitor allows data provider to take proper synchronization locks only once per large data block (and not per visited entity) and save on navigation through data storage by calculating and caching locally required references and indices.

Therefore, the implementor of DataVisitor must perform its operations quickly without need for synchronization and prolonged external actions for each step. If data consumer in its turn requires synchronized access or is otherwise slow, then it should accept DataIterator as a source of data and use intermediate data buffer (DataBuffer or equivalent).

The DataVisitor visits all available data records and for each record it visits all fields in their serial order (see DataRecord). The corresponding state diagram is shown below (note that the number and types of visited fields exactly matches number and types of the fields in the current record):

 +-----> [Ready]
 |          |
 |          1 visitRecord
 |          |
 |          V
 |  +--> [Visiting Int]
 |  |       |
 |  +-------* visitIntField
 |          |
 |          V
 |  +--> [Visiting Obj]
 |  |       |
 |  +-------* visitObjField
 |          |
 +----------+
 
NOTE: if visiting is ever aborted in a state different from [Ready], then behavior of both parties (data visitor and data provider) is undefined.

FUTURE DEPRECATION NOTE: New code shall not implement this interface due to its complexity and inherent slowness. Implement RecordSink or DataSink, or use RecordBuffer as a high-performance implementation of it. New code is also discouraged from using this interface unless it is need for interoperability with legacy code. Various legacy APIs will be gradually migrated to NG interfaces and classes.


Method Summary
 boolean hasCapacity()
          Returns whether visitor has capacity to efficiently visit next record.
 void visitIntField(DataIntField field, int value)
          Visits next Int-field within current record.
 void visitObjField(DataObjField field, java.lang.Object value)
          Visits next Obj-field within current record.
 void visitRecord(DataRecord record, int cipher, java.lang.String symbol)
          Visits next record.
 

Method Detail

hasCapacity

boolean hasCapacity()
Returns whether visitor has capacity to efficiently visit next record. This method may be used to advise data provider that it is desirable to stop current string of visiting and to keep remaining data. However, at present, data provider is not obliged to adhere to this method contract.

NOTE: data visitor must process all data that is passed to it via visitXXX calls no matter whether it has capacity to do it efficiently.


visitRecord

void visitRecord(DataRecord record,
                 int cipher,
                 java.lang.String symbol)
Visits next record.

Throws:
java.lang.IllegalStateException - if visitor is not in [Ready] state.

visitIntField

void visitIntField(DataIntField field,
                   int value)
Visits next Int-field within current record.

Throws:
java.lang.IllegalStateException - if visitor is not in a state to visit specified field.

visitObjField

void visitObjField(DataObjField field,
                   java.lang.Object value)
Visits next Obj-field within current record.

Throws:
java.lang.IllegalStateException - if visitor is not in a state to visit specified field.