Search in sources :

Example 1 with TableStore

use of net.openhft.chronicle.queue.impl.TableStore in project Chronicle-Queue by OpenHFT.

the class TableDirectoryListingTest method lockShouldTimeOut.

@Test
public void lockShouldTimeOut() throws Exception {
    listing.onFileCreated(tempFile, 8);
    final TableStore tableCopy = SingleTableBuilder.binary(tableFile).build();
    final LongValue lock = tableCopy.acquireValueFor(TableDirectoryListing.LOCK);
    lock.setOrderedValue(System.currentTimeMillis() - (TimeUnit.SECONDS.toMillis(9) + 500));
    listing.onFileCreated(tempFile, 9);
    assertThat(listing.getMaxCreatedCycle(), is(9));
}
Also used : LongValue(net.openhft.chronicle.core.values.LongValue) TableStore(net.openhft.chronicle.queue.impl.TableStore) Test(org.junit.Test)

Example 2 with TableStore

use of net.openhft.chronicle.queue.impl.TableStore in project Chronicle-Queue by OpenHFT.

the class SingleTableBuilder method build.

// *************************************************************************
// 
// *************************************************************************
@NotNull
public TableStore build() {
    if (readOnly && !file.exists()) {
        throw new IORuntimeException("File not found in readOnly mode");
    }
    try {
        MappedBytes bytes = MappedBytes.mappedBytes(file, 64 << 10, 0, readOnly);
        Wire wire = wireType.apply(bytes);
        StoreRecovery recovery = recoverySupplier.apply(wireType);
        try {
            TableStore tableStore;
            if ((!readOnly) && wire.writeFirstHeader()) {
                tableStore = writeTableStore(bytes, wire, recovery);
            } else {
                wire.readFirstHeader(timeoutMS, TimeUnit.MILLISECONDS);
                StringBuilder name = Wires.acquireStringBuilder();
                ValueIn valueIn = wire.readEventName(name);
                if (StringUtils.isEqual(name, MetaDataKeys.header.name())) {
                    tableStore = valueIn.typedMarshallable();
                } else {
                    // noinspection unchecked
                    throw new StreamCorruptedException("The first message should be the header, was " + name);
                }
            }
            return tableStore;
        } catch (TimeoutException e) {
            recovery.recoverAndWriteHeader(wire, 10_000, null, null);
            return writeTableStore(bytes, wire, recovery);
        }
    } catch (IOException e) {
        throw new IORuntimeException(e);
    }
}
Also used : ValueIn(net.openhft.chronicle.wire.ValueIn) IORuntimeException(net.openhft.chronicle.core.io.IORuntimeException) TimedStoreRecovery(net.openhft.chronicle.queue.impl.single.TimedStoreRecovery) StoreRecovery(net.openhft.chronicle.queue.impl.single.StoreRecovery) StreamCorruptedException(java.io.StreamCorruptedException) IOException(java.io.IOException) Wire(net.openhft.chronicle.wire.Wire) MappedBytes(net.openhft.chronicle.bytes.MappedBytes) TableStore(net.openhft.chronicle.queue.impl.TableStore) TimeoutException(java.util.concurrent.TimeoutException) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with TableStore

use of net.openhft.chronicle.queue.impl.TableStore in project Chronicle-Queue by OpenHFT.

the class SingleTableBuilder method writeTableStore.

@NotNull
private TableStore writeTableStore(MappedBytes bytes, Wire wire, StoreRecovery recovery) throws EOFException, StreamCorruptedException {
    TableStore store = new SingleTableStore(wireType, bytes, recovery);
    wire.writeEventName("header").object(store);
    wire.updateFirstHeader();
    return store;
}
Also used : TableStore(net.openhft.chronicle.queue.impl.TableStore) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TableStore (net.openhft.chronicle.queue.impl.TableStore)3 NotNull (org.jetbrains.annotations.NotNull)2 IOException (java.io.IOException)1 StreamCorruptedException (java.io.StreamCorruptedException)1 TimeoutException (java.util.concurrent.TimeoutException)1 MappedBytes (net.openhft.chronicle.bytes.MappedBytes)1 IORuntimeException (net.openhft.chronicle.core.io.IORuntimeException)1 LongValue (net.openhft.chronicle.core.values.LongValue)1 StoreRecovery (net.openhft.chronicle.queue.impl.single.StoreRecovery)1 TimedStoreRecovery (net.openhft.chronicle.queue.impl.single.TimedStoreRecovery)1 ValueIn (net.openhft.chronicle.wire.ValueIn)1 Wire (net.openhft.chronicle.wire.Wire)1 Test (org.junit.Test)1