Java Code Examples for io.atomix.primitive.PrimitiveState#CONNECTED
The following examples show how to use
io.atomix.primitive.PrimitiveState#CONNECTED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractProxyClient.java From atomix with Apache License 2.0 | 6 votes |
/** * Handles a partition proxy state change. */ private synchronized void onStateChange(PartitionId partitionId, PrimitiveState state) { states.put(partitionId, state); switch (state) { case CONNECTED: if (this.state != PrimitiveState.CONNECTED && !states.containsValue(PrimitiveState.SUSPENDED) && !states.containsValue(PrimitiveState.CLOSED)) { this.state = PrimitiveState.CONNECTED; stateChangeListeners.forEach(l -> l.accept(PrimitiveState.CONNECTED)); } break; case SUSPENDED: if (this.state == PrimitiveState.CONNECTED) { this.state = PrimitiveState.SUSPENDED; stateChangeListeners.forEach(l -> l.accept(PrimitiveState.SUSPENDED)); } break; case CLOSED: if (this.state != PrimitiveState.CLOSED) { this.state = PrimitiveState.CLOSED; stateChangeListeners.forEach(l -> l.accept(PrimitiveState.CLOSED)); } break; } }
Example 2
Source File: KeyLock.java From atomix with Apache License 2.0 | 6 votes |
/** * Attempts to lock the key. * * @return a future to be completed once the lock attempt is complete */ CompletableFuture<OptionalLong> tryLock() { // If the proxy is currently disconnected from the cluster, we can just fail the lock attempt here. PrimitiveState state = client.getPartition(partitionId).getState(); if (state != PrimitiveState.CONNECTED) { return CompletableFuture.completedFuture(OptionalLong.empty()); } // Create and register a new attempt and invoke the LOCK operation on teh replicated state machine with // a 0 timeout. The timeout will cause the state machine to immediately reject the request if the lock is // already owned by another process. LockFuture future = new LockFuture(); client.acceptOn(partitionId, service -> service.lock(key, future.id(), 0)).whenComplete((result, error) -> { if (error != null) { future.completeExceptionally(error); } }); return future.thenApply(v -> v != null ? OptionalLong.of(v) : OptionalLong.empty()); }
Example 3
Source File: AtomicLockProxy.java From atomix with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<Optional<Version>> tryLock() { // If the proxy is currently disconnected from the cluster, we can just fail the lock attempt here. PrimitiveState state = getProxyClient().getPartition(name()).getState(); if (state != PrimitiveState.CONNECTED) { return CompletableFuture.completedFuture(Optional.empty()); } // Create and register a new attempt and invoke the LOCK operation on teh replicated state machine with // a 0 timeout. The timeout will cause the state machine to immediately reject the request if the lock is // already owned by another process. LockAttempt attempt = new LockAttempt(); getProxyClient().acceptBy(name(), service -> service.lock(attempt.id(), 0)).whenComplete((result, error) -> { if (error != null) { attempt.completeExceptionally(error); } }); return attempt.thenApply(Optional::ofNullable); }
Example 4
Source File: ClusterClient.java From submarine with Apache License 2.0 | 5 votes |
@Override public boolean raftInitialized() { if (null != raftClient && null != raftSessionClient && raftSessionClient.getState() == PrimitiveState.CONNECTED) { return true; } return false; }
Example 5
Source File: ClusterServer.java From submarine with Apache License 2.0 | 5 votes |
@Override public boolean raftInitialized() { if (null != raftServer && raftServer.isRunning() && null != raftClient && null != raftSessionClient && raftSessionClient.getState() == PrimitiveState.CONNECTED) { return true; } return false; }
Example 6
Source File: ClusterManagerClient.java From zeppelin with Apache License 2.0 | 5 votes |
@Override public boolean raftInitialized() { if (null != raftClient && null != raftSessionClient && raftSessionClient.getState() == PrimitiveState.CONNECTED) { return true; } return false; }
Example 7
Source File: ClusterManagerServer.java From zeppelin with Apache License 2.0 | 5 votes |
@Override public boolean raftInitialized() { if (null != raftServer && raftServer.isRunning() && null != raftClient && null != raftSessionClient && raftSessionClient.getState() == PrimitiveState.CONNECTED) { return true; } return false; }
Example 8
Source File: KeyLock.java From atomix with Apache License 2.0 | 5 votes |
/** * Handles a primitive state change. * * @param state the primitive state change */ void change(PrimitiveState state) { if (state != PrimitiveState.CONNECTED) { for (LockFuture future : futures.values()) { client.acceptOn(partitionId, service -> service.unlock(key, future.id())); future.completeExceptionally(new PrimitiveException.Unavailable()); } } }
Example 9
Source File: AtomicLockProxy.java From atomix with Apache License 2.0 | 5 votes |
private void onStateChange(PrimitiveState state) { if (state != PrimitiveState.CONNECTED) { for (LockAttempt attempt : attempts.values()) { getProxyClient().acceptBy(name(), service -> service.unlock(attempt.id())); attempt.completeExceptionally(new PrimitiveException.Unavailable()); } } }