Search in sources :

Example 11 with Buffer

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;
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) MappedBuffer(io.atomix.storage.buffer.MappedBuffer) FileBuffer(io.atomix.storage.buffer.FileBuffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) File(java.io.File)

Example 12 with Buffer

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;
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) MappedBuffer(io.atomix.storage.buffer.MappedBuffer) FileBuffer(io.atomix.storage.buffer.FileBuffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) File(java.io.File)

Example 13 with Buffer

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;
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) MappedBuffer(io.atomix.storage.buffer.MappedBuffer) FileBuffer(io.atomix.storage.buffer.FileBuffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) File(java.io.File)

Example 14 with Buffer

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());
}
Also used : Add(io.atomix.core.queue.impl.WorkQueueOperations.Add) Buffer(io.atomix.storage.buffer.Buffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) Take(io.atomix.core.queue.impl.WorkQueueOperations.Take) Task(io.atomix.core.queue.Task) ServiceContext(io.atomix.primitive.service.ServiceContext) WorkQueueService(io.atomix.core.queue.impl.WorkQueueService) Session(io.atomix.primitive.session.Session) Test(org.junit.Test)

Example 15 with Buffer

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());
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) ConsistentSetMultimapService(io.atomix.core.multimap.impl.ConsistentSetMultimapService) Get(io.atomix.core.multimap.impl.ConsistentSetMultimapOperations.Get) Collection(java.util.Collection) Put(io.atomix.core.multimap.impl.ConsistentSetMultimapOperations.Put) Test(org.junit.Test)

Aggregations

Buffer (io.atomix.storage.buffer.Buffer)17 HeapBuffer (io.atomix.storage.buffer.HeapBuffer)14 FileBuffer (io.atomix.storage.buffer.FileBuffer)9 Test (org.junit.Test)8 MappedBuffer (io.atomix.storage.buffer.MappedBuffer)6 File (java.io.File)6 ServiceContext (io.atomix.primitive.service.ServiceContext)2 Session (io.atomix.primitive.session.Session)2 Set (io.atomix.core.counter.impl.AtomicCounterOperations.Set)1 AtomicCounterService (io.atomix.core.counter.impl.AtomicCounterService)1 Run (io.atomix.core.election.impl.LeaderElectionOperations.Run)1 LeaderElectionService (io.atomix.core.election.impl.LeaderElectionService)1 Get (io.atomix.core.map.impl.AtomicCounterMapOperations.Get)1 Put (io.atomix.core.map.impl.AtomicCounterMapOperations.Put)1 AtomicCounterMapService (io.atomix.core.map.impl.AtomicCounterMapService)1 Get (io.atomix.core.map.impl.ConsistentMapOperations.Get)1 Put (io.atomix.core.map.impl.ConsistentMapOperations.Put)1 Get (io.atomix.core.multimap.impl.ConsistentSetMultimapOperations.Get)1 Put (io.atomix.core.multimap.impl.ConsistentSetMultimapOperations.Put)1 ConsistentSetMultimapService (io.atomix.core.multimap.impl.ConsistentSetMultimapService)1