Class AsyncWriter
-
Nested Class Summary
Nested classes/interfaces inherited from class com.northconcepts.datapipeline.core.DataEndpoint
DataEndpoint.State -
Field Summary
Fields inherited from class com.northconcepts.datapipeline.core.DataEndpoint
lastRecord, PRODUCT, PRODUCT_VERSION, VENDOR, XML_INPUT_FACTORY_KEYFields inherited from class com.northconcepts.datapipeline.core.Endpoint
BUFFER_SIZE, captureElapsedTime, DEFAULT_READ_BUFFER_SIZEFields inherited from class com.northconcepts.datapipeline.core.DataObject
id, log, name, TIMESTAMP_FORMAT -
Constructor Summary
ConstructorsConstructorDescriptionAsyncWriter(DataWriter nestedDataWriter) Creates anAsyncWriterobject, with the givenDataWriterand default capacity of 500 records that can be queued.AsyncWriter(DataWriter nestedDataWriter, int maxQueuedRecords) Creates anAsyncWriterobject, with the givenDataWriterand maximum number of records that can be queued. -
Method Summary
Modifier and TypeMethodDescriptionfinal DataExceptionaddExceptionProperties(DataException exception) Adds this endpoint's current state to aDataException.protected DataExceptionaddExceptionPropertiesImpl(DataException exception) Adds this writer's own state, but not the nested writer's (it runs on another thread), to the exception; subclasses override this instead of the finaladdExceptionProperties(DataException).intReturns the number of records that can probably be written without blocking.voidclose()Indicates that this endpoint has finished reading or writing.final DataExceptionCreates an exception with the specified message and containing this endpoint's properties (name-value pairs).final DataExceptionConverts an exception to aDataException, prefixing the original message with the specified text and adding this endpoint's properties (name-value pairs).final DataExceptionConverts an exception to aDataExceptionand adds this endpoint's properties (name-value pairs).longReturns the estimated size in bytes of the records queued but not yet passed to the nested writer.Returns the background thread's failure that has not yet been rethrown to the caller or null if there is none.longReturns the largest valuegetBufferSizeInBytes()has reached.intReturns the priority given to the background writing thread when this writer is opened (defaults toThread.NORM_PRIORITY).voidopen()Makes this endpoint ready for reading or writing.voidRethrows the exception thrown by the internal thread or returns silently if no exception was thrown.setPriority(int priority) Sets the priority given to the background writing thread when this writer is opened, fromThread.MIN_PRIORITYtoThread.MAX_PRIORITY(defaults toThread.NORM_PRIORITY).voidWrites the specified record to thisDataWriterand increases the record-count by 1.protected voidOverridden by subclasses to write the specified record to thisDataWriter.Methods inherited from class com.northconcepts.datapipeline.core.ProxyWriter
getNestedWriter, interceptRecord, map, map, setNestedDataWriter, setNestedDataWriterMethods inherited from class com.northconcepts.datapipeline.core.DataWriter
getNestedEndpoint, getRootEndpoint, getRootWriter, getWriterMethods inherited from class com.northconcepts.datapipeline.core.DataEndpoint
decrementRecordCount, enableJmx, getLastRecord, getRecordCount, getRecordCountAsBigInteger, getRecordCountAsString, incrementRecordCount, isRecordCountBigInteger, resetRecordCount, toStringMethods inherited from class com.northconcepts.datapipeline.core.Endpoint
addElapsedtime, assertClosed, assertNotOpened, assertOpened, finalize, getClosedOn, getDescription, getElapsedTime, getElapsedTimeAsString, getOpenedOn, getOpenElapsedTime, getOpenElapsedTimeAsString, getSelfTime, getSelfTimeAsString, getState, isCaptureElapsedTime, isClosed, isOpen, setCaptureElapsedTime, setDescriptionMethods inherited from class com.northconcepts.datapipeline.core.DataObject
getId, getName, resetID
-
Constructor Details
-
AsyncWriter
Creates anAsyncWriterobject, with the givenDataWriterand maximum number of records that can be queued. -
AsyncWriter
Creates anAsyncWriterobject, with the givenDataWriterand default capacity of 500 records that can be queued.
-
-
Method Details
-
getBufferSizeInBytes
public long getBufferSizeInBytes()Returns the estimated size in bytes of the records queued but not yet passed to the nested writer. -
getPeakBufferSizeInBytes
public long getPeakBufferSizeInBytes()Returns the largest valuegetBufferSizeInBytes()has reached. -
getPriority
public int getPriority()Returns the priority given to the background writing thread when this writer is opened (defaults toThread.NORM_PRIORITY). -
setPriority
Sets the priority given to the background writing thread when this writer is opened, fromThread.MIN_PRIORITYtoThread.MAX_PRIORITY(defaults toThread.NORM_PRIORITY). -
getException
Returns the background thread's failure that has not yet been rethrown to the caller or null if there is none. -
open
Description copied from class:DataEndpointMakes this endpoint ready for reading or writing.- Overrides:
openin classProxyWriter- Throws:
DataException
-
close
Description copied from class:DataEndpointIndicates that this endpoint has finished reading or writing.- Overrides:
closein classProxyWriter- Throws:
DataException
-
available
Description copied from class:DataWriterReturns the number of records that can probably be written without blocking.- Overrides:
availablein classProxyWriter- Throws:
DataException
-
write
Description copied from class:DataWriterWrites the specified record to thisDataWriterand increases the record-count by 1. Any exception raised while writing will be converted to aDataExceptionusingDataObject.exception(Throwable).Subclasses generally do not need to override this method, instead they should implement
DataWriter.writeImpl(Record).- Overrides:
writein classDataWriter- Throws:
DataException
-
writeImpl
Description copied from class:DataWriterOverridden by subclasses to write the specified record to thisDataWriter.Contract for subclasses (see also
docs/authoring/DataWriter.md):- Do not call this method directly —
DataWriter.write(Record)is the template method that wraps exceptions, increments the record count, and attaches the offending record to thrownDataExceptions. - Do not call
DataEndpoint.incrementRecordCount()here;DataWriter.write(Record)already does. - Throw raw exceptions;
DataWriter.write(Record)wraps them viaexception(throwable).setRecord(record).
- Overrides:
writeImplin classProxyWriter- Throws:
Throwable
- Do not call this method directly —
-
rethrowAsyncException
public void rethrowAsyncException()Rethrows the exception thrown by the internal thread or returns silently if no exception was thrown. -
exception
Description copied from class:DataObjectConverts an exception to aDataException, prefixing the original message with the specified text and adding this endpoint's properties (name-value pairs).The returned exception can then be thrown in the normal way.
If the supplied exception is an instanceof
DataException, it will be returned, otherwise it will be nested inside aDataException. In either case the result message will contain the new prefix along with this endpoint properties.- Overrides:
exceptionin classDataObject
-
exception
Description copied from class:DataObjectConverts an exception to aDataExceptionand adds this endpoint's properties (name-value pairs).The returned exception can then be thrown in the normal way.
If the supplied exception is an instanceof
DataException, it will be returned, otherwise it will be nested inside aDataException. In either case the result message will contain this endpoint properties.- Overrides:
exceptionin classDataObject
-
exception
Description copied from class:DataObjectCreates an exception with the specified message and containing this endpoint's properties (name-value pairs).The returned exception can then be thrown in the normal way.
- Overrides:
exceptionin classDataObject
-
addExceptionProperties
Description copied from class:EndpointAdds this endpoint's current state to aDataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.- Overrides:
addExceptionPropertiesin classProxyWriter
-
addExceptionPropertiesImpl
Adds this writer's own state, but not the nested writer's (it runs on another thread), to the exception; subclasses override this instead of the finaladdExceptionProperties(DataException).
-