@SuppressWarnings("unchecked") public ServerContext(String name, Member.Type type, Address serverAddress, Address clientAddress, Storage storage, Serializer serializer, Supplier<StateMachine> stateMachineFactory, ConnectionManager connections, ThreadContext threadContext) { this.name = Assert.notNull(name, "name"); this.storage = Assert.notNull(storage, "storage"); this.serializer = Assert.notNull(serializer, "serializer"); this.threadContext = Assert.notNull(threadContext, "threadContext"); this.connections = Assert.notNull(connections, "connections"); this.stateMachineFactory = Assert.notNull(stateMachineFactory, "stateMachineFactory"); this.stateContext = new SingleThreadContext(String.format("copycat-server-%s-%s-state", serverAddress, name), threadContext.serializer().clone()); // Open the meta store. threadContext.execute(() -> this.meta = storage.openMetaStore(name)).join(); // Load the current term and last vote from disk. this.term = meta.loadTerm(); this.lastVotedFor = meta.loadVote(); // Reset the state machine. threadContext.execute(this::reset).join(); this.cluster = new ClusterState(type, serverAddress, clientAddress, this); }
@SuppressWarnings("unchecked") public ServerContext(String name, Member.Type type, Address serverAddress, Address clientAddress, Storage storage, Serializer serializer, Supplier<StateMachine> stateMachineFactory, ConnectionManager connections, ThreadContext threadContext) { this.name = Assert.notNull(name, "name"); this.storage = Assert.notNull(storage, "storage"); this.serializer = Assert.notNull(serializer, "serializer"); this.threadContext = Assert.notNull(threadContext, "threadContext"); this.connections = Assert.notNull(connections, "connections"); this.stateMachineFactory = Assert.notNull(stateMachineFactory, "stateMachineFactory"); this.stateContext = new SingleThreadContext(String.format("copycat-server-%s-%s-state", serverAddress, name), threadContext.serializer().clone()); // Open the meta store. threadContext.execute(() -> this.meta = storage.openMetaStore(name)).join(); // Load the current term and last vote from disk. this.term = meta.loadTerm(); this.lastVotedFor = meta.loadVote(); // Reset the state machine. threadContext.execute(this::reset).join(); this.cluster = new ClusterState(type, serverAddress, clientAddress, this); }
@SuppressWarnings("unchecked") public ServerContext(String name, Member.Type type, Address serverAddress, Address clientAddress, Collection<Address> members, Storage storage, Serializer serializer, Supplier<StateMachine> stateMachineFactory, ConnectionManager connections, ThreadContext threadContext) { this.name = Assert.notNull(name, "name"); this.storage = Assert.notNull(storage, "storage"); this.serializer = Assert.notNull(serializer, "serializer"); this.threadContext = Assert.notNull(threadContext, "threadContext"); this.connections = Assert.notNull(connections, "connections"); this.stateMachineFactory = Assert.notNull(stateMachineFactory, "stateMachineFactory"); this.stateContext = new SingleThreadContext("copycat-server-" + serverAddress + "-state-%d", threadContext.serializer().clone()); // Open the meta store. threadContext.execute(() -> this.meta = storage.openMetaStore(name)).join(); // Load the current term and last vote from disk. this.term = meta.loadTerm(); this.lastVotedFor = meta.loadVote(); // Reset the state machine. threadContext.execute(this::reset).join(); this.cluster = new ClusterState(type, serverAddress, clientAddress, members, this); }