CompletableFuture<byte[]> transfer(byte[] request) { if (transferHandler != null) { return transferHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
CompletableFuture<byte[]> heartbeat(byte[] request) { if (heartbeatHandler != null) { return heartbeatHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
CompletableFuture<byte[]> closeSession(byte[] request) { if (closeSessionHandler != null) { return closeSessionHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
CompletableFuture<byte[]> command(byte[] request) { if (commandHandler != null) { return commandHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
CompletableFuture<byte[]> leave(byte[] request) { if (leaveHandler != null) { return leaveHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
CompletableFuture<byte[]> poll(byte[] request) { if (pollHandler != null) { return pollHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
CompletableFuture<byte[]> openSession(byte[] request) { if (openSessionHandler != null) { return openSessionHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
CompletableFuture<byte[]> query(byte[] request) { if (queryHandler != null) { return queryHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
CompletableFuture<byte[]> keepAlive(byte[] request) { if (keepAliveHandler != null) { return keepAliveHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
CompletableFuture<byte[]> configure(byte[] request) { if (configureHandler != null) { return configureHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
CompletableFuture<byte[]> reconfigure(byte[] request) { if (reconfigureHandler != null) { return reconfigureHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
CompletableFuture<byte[]> metadata(byte[] request) { if (metadataHandler != null) { return metadataHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
CompletableFuture<byte[]> join(byte[] request) { if (joinHandler != null) { return joinHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
CompletableFuture<byte[]> install(byte[] request) { if (installHandler != null) { return installHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
CompletableFuture<byte[]> append(byte[] request) { if (appendHandler != null) { return appendHandler.apply(decode(request)).thenApply(this::encode); } else { return Futures.exceptionalFuture(new ConnectException()); } }
final boolean failConnectPromise(Throwable cause) { if (connectPromise != null) { // SO_ERROR has been shown to return 0 on macOS if detect an error via read() and the write filter was // not set before calling connect. This means finishConnect will not detect any error and would // successfully complete the connectPromise and update the channel state to active (which is incorrect). ChannelPromise connectPromise = AbstractKQueueChannel.this.connectPromise; AbstractKQueueChannel.this.connectPromise = null; if (connectPromise.tryFailure((cause instanceof ConnectException) ? cause : new ConnectException("failed to connect").initCause(cause))) { closeIfClosed(); return true; } } return false; }
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); }
private CompletableFuture<LocalRaftServerProtocol> getServer(MemberId memberId) { LocalRaftServerProtocol server = server(memberId); if (server != null) { return Futures.completedFuture(server); } else { return Futures.exceptionalFuture(new ConnectException()); } }
private CompletableFuture<LocalRaftClientProtocol> getClient(MemberId memberId) { LocalRaftClientProtocol client = client(memberId); if (client != null) { return Futures.completedFuture(client); } else { return Futures.exceptionalFuture(new ConnectException()); } }
/** Does all the work necessary to build a full HTTP or HTTPS connection on a raw socket. */ private void connectSocket(int connectTimeout, int readTimeout, Call call, EventListener eventListener) throws IOException { Proxy proxy = route.proxy(); Address address = route.address(); rawSocket = proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.HTTP ? address.socketFactory().createSocket() : new Socket(proxy); eventListener.connectStart(call, route.socketAddress(), proxy); rawSocket.setSoTimeout(readTimeout); try { Platform.get().connectSocket(rawSocket, route.socketAddress(), connectTimeout); } catch (ConnectException e) { ConnectException ce = new ConnectException("Failed to connect to " + route.socketAddress()); ce.initCause(e); throw ce; } // The following try/catch block is a pseudo hacky way to get around a crash on Android 7.0 // More details: // https://github.com/square/okhttp/issues/3245 // https://android-review.googlesource.com/#/c/271775/ try { source = Okio.buffer(Okio.source(rawSocket)); sink = Okio.buffer(Okio.sink(rawSocket)); } catch (NullPointerException npe) { if (NPE_THROW_WITH_NULL.equals(npe.getMessage())) { throw new IOException(npe); } } }