Search in sources :

Example 6 with RaftServiceContext

use of io.atomix.protocols.raft.service.RaftServiceContext in project atomix by atomix.

the class RaftServiceManager method applyOpenSession.

/**
 * Applies an open session entry to the state machine.
 */
private long applyOpenSession(Indexed<OpenSessionEntry> entry) {
    PrimitiveType primitiveType = raft.getPrimitiveTypes().get(entry.entry().serviceType());
    if (primitiveType == null) {
        throw new RaftException.UnknownService("Unknown service type " + entry.entry().serviceType());
    }
    // Get the state machine executor or create one if it doesn't already exist.
    RaftServiceContext service = getOrInitializeService(PrimitiveId.from(entry.index()), raft.getPrimitiveTypes().get(entry.entry().serviceType()), entry.entry().serviceName());
    if (service == null) {
        throw new RaftException.UnknownService("Unknown service type " + entry.entry().serviceType());
    }
    SessionId sessionId = SessionId.from(entry.index());
    RaftSession session = raft.getSessions().addSession(new RaftSession(sessionId, NodeId.from(entry.entry().memberId()), entry.entry().serviceName(), primitiveType, entry.entry().readConsistency(), entry.entry().minTimeout(), entry.entry().maxTimeout(), entry.entry().timestamp(), service, raft, threadContextFactory));
    return service.openSession(entry.index(), entry.entry().timestamp(), session);
}
Also used : RaftSession(io.atomix.protocols.raft.session.RaftSession) RaftServiceContext(io.atomix.protocols.raft.service.RaftServiceContext) PrimitiveType(io.atomix.primitive.PrimitiveType) SessionId(io.atomix.primitive.session.SessionId)

Example 7 with RaftServiceContext

use of io.atomix.protocols.raft.service.RaftServiceContext in project atomix by atomix.

the class RaftSessionRegistryTest method createSession.

private RaftSession createSession(long sessionId) {
    RaftServiceContext context = mock(RaftServiceContext.class);
    when(context.serviceType()).thenReturn(new TestPrimitiveType());
    when(context.serviceName()).thenReturn("test");
    when(context.serviceId()).thenReturn(PrimitiveId.from(1));
    RaftContext server = mock(RaftContext.class);
    when(server.getProtocol()).thenReturn(mock(RaftServerProtocol.class));
    RaftServiceManager manager = mock(RaftServiceManager.class);
    when(manager.executor()).thenReturn(mock(ThreadContext.class));
    when(server.getServiceManager()).thenReturn(manager);
    return new RaftSession(SessionId.from(sessionId), NodeId.from("1"), "test", new TestPrimitiveType(), ReadConsistency.LINEARIZABLE, 100, 5000, System.currentTimeMillis(), context, server, mock(ThreadContextFactory.class));
}
Also used : RaftServerProtocol(io.atomix.protocols.raft.protocol.RaftServerProtocol) RaftContext(io.atomix.protocols.raft.impl.RaftContext) RaftServiceManager(io.atomix.protocols.raft.impl.RaftServiceManager) ThreadContextFactory(io.atomix.utils.concurrent.ThreadContextFactory) ThreadContext(io.atomix.utils.concurrent.ThreadContext) RaftServiceContext(io.atomix.protocols.raft.service.RaftServiceContext) TestPrimitiveType(io.atomix.protocols.raft.proxy.impl.TestPrimitiveType)

Aggregations

RaftServiceContext (io.atomix.protocols.raft.service.RaftServiceContext)7 RaftSession (io.atomix.protocols.raft.session.RaftSession)3 PrimitiveType (io.atomix.primitive.PrimitiveType)2 PrimitiveId (io.atomix.primitive.PrimitiveId)1 SessionId (io.atomix.primitive.session.SessionId)1 RaftException (io.atomix.protocols.raft.RaftException)1 RaftContext (io.atomix.protocols.raft.impl.RaftContext)1 RaftServiceManager (io.atomix.protocols.raft.impl.RaftServiceManager)1 RaftServerProtocol (io.atomix.protocols.raft.protocol.RaftServerProtocol)1 TestPrimitiveType (io.atomix.protocols.raft.proxy.impl.TestPrimitiveType)1 Snapshot (io.atomix.protocols.raft.storage.snapshot.Snapshot)1 SnapshotWriter (io.atomix.protocols.raft.storage.snapshot.SnapshotWriter)1 ThreadContext (io.atomix.utils.concurrent.ThreadContext)1 ThreadContextFactory (io.atomix.utils.concurrent.ThreadContextFactory)1 WallClockTimestamp (io.atomix.utils.time.WallClockTimestamp)1 ArrayList (java.util.ArrayList)1