Search in sources :

Example 6 with TextDescription

use of de.invesdwin.util.lang.description.TextDescription in project invesdwin-context-persistence by subes.

the class FileLiveSegment method getFlushedValues.

private SerializingCollection<V> getFlushedValues() {
    synchronized (this) {
        if (needsFlush) {
            values.flush();
            needsFlush = false;
        }
    }
    final TextDescription name = new TextDescription("%s[%s]: getFlushedValues()", FileLiveSegment.class.getSimpleName(), segmentedKey);
    return new SerializingCollection<V>(name, values.getFile(), true) {

        @Override
        protected ISerde<V> newSerde() {
            return historicalSegmentTable.newValueSerde();
        }

        @Override
        protected Integer getFixedLength() {
            return historicalSegmentTable.newValueFixedLength();
        }

        @Override
        protected OutputStream newCompressor(final OutputStream out) {
            return compressionFactory.newCompressor(out, LARGE_COMPRESSOR);
        }

        @Override
        protected InputStream newDecompressor(final InputStream inputStream) {
            return compressionFactory.newDecompressor(inputStream);
        }

        @Override
        protected InputStream newFileInputStream(final File file) throws IOException {
            // keep file input stream open as shorty as possible to prevent too many open files error
            try (InputStream fis = super.newFileInputStream(file)) {
                final PooledFastByteArrayOutputStream bos = PooledFastByteArrayOutputStream.newInstance();
                IOUtils.copy(fis, bos.asNonClosing());
                return bos.asInputStream();
            } catch (final FileNotFoundException e) {
                // maybe retry because of this in the outer iterator?
                throw new RetryLaterRuntimeException("File might have been deleted in the mean time between read locks: " + file.getAbsolutePath(), e);
            }
        }
    };
}
Also used : InputStream(java.io.InputStream) TextDescription(de.invesdwin.util.lang.description.TextDescription) SerializingCollection(de.invesdwin.context.persistence.timeseriesdb.SerializingCollection) OutputStream(java.io.OutputStream) PooledFastByteArrayOutputStream(de.invesdwin.util.streams.pool.PooledFastByteArrayOutputStream) FileNotFoundException(java.io.FileNotFoundException) RetryLaterRuntimeException(de.invesdwin.context.integration.retry.RetryLaterRuntimeException) File(java.io.File) PooledFastByteArrayOutputStream(de.invesdwin.util.streams.pool.PooledFastByteArrayOutputStream)

Aggregations

TextDescription (de.invesdwin.util.lang.description.TextDescription)6 File (java.io.File)4 RetryLaterRuntimeException (de.invesdwin.context.integration.retry.RetryLaterRuntimeException)3 PooledFastByteArrayOutputStream (de.invesdwin.util.streams.pool.PooledFastByteArrayOutputStream)3 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 SerializingCollection (de.invesdwin.context.persistence.timeseriesdb.SerializingCollection)2 MemoryFileSummary (de.invesdwin.context.persistence.timeseriesdb.storage.MemoryFileSummary)2 ACloseableIterator (de.invesdwin.util.collections.iterable.ACloseableIterator)2 ICloseableIterable (de.invesdwin.util.collections.iterable.ICloseableIterable)2 ICloseableIterator (de.invesdwin.util.collections.iterable.ICloseableIterator)2 ASkippingIterator (de.invesdwin.util.collections.iterable.skip.ASkippingIterator)2 FDate (de.invesdwin.util.time.date.FDate)2 RangeTableRow (ezdb.table.RangeTableRow)2 FileNotFoundException (java.io.FileNotFoundException)2 ATimeSeriesUpdater (de.invesdwin.context.persistence.timeseriesdb.updater.ATimeSeriesUpdater)1 ATest (de.invesdwin.context.test.ATest)1 ISerde (de.invesdwin.util.marshallers.serde.ISerde)1 PreLockedDelegateInputStream (de.invesdwin.util.streams.PreLockedDelegateInputStream)1 MemoryMappedFile (de.invesdwin.util.streams.buffer.MemoryMappedFile)1