Java Code Examples for io.atomix.utils.concurrent.Futures#exceptionalFuture()
The following examples show how to use
io.atomix.utils.concurrent.Futures#exceptionalFuture() .
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: AbstractRole.java From atomix with Apache License 2.0 | 6 votes |
/** * Forwards the given request to the leader if possible. */ protected <T extends RaftRequest, U extends RaftResponse> CompletableFuture<U> forward(T request, BiFunction<MemberId, T, CompletableFuture<U>> function) { CompletableFuture<U> future = new CompletableFuture<>(); DefaultRaftMember leader = raft.getLeader(); if (leader == null) { return Futures.exceptionalFuture(new RaftException.NoLeader("No leader found")); } function.apply(leader.memberId(), request).whenCompleteAsync((response, error) -> { if (error == null) { future.complete(response); } else { future.completeExceptionally(error); } }, raft.getThreadContext()); return future; }
Example 2
Source File: DefaultDistributedCounterBuilder.java From atomix with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<DistributedCounter> buildAsync() { PrimitiveProtocol protocol = protocol(); if (protocol instanceof GossipProtocol) { if (protocol instanceof CounterProtocol) { return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture( new GossipDistributedCounter(name, (GossipProtocol) protocol, ((CounterProtocol) protocol) .newCounterDelegate(name, managementService)))) .thenApply(AsyncDistributedCounter::sync); } else { return Futures.exceptionalFuture(new UnsupportedOperationException("Counter is not supported by the provided gossip protocol")); } } else if (protocol instanceof ProxyProtocol) { return newProxy(AtomicCounterService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicCounterProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(DelegatingDistributedCounter::new) .thenApply(AsyncDistributedCounter::sync); } else { return Futures.exceptionalFuture(new ConfigurationException("Invalid protocol type")); } }
Example 3
Source File: TranscodingAsyncAtomicMap.java From atomix with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<Void> commit(TransactionId transactionId) { try { return backingMap.commit(transactionId); } catch (Exception e) { return Futures.exceptionalFuture(e); } }
Example 4
Source File: LocalRaftServerProtocol.java From zeppelin with Apache License 2.0 | 5 votes |
CompletableFuture<byte[]> openSession(byte[] request) { if (openSessionHandler != null) { return openSessionHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
Example 5
Source File: RaftPartitionServer.java From atomix with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<RaftPartitionServer> start() { log.info("Starting server for partition {}", partition.id()); CompletableFuture<RaftServer> serverOpenFuture; if (partition.members().contains(localMemberId)) { if (server != null && server.isRunning()) { return CompletableFuture.completedFuture(null); } synchronized (this) { try { initServer(); } catch (StorageException e) { return Futures.exceptionalFuture(e); } } serverOpenFuture = server.bootstrap(partition.members()); } else { serverOpenFuture = CompletableFuture.completedFuture(null); } return serverOpenFuture.whenComplete((r, e) -> { if (e == null) { log.debug("Successfully started server for partition {}", partition.id()); } else { log.warn("Failed to start server for partition {}", partition.id(), e); } }).thenApply(v -> this); }
Example 6
Source File: GossipDistributedValue.java From atomix with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<Void> delete() { try { value.set(null); value.close(); return CompletableFuture.completedFuture(null); } catch (Exception e) { return Futures.exceptionalFuture(e); } }
Example 7
Source File: TestRaftClientProtocol.java From atomix with Apache License 2.0 | 5 votes |
private CompletableFuture<TestRaftServerProtocol> getServer(MemberId memberId) { TestRaftServerProtocol server = server(memberId); if (server != null) { return Futures.completedFuture(server); } else { return Futures.exceptionalFuture(new ConnectException()); } }
Example 8
Source File: TranscodingAsyncAtomicMap.java From atomix with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<Boolean> replace(K1 key, long oldVersion, V1 newValue) { try { return backingMap.replace(keyEncoder.apply(key), oldVersion, valueEncoder.apply(newValue)); } catch (Exception e) { return Futures.exceptionalFuture(e); } }
Example 9
Source File: LocalRaftServerProtocol.java From zeppelin with Apache License 2.0 | 5 votes |
CompletableFuture<byte[]> closeSession(byte[] request) { if (closeSessionHandler != null) { return closeSessionHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
Example 10
Source File: RaftMessagingProtocol.java From atomix with Apache License 2.0 | 5 votes |
protected <T, U> CompletableFuture<U> sendAndReceive(MemberId memberId, String type, T request) { Address address = address(memberId); if (address == null) { return Futures.exceptionalFuture(new ConnectException()); } return messagingService.sendAndReceive(address, type, serializer.encode(request)) .thenApply(serializer::decode); }
Example 11
Source File: TranscodingAsyncAtomicMap.java From atomix with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<Boolean> prepare(TransactionLog<MapUpdate<K1, V1>> transactionLog) { try { return backingMap.prepare(transactionLog.map(record -> record.map(keyEncoder, valueEncoder))); } catch (Exception e) { return Futures.exceptionalFuture(e); } }
Example 12
Source File: TranscodingAsyncDistributedMap.java From atomix with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<V1> replace(K1 key, V1 value) { try { return backingMap.replace(keyEncoder.apply(key), valueEncoder.apply(value)) .thenApply(valueDecoder); } catch (Exception e) { return Futures.exceptionalFuture(e); } }
Example 13
Source File: TestPrimaryBackupServerProtocol.java From atomix with Apache License 2.0 | 5 votes |
CompletableFuture<MetadataResponse> metadata(MetadataRequest request) { if (metadataHandler != null) { return metadataHandler.apply(request); } else { return Futures.exceptionalFuture(new ConnectException()); } }
Example 14
Source File: LocalRaftServerProtocol.java From zeppelin with Apache License 2.0 | 5 votes |
CompletableFuture<byte[]> join(byte[] request) { if (joinHandler != null) { return joinHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
Example 15
Source File: LocalRaftServerProtocol.java From zeppelin with Apache License 2.0 | 5 votes |
private CompletableFuture<LocalRaftServerProtocol> getServer(MemberId memberId) { LocalRaftServerProtocol server = server(memberId); if (server != null) { return Futures.completedFuture(server); } else { return Futures.exceptionalFuture(new ConnectException()); } }
Example 16
Source File: AtomicMultimapProxy.java From atomix with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<Void> addListener(CollectionEventListener<Multiset.Entry<byte[]>> listener, Executor executor) { return Futures.exceptionalFuture(new UnsupportedOperationException()); }
Example 17
Source File: AtomicMultimapProxy.java From atomix with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<Boolean> removeAll(Collection<? extends byte[]> c) { return Futures.exceptionalFuture(new UnsupportedOperationException()); }
Example 18
Source File: AtomicMultimapProxy.java From atomix with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<Boolean> containsAll(Collection<? extends byte[]> c) { return Futures.exceptionalFuture(new UnsupportedOperationException()); }
Example 19
Source File: AtomicMultimapProxy.java From atomix with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<Integer> add(byte[] element, int occurrences) { return Futures.exceptionalFuture(new UnsupportedOperationException()); }
Example 20
Source File: AtomicMultimapProxy.java From atomix with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<Boolean> retainAll(Collection<? extends Map.Entry<String, byte[]>> c) { return Futures.exceptionalFuture(new UnsupportedOperationException()); }