Example #1
0
 @Override
 public Snapshot complete() {
   Buffer buffer = FileBuffer.allocate(file.file(), SnapshotDescriptor.BYTES);
   try (SnapshotDescriptor descriptor = new SnapshotDescriptor(buffer)) {
     Assert.stateNot(descriptor.locked(), "cannot complete locked snapshot descriptor");
     descriptor.lock();
   }
   return super.complete();
 }
Example #2
0
 @Override
 public synchronized SnapshotReader reader() {
   Assert.state(file.file().exists(), "missing snapshot file: %s", file.file());
   Buffer buffer = FileBuffer.allocate(file.file(), SnapshotDescriptor.BYTES);
   SnapshotDescriptor descriptor = new SnapshotDescriptor(buffer);
   int length = buffer.position(SnapshotDescriptor.BYTES).readInt();
   return openReader(
       new SnapshotReader(
           buffer.mark().limit(SnapshotDescriptor.BYTES + Integer.BYTES + length),
           this,
           store.serializer()),
       descriptor);
 }
Example #3
0
  @Override
  public synchronized SnapshotWriter writer() {
    checkWriter();
    SnapshotDescriptor descriptor =
        SnapshotDescriptor.builder()
            .withIndex(file.index())
            .withTimestamp(file.timestamp())
            .build();

    Buffer buffer = FileBuffer.allocate(file.file(), SnapshotDescriptor.BYTES);
    descriptor.copyTo(buffer);

    int length = buffer.position(SnapshotDescriptor.BYTES).readInt();
    return openWriter(
        new SnapshotWriter(buffer.skip(length).mark(), this, store.serializer()), descriptor);
  }