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