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));
}
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);
}
}
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;
}
Aggregations