use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class SegmentedJournal method createDiskSegment.
/**
* Creates a new segment.
*/
private JournalSegment<E> createDiskSegment(JournalSegmentDescriptor descriptor) {
File segmentFile = JournalSegmentFile.createSegmentFile(name, directory, descriptor.id());
Buffer buffer = FileBuffer.allocate(segmentFile, Math.min(DEFAULT_BUFFER_SIZE, descriptor.maxSegmentSize()), Integer.MAX_VALUE);
descriptor.copyTo(buffer);
JournalSegment<E> segment = newSegment(new JournalSegmentFile(segmentFile), descriptor);
log.debug("Created disk segment: {}", segment);
return segment;
}
use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class SegmentedJournal method loadDiskSegment.
/**
* Loads a segment.
*/
private JournalSegment<E> loadDiskSegment(long segmentId) {
File file = JournalSegmentFile.createSegmentFile(name, directory, segmentId);
Buffer buffer = FileBuffer.allocate(file, Math.min(DEFAULT_BUFFER_SIZE, maxSegmentSize), Integer.MAX_VALUE);
JournalSegmentDescriptor descriptor = new JournalSegmentDescriptor(buffer);
JournalSegment<E> segment = newSegment(new JournalSegmentFile(file), descriptor);
log.debug("Loaded disk segment: {} ({})", descriptor.id(), file.getName());
return segment;
}
use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class SegmentedJournal method loadMappedSegment.
/**
* Loads a segment.
*/
private JournalSegment<E> loadMappedSegment(long segmentId) {
File file = JournalSegmentFile.createSegmentFile(name, directory, segmentId);
Buffer buffer = MappedBuffer.allocate(file, Math.min(DEFAULT_BUFFER_SIZE, maxSegmentSize), Integer.MAX_VALUE);
JournalSegmentDescriptor descriptor = new JournalSegmentDescriptor(buffer);
JournalSegment<E> segment = newSegment(new JournalSegmentFile(file), descriptor);
log.debug("Loaded memory mapped segment: {} ({})", descriptor.id(), file.getName());
return segment;
}
use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class WorkQueueServiceTest method testSnapshot.
@Test
public void testSnapshot() throws Exception {
ServiceContext context = mock(ServiceContext.class);
when(context.serviceType()).thenReturn(PrimitiveTypes.workQueue());
when(context.serviceName()).thenReturn("test");
when(context.serviceId()).thenReturn(PrimitiveId.from(1));
Session session = mock(Session.class);
when(session.sessionId()).thenReturn(SessionId.from(1));
WorkQueueService service = new WorkQueueService();
service.init(context);
service.add(new DefaultCommit<>(2, ADD, new Add(Arrays.asList("Hello world!".getBytes())), session, System.currentTimeMillis()));
Buffer buffer = HeapBuffer.allocate();
service.backup(buffer);
service = new WorkQueueService();
service.init(context);
service.restore(buffer.flip());
Collection<Task<byte[]>> value = service.take(new DefaultCommit<>(2, TAKE, new Take(1), session, System.currentTimeMillis()));
assertNotNull(value);
assertEquals(1, value.size());
assertArrayEquals("Hello world!".getBytes(), value.iterator().next().payload());
}
use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class ConsistentSetMultimapServiceTest method testSnapshot.
@Test
@SuppressWarnings("unchecked")
public void testSnapshot() throws Exception {
ConsistentSetMultimapService service = new ConsistentSetMultimapService();
service.put(new DefaultCommit<>(2, PUT, new Put("foo", Arrays.asList("Hello world!".getBytes()), Match.ANY), mock(Session.class), System.currentTimeMillis()));
Buffer buffer = HeapBuffer.allocate();
service.backup(buffer);
service = new ConsistentSetMultimapService();
service.restore(buffer.flip());
Versioned<Collection<? extends byte[]>> value = service.get(new DefaultCommit<>(2, GET, new Get("foo"), mock(Session.class), System.currentTimeMillis()));
assertNotNull(value);
assertEquals(1, value.value().size());
assertArrayEquals("Hello world!".getBytes(), value.value().iterator().next());
}
Aggregations