@Override @SuppressWarnings("unchecked") public Listener onEvent(String event, Consumer listener) { return eventListeners .computeIfAbsent(Assert.notNull(event, "event"), e -> new Listeners<>()) .add(Assert.notNull(listener, "listener")); }
@Override public <T extends Operation<U>, U> StateMachineExecutor register( Class<T> type, Function<Commit<T>, U> callback) { Assert.notNull(type, "type"); Assert.notNull(callback, "callback"); operations.put(type, callback); return this; }
private Builder(Address clientAddress, Address serverAddress, Collection<Address> members) { this.members = Assert.notNull(members, "members"); Serializer serializer = new Serializer(); this.clientAddress = Assert.notNull(clientAddress, "clientAddress"); this.clientBuilder = CopycatClient.builder(members).withSerializer(serializer.clone()); this.serverBuilder = CopycatServer.builder(clientAddress, serverAddress, members) .withSerializer(serializer.clone()); }
public ClientSession( UUID clientId, Transport transport, Collection<Address> members, Serializer serializer) { this.clientId = Assert.notNull(clientId, "clientId"); this.client = Assert.notNull(transport, "transport").client(); this.members = new HashSet<>(Assert.notNull(members, "members")); this.context = new SingleThreadContext( "copycat-client-" + clientId.toString(), Assert.notNull(serializer, "serializer").clone()); this.connectMembers = new ArrayList<>(members); }
private ClientSession( ClientConnection connection, ClientSessionState state, ThreadContext context, ConnectionStrategy connectionStrategy) { this.connection = Assert.notNull(connection, "connection"); this.state = Assert.notNull(state, "state"); this.manager = new ClientSessionManager(connection, state, context, connectionStrategy); ClientSequencer sequencer = new ClientSequencer(state); this.listener = new ClientSessionListener(connection, state, sequencer, context); this.submitter = new ClientSessionSubmitter(connection, state, sequencer, context); }
@Override public <T extends Operation<Void>> StateMachineExecutor register( Class<T> type, Consumer<Commit<T>> callback) { Assert.notNull(type, "type"); Assert.notNull(callback, "callback"); operations.put( type, (Function<Commit<T>, Void>) commit -> { callback.accept(commit); return null; }); return this; }
@Override public CompletableFuture<Void> listen(Address address, Consumer<Connection> listener) { Assert.notNull(address, "address"); Assert.notNull(listener, "listener"); if (listening) return CompletableFuture.completedFuture(null); ThreadContext context = ThreadContext.currentContextOrThrow(); synchronized (this) { if (listenFuture == null) { listenFuture = new CompletableFuture<>(); listen(address, listener, context); } } return listenFuture; }
@Override public Session publish(String event, Object message) { Assert.notNull(event, "event"); context .executor() .execute( () -> { Listeners<Object> listeners = eventListeners.get(event); if (listeners != null) { listeners.accept(message); } }); return this; }
/** * Returns a boolean value indicating whether the selector state would be changed by the given * members. */ private boolean changed(Address leader, Collection<Address> servers) { Assert.notNull(servers, "servers"); Assert.argNot(servers.isEmpty(), "servers list cannot be empty"); if (this.leader != null && leader == null) { return true; } else if (this.leader == null && leader != null) { Assert.arg(servers.contains(leader), "leader must be present in servers list"); return true; } else if (this.leader != null && !this.leader.equals(leader)) { Assert.arg(servers.contains(leader), "leader must be present in servers list"); return true; } else if (!matches(this.servers, servers)) { return true; } return false; }
/** * Sets the client transport, returning the server builder for method chaining. * * <p>The configured transport should be the same transport as all clients. If no transport is * explicitly provided, the instance will default to the {@code NettyTransport} if available on * the classpath. * * @param transport The server transport. * @return The server builder. * @throws NullPointerException if {@code transport} is null */ public Builder withClientTransport(Transport transport) { this.clientTransport = Assert.notNull(transport, "transport"); return this; }
private AtomixReplica(ResourceClient client, ResourceServer server, ClusterBalancer balancer) { super(client); this.server = Assert.notNull(server, "server"); this.balancer = Assert.notNull(balancer, "balancer"); }
/** @throws NullPointerException if {@code directory} is null */ public Storage(String directory) { this(new File(Assert.notNull(directory, "directory"))); }
@Override public Listener<Session> onOpen(Consumer<Session> listener) { return openListeners.add(Assert.notNull(listener, "listener")); }
/** * Sets the Atomix resource type resolver. * * @param resolver The resource type resolver. * @return The Atomix builder. */ public Builder withResourceResolver(ResourceTypeResolver resolver) { this.resourceResolver = Assert.notNull(resolver, "resolver"); return this; }
public Storage(StorageLevel storageLevel) { this.storageLevel = Assert.notNull(storageLevel, "storageLevel"); }
/** * Sets the log directory, returning the builder for method chaining. * * <p>The log will write segment files into the provided directory. If multiple {@link Storage} * objects are located on the same machine, they write logs to different directories. * * @param directory The log directory. * @return The storage builder. * @throws NullPointerException If the {@code directory} is {@code null} */ public Builder withDirectory(String directory) { return withDirectory(new File(Assert.notNull(directory, "directory"))); }
SnapshotWriter(Buffer buffer, Snapshot snapshot, Serializer serializer) { this.buffer = Assert.notNull(buffer, "buffer"); this.snapshot = Assert.notNull(snapshot, "snapshot"); this.serializer = Assert.notNull(serializer, "serializer"); }
public ResourceManagerState(ResourceRegistry registry) { this.registry = Assert.notNull(registry, "registry"); }
/** * Sets the server transport, returning the server builder for method chaining. * * <p>The configured transport should be the same transport as all other servers in the cluster. * If no transport is explicitly provided, the instance will default to the {@code * NettyTransport} if available on the classpath. * * @param transport The server transport. * @return The server builder. * @throws NullPointerException if {@code transport} is null */ public Builder withServerTransport(Transport transport) { this.serverTransport = Assert.notNull(transport, "transport"); return this; }
/** @throws NullPointerException if {@code directory} is null */ public Storage(String directory, StorageLevel storageLevel) { this(new File(Assert.notNull(directory, "directory")), storageLevel); }
@Override public CompletableFuture<Void> listen(Address address, Consumer<Connection> listener) { Assert.notNull(address, "address"); Assert.notNull(listener, "listener"); return local.listen(address, listener).thenCompose(v -> remote.listen(address, listener)); }
CombinedCopycatClient(CopycatClient client, Transport transport) { this.client = Assert.notNull(client, "client"); this.transport = Assert.notNull(transport, "transport"); }
@Override public Listener<Session> onClose(Consumer<Session> listener) { return closeListeners.add(Assert.notNull(listener, "listener")); }
/** * Sets the log directory, returning the builder for method chaining. * * <p>The log will write segment files into the provided directory. If multiple {@link Storage} * objects are located on the same machine, they write logs to different directories. * * @param directory The log directory. * @return The storage builder. * @throws NullPointerException If the {@code directory} is {@code null} */ public Builder withDirectory(File directory) { storage.directory = Assert.notNull(directory, "directory"); return this; }
/** * Returns a new Atomix replica builder. * * <p>The provided set of members will be used to connect to the other members in the Raft * cluster. * * @param clientAddress The address through which clients connect to the server. * @param serverAddress The local server member address. * @param members The cluster members to which to connect. * @return The replica builder. */ public static Builder builder(Address clientAddress, Address serverAddress, Address... members) { return builder(clientAddress, serverAddress, Arrays.asList(Assert.notNull(members, "members"))); }
/** * Sets the major compaction interval, returning the builder for method chaining. * * <p>The major compaction interval dictates the interval at which the {@link * io.atomix.copycat.server.storage.compaction.MajorCompactionManager} should evaluate {@link * Segment}s in the log for major compaction. Because of the performance costs of major * compaction, it is recommended that the major compaction interval be at least an order of * magnitude greater than the minor compaction interval. * * @see io.atomix.copycat.server.storage.compaction.MajorCompactionManager * @see io.atomix.copycat.server.storage.compaction.MajorCompactionTask * @param interval The major compaction interval. * @return The storage builder. */ public Builder withMajorCompactionInterval(Duration interval) { storage.majorCompactionInterval = Assert.notNull(interval, "interval"); return this; }
/** @throws NullPointerException if {@code directory} is null */ public Storage(File directory, StorageLevel storageLevel) { this.directory = Assert.notNull(directory, "directory"); this.storageLevel = Assert.notNull(storageLevel, "storageLevel"); }
/** * Sets the quorum hint. * * @param quorum The quorum hint. * @return The replica builder. */ public Builder withQuorumHint(Quorum quorum) { this.quorumHint = Assert.notNull(quorum, "quorum").size(); return this; }
/** * Sets the request member. * * @param member The request member. * @return The request builder. * @throws NullPointerException if {@code member} is null */ public Builder withMember(Address member) { request.member = Assert.notNull(member, "member"); return this; }
/** * Sets the log storage level, returning the builder for method chaining. * * <p>The storage level indicates how individual {@link * io.atomix.copycat.server.storage.entry.Entry entries} should be persisted in the log. * * @param storageLevel The log storage level. * @return The storage builder. */ public Builder withStorageLevel(StorageLevel storageLevel) { storage.storageLevel = Assert.notNull(storageLevel, "storageLevel"); return this; }