gr.uoa.di.madgik.grs.writer
Class RecordWriter<T extends Record>

java.lang.Object
  extended by gr.uoa.di.madgik.grs.writer.RecordWriter<T>
All Implemented Interfaces:
IRecordWriter<T>

public class RecordWriter<T extends Record>
extends java.lang.Object
implements IRecordWriter<T>


Field Summary
static int DefaultBufferCapacity
           
static int DefaultConcurrentPartialCapacity
           
static long DefaultInactivityTimeout
           
static java.util.concurrent.TimeUnit DefaultInactivityTimeUnit
           
static float DefaultMirrorBufferFactor
           
static float DefaultThreshold
           
 
Constructor Summary
RecordWriter(IWriterProxy proxy, IRecordReader reader)
          Creates a new instance using the configuration retrieved from an IRecordReader.
RecordWriter(IWriterProxy proxy, IRecordReader reader, int capacity, int concurrentPartialCapacity, float mirrorSizeFactor)
          Creates a new instance using the same record definitions as the ones of the supplied IRecordReader.
RecordWriter(IWriterProxy proxy, IRecordReader reader, int capacity, int concurrentPartialCapacity, float mirrorSizeFactor, long inactivityTimeout, java.util.concurrent.TimeUnit inactivityTimeUnit)
          Creates a new instance using the same record definitions as the ones of the supplied IRecordReader.
RecordWriter(IWriterProxy proxy, RecordDefinition[] definitions)
          Creates a new instance
RecordWriter(IWriterProxy proxy, RecordDefinition[] definitions, int capacity, int concurrentPartialCapacity, float mirrorSizeFactor)
          Creates a new instance
RecordWriter(IWriterProxy proxy, RecordDefinition[] definitions, int capacity, int concurrentPartialCapacity, float mirrorSizeFactor, long inactivityTimeout, java.util.concurrent.TimeUnit inactivityTimeUnit)
          Creates a new instance
 
Method Summary
 int availableRecords()
          The number of readily available for consumption Records
 void close()
          Closes the underlying buffer.
 void dispose()
          Disposes the underlying buffer.
 void emit(BufferEvent event)
          Emits the provided event to the reader.
 int getCapacity()
          The underlying IBuffer capacity used
 java.net.URI getLocator()
          
 IBuffer.Status getStatus()
          Retrieves the status of the underlying IBuffer
 boolean importRecord(T record)
          Dissociates a Record from the underlying IBuffer of a producer and stores it to the IBuffer of this IRecordWriter.
 boolean importRecord(T record, int newDefinitionIndex)
          Dissociates a Record from the underlying IBuffer of a producer and stores it to the IBuffer of this RecordWriter.
 boolean importRecord(T record, int newDefinitionIndex, long timeout, java.util.concurrent.TimeUnit unit)
          Dissociates a Record from the underlying IBuffer of a producer and stores it to the IBuffer of this RecordWriter.
 boolean importRecord(T record, long timeout, java.util.concurrent.TimeUnit unit)
          Dissociates a Record from the underlying IBuffer of a producer and stores it to the IBuffer of this RecordWriter.
 boolean put(T record)
          Stores the provided Record to the underlying IBuffer
 boolean put(T record, long timeout, java.util.concurrent.TimeUnit unit)
          Stores the provided Record to the underlying IBuffer.
 BufferEvent receive()
          Receives a previously emitted event from a reader
 void setBufferStore(IBufferStore store)
          If this writer is populated by an IBufferStore this store is provided in order to keep the store alive and active even after the respective BufferStoreReader has closed the writer but the client reader is still using it
 long totalRecords()
          The number of total Records that have passed through the IBuffer this far
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DefaultBufferCapacity

public static int DefaultBufferCapacity

DefaultConcurrentPartialCapacity

public static int DefaultConcurrentPartialCapacity

DefaultThreshold

public static float DefaultThreshold

DefaultMirrorBufferFactor

public static float DefaultMirrorBufferFactor

DefaultInactivityTimeout

public static long DefaultInactivityTimeout

DefaultInactivityTimeUnit

public static java.util.concurrent.TimeUnit DefaultInactivityTimeUnit
Constructor Detail

RecordWriter

public RecordWriter(IWriterProxy proxy,
                    RecordDefinition[] definitions)
             throws GRS2WriterException
Creates a new instance

Parameters:
proxy - the IWriterProxy to use to publish the authored IBuffer
definitions - the RecordDefinitions of the Records added
Throws:
GRS2WriterException - the operation could not be completed
See Also:
BufferFactory.getBuffer(), IBuffer.setRecordDefinitions(RecordDefinition[])

RecordWriter

public RecordWriter(IWriterProxy proxy,
                    RecordDefinition[] definitions,
                    int capacity,
                    int concurrentPartialCapacity,
                    float mirrorSizeFactor)
             throws GRS2WriterException
Creates a new instance

Parameters:
proxy - the IWriterProxy to use to publish the authored IBuffer
definitions - the RecordDefinitions of the Records added
capacity - the capacity of the underlying IBuffer
concurrentPartialCapacity - the concurrent partial record capacity of the underlying IBuffer
mirrorSizeFactor - the factor to calculate the mirror threshold size
Throws:
GRS2WriterException - the operation could not be completed
See Also:
BufferFactory.getBuffer(), IBuffer.setRecordDefinitions(RecordDefinition[]), IBuffer.setCapacity(int), IBuffer.setConcurrentPartialCapacity(int), IBuffer.setMirrorBuffer(int)

RecordWriter

public RecordWriter(IWriterProxy proxy,
                    RecordDefinition[] definitions,
                    int capacity,
                    int concurrentPartialCapacity,
                    float mirrorSizeFactor,
                    long inactivityTimeout,
                    java.util.concurrent.TimeUnit inactivityTimeUnit)
             throws GRS2WriterException
Creates a new instance

Parameters:
proxy - the IWriterProxy to use to publish the authored IBuffer
definitions - the RecordDefinitions of the Records added
capacity - the capacity of the underlying IBuffer
concurrentPartialCapacity - the concurrent partial record capacity of the underlying IBuffer
mirrorSizeFactor - the factor to calculate the mirror threshold size
inactivityTimeout - the inactivity timeout after which the IBuffer is considered eligible for disposal. This value is interpreted in conjunction with the inactivityTimeUnit value
inactivityTimeUnit - the inactivity timeout unit after which the IBuffer is considered eligible for disposal. This value is interpreted in conjunction with the inactivityTimeout value
Throws:
GRS2WriterException - the operation could not be completed
See Also:
BufferFactory.getBuffer(), IBuffer.setRecordDefinitions(RecordDefinition[]), IBuffer.setCapacity(int), IBuffer.setConcurrentPartialCapacity(int), IBuffer#setNotificationThreshold(float), IBuffer.setMirrorBuffer(int), IBuffer.setInactivityTimeout(long), IBuffer.setInactivityTimeUnit(TimeUnit), IBuffer#getWriterThresholdNotificationObject(), IBuffer.initialize()

RecordWriter

public RecordWriter(IWriterProxy proxy,
                    IRecordReader reader)
             throws GRS2WriterException
Creates a new instance using the configuration retrieved from an IRecordReader. The record definitions, capacity and concurrent partial capacity configuration parameters are duplicated from the reader and all other configuration parameters are set to their default values.

Parameters:
proxy - the IWriterProxy to use to publish the authored IBuffer
reader - the IRecordReader to retrieve configuration from
Throws:
GRS2WriterException - the operation could not be completed
See Also:
BufferFactory.getBuffer(), IBuffer.setRecordDefinitions(RecordDefinition[])

RecordWriter

public RecordWriter(IWriterProxy proxy,
                    IRecordReader reader,
                    int capacity,
                    int concurrentPartialCapacity,
                    float mirrorSizeFactor)
             throws GRS2WriterException
Creates a new instance using the same record definitions as the ones of the supplied IRecordReader. Capacity, concurrent partial capacity and mirror buffer factor configuration parameters can be configured to a non-default value. All other configuration parameters are set to their default values.

Parameters:
proxy - the IWriterProxy to use to publish the authored IBuffer
reader - the IRecordReader to retrieve record definitions from
capacity - the capacity of the underlying IBuffer
concurrentPartialCapacity - the concurrent partial record capacity of the underlying IBuffer
mirrorSizeFactor - the factor to calculate the mirror threshold size
Throws:
GRS2WriterException - the operation could not be completed
See Also:
BufferFactory.getBuffer(), IBuffer.setRecordDefinitions(RecordDefinition[]), IBuffer.setCapacity(int), IBuffer.setConcurrentPartialCapacity(int), IBuffer.setMirrorBuffer(int)

RecordWriter

public RecordWriter(IWriterProxy proxy,
                    IRecordReader reader,
                    int capacity,
                    int concurrentPartialCapacity,
                    float mirrorSizeFactor,
                    long inactivityTimeout,
                    java.util.concurrent.TimeUnit inactivityTimeUnit)
             throws GRS2WriterException
Creates a new instance using the same record definitions as the ones of the supplied IRecordReader. All configuration parameters can be configured to a non-default value.

Parameters:
proxy - the IWriterProxy to use to publish the authored IBuffer
reader - the IRecordReader to retrieve record definitions from
capacity - the capacity of the underlying IBuffer
concurrentPartialCapacity - the concurrent partial record capacity of the underlying IBuffer
mirrorSizeFactor - the factor to calculate the mirror threshold size
inactivityTimeout - the inactivity timeout after which the IBuffer is considered eligible for disposal. This value is interpreted in conjunction with the inactivityTimeUnit value
inactivityTimeUnit - the inactivity timeout unit after which the IBuffer is considered eligible for disposal. This value is interpreted in conjunction with the inactivityTimeout value
Throws:
GRS2WriterException - the operation could not be completed
See Also:
BufferFactory.getBuffer(), IBuffer.setRecordDefinitions(RecordDefinition[]), IBuffer.setCapacity(int), IBuffer.setConcurrentPartialCapacity(int), IBuffer#setNotificationThreshold(float), IBuffer.setMirrorBuffer(int), IBuffer.setInactivityTimeout(long), IBuffer.setInactivityTimeUnit(TimeUnit), IBuffer#getWriterThresholdNotificationObject(), IBuffer.initialize()
Method Detail

setBufferStore

public void setBufferStore(IBufferStore store)
                    throws GRS2WriterException
If this writer is populated by an IBufferStore this store is provided in order to keep the store alive and active even after the respective BufferStoreReader has closed the writer but the client reader is still using it

Specified by:
setBufferStore in interface IRecordWriter<T extends Record>
Parameters:
store - the store which serves the writer
Throws:
GRS2WriterException - the operation could not be completed
See Also:
IRecordWriter.setBufferStore(IBufferStore)

getCapacity

public int getCapacity()
                throws GRS2WriterException
The underlying IBuffer capacity used

Specified by:
getCapacity in interface IRecordWriter<T extends Record>
Returns:
the buffer capacity
Throws:
GRS2WriterException - the operation could not be completed
See Also:
IRecordWriter.getCapacity()

getLocator

public java.net.URI getLocator()
                        throws GRS2WriterException

Specified by:
getLocator in interface IRecordWriter<T extends Record>
Returns:
the locator identifying the authored IBuffer created through the IWriterProxy provided at writer initialization
Throws:
GRS2WriterException - the operation could not be completed
See Also:
IRecordWriter.getLocator()

getStatus

public IBuffer.Status getStatus()
Retrieves the status of the underlying IBuffer

Specified by:
getStatus in interface IRecordWriter<T extends Record>
Returns:
the status of the underlying buffer
See Also:
IRecordWriter.getStatus()

availableRecords

public int availableRecords()
                     throws GRS2WriterException
The number of readily available for consumption Records

Specified by:
availableRecords in interface IRecordWriter<T extends Record>
Returns:
the number of readily available for consumption records
Throws:
GRS2WriterException - the operation could not be completed
See Also:
IRecordWriter.availableRecords()

totalRecords

public long totalRecords()
                  throws GRS2WriterException
The number of total Records that have passed through the IBuffer this far

Specified by:
totalRecords in interface IRecordWriter<T extends Record>
Returns:
the number of total Records that have passed through the IBuffer this far
Throws:
GRS2WriterException - the operation could not be completed
See Also:
IRecordWriter.totalRecords()

put

public boolean put(T record)
            throws GRS2WriterException
Stores the provided Record to the underlying IBuffer

Specified by:
put in interface IRecordWriter<T extends Record>
Parameters:
record - the Record to add
Returns:
true if the addition was successful or false if the IBuffer has reached its capacity
Throws:
GRS2WriterException - the operation could not be completed
See Also:
IRecordWriter.put(Record)

put

public boolean put(T record,
                   long timeout,
                   java.util.concurrent.TimeUnit unit)
            throws GRS2WriterException
Stores the provided Record to the underlying IBuffer. If the IBuffer has already reached its capacity, the method will block for a maximum of timeout unit units of time waiting for a record to be consumed or until the IBuffer uses the IBuffer.getWriterImmediateNotificationObject() to notify blocked writers

Specified by:
put in interface IRecordWriter<T extends Record>
Parameters:
record - the Record to add
timeout - the timeout to wait for
unit - the unit of time to use to interpret the timeout value
Returns:
true if the addition was successful or false if the IBuffer has reached its capacity and the timeout expired
Throws:
GRS2WriterException - the operation could not be completed
See Also:
IRecordWriter.put(Record, long, TimeUnit)

importRecord

public boolean importRecord(T record)
                     throws GRS2Exception
Dissociates a Record from the underlying IBuffer of a producer and stores it to the IBuffer of this IRecordWriter. Before IRecordWriter.put(Record) is called, the record is unbound from the buffer to which is associated, and its definition index is re-set to the same value it had before.

Equivalent to calling IRecordWriter.importRecord(Record, int) with the second parameter being equal to Record.getDefinitionIndex(). Used for convenience if this IRecordWriter is associated with the same definitions as the reader from which the record is originating

Specified by:
importRecord in interface IRecordWriter<T extends Record>
Parameters:
record - the Record to import to the RecordWriter
Returns:
true if the import was successful or false if the IBuffer has reached its capacity
Throws:
GRS2Exception - an error has occurred
See Also:
IRecordWriter.importRecord(Record)

importRecord

public boolean importRecord(T record,
                            long timeout,
                            java.util.concurrent.TimeUnit unit)
                     throws GRS2Exception
Dissociates a Record from the underlying IBuffer of a producer and stores it to the IBuffer of this RecordWriter. Before put(Record, long, TimeUnit) is called, the record is unbound from the buffer to which is associated, and its definition index is re-set to the same value it had before.

Equivalent to calling importRecord(Record, int, long, TimeUnit) with the second parameter being equal to Record.getDefinitionIndex(). Used for convenience if this RecordWriter is associated with the same definitions as the reader from which the record is originating

Specified by:
importRecord in interface IRecordWriter<T extends Record>
Parameters:
record - the Record to import to the RecordWriter
Returns:
true if the import was successful or false if the IBuffer has reached its capacity and the timeout expired
Throws:
GRS2Exception - an error has occurred
See Also:
IRecordWriter.importRecord(Record, long, TimeUnit)

importRecord

public boolean importRecord(T record,
                            int newDefinitionIndex)
                     throws GRS2Exception
Dissociates a Record from the underlying IBuffer of a producer and stores it to the IBuffer of this RecordWriter. Before put(Record) is called, the record is unbound from the buffer to which is associated, and its definition index is set to the supplied value

Specified by:
importRecord in interface IRecordWriter<T extends Record>
Parameters:
record - the Record to import to this RecordWriter
newDefinitionIndex - the definition index that the Record will have in this RecordWriter
Returns:
true if the import was successful or false if the IBuffer has reached its capacity
Throws:
GRS2Exception - an error has occurred
See Also:
IRecordWriter.importRecord(Record, int)

importRecord

public boolean importRecord(T record,
                            int newDefinitionIndex,
                            long timeout,
                            java.util.concurrent.TimeUnit unit)
                     throws GRS2Exception
Dissociates a Record from the underlying IBuffer of a producer and stores it to the IBuffer of this RecordWriter. Before put(Record, long, TimeUnit) is called, the record is unbound from the buffer to which is associated, and its definition index is set to the supplied value

Specified by:
importRecord in interface IRecordWriter<T extends Record>
Parameters:
record - the Record to import to this RecordWriter
newDefinitionIndex - the definition index that the Record will have in this RecordWriter
Returns:
true if the import was successful or false if the IBuffer has reached its capacity and the timeout expired
Throws:
GRS2Exception - an error has occurred
See Also:
IRecordWriter.importRecord(Record, int, long, TimeUnit)

close

public void close()
           throws GRS2WriterException
Closes the underlying buffer. After this method has been invoked, no more Records can be added

Specified by:
close in interface IRecordWriter<T extends Record>
Throws:
GRS2WriterException - the operation could not be completed
See Also:
IRecordWriter.close()

dispose

public void dispose()
Disposes the underlying buffer. After this method has been invoked, all associated resources are disposed. If there are any readers connected through the underlying IBuffer, their resources will also be disposed

Specified by:
dispose in interface IRecordWriter<T extends Record>
See Also:
IRecordWriter.dispose()

emit

public void emit(BufferEvent event)
          throws GRS2WriterException,
                 GRS2WriterInvalidArgumentException
Emits the provided event to the reader. The source of the event is set to BufferEvent.EventSource.Writer

Specified by:
emit in interface IRecordWriter<T extends Record>
Parameters:
event - the event to send to the reader
Throws:
GRS2WriterException - the operation could not be completed
GRS2WriterInvalidArgumentException - the event provided cannot be null
See Also:
IRecordWriter.emit(BufferEvent)

receive

public BufferEvent receive()
                    throws GRS2WriterException
Receives a previously emitted event from a reader

Specified by:
receive in interface IRecordWriter<T extends Record>
Returns:
the event received or null if no pending events exist
Throws:
GRS2WriterException - the operation could not be completed
See Also:
IRecordWriter.receive()