Java Code Examples for io.netty.util.concurrent.Future#isDone()
The following examples show how to use
io.netty.util.concurrent.Future#isDone() .
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: LocalChannel.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
private void finishPeerRead0(LocalChannel peer) { Future<?> peerFinishReadFuture = peer.finishReadFuture; if (peerFinishReadFuture != null) { if (!peerFinishReadFuture.isDone()) { runFinishPeerReadTask(peer); return; } else { // Lazy unset to make sure we don't prematurely unset it while scheduling a new task. FINISH_READ_FUTURE_UPDATER.compareAndSet(peer, peerFinishReadFuture, null); } } ChannelPipeline peerPipeline = peer.pipeline(); if (peer.readInProgress) { peer.readInProgress = false; for (;;) { Object received = peer.inboundBuffer.poll(); if (received == null) { break; } peerPipeline.fireChannelRead(received); } peerPipeline.fireChannelReadComplete(); } }
Example 2
Source File: DefaultDnsClient.java From servicetalk with Apache License 2.0 | 6 votes |
private void doQuery0() { assertInEventloop(); if (closed) { // best effort check to cleanup state after close. handleTerminalError0(new ClosedServiceDiscovererException(DefaultDnsClient.this + " has been closed!")); } else { final DnsResolutionObserver resolutionObserver = newResolutionObserver(); LOGGER.trace("DnsClient {}, querying DNS for {}", DefaultDnsClient.this, AbstractDnsPublisher.this); final Future<DnsAnswer<T>> addressFuture = doDnsQuery(); cancellableForQuery = () -> addressFuture.cancel(true); if (addressFuture.isDone()) { handleResolveDone0(addressFuture, resolutionObserver); } else { addressFuture.addListener((FutureListener<DnsAnswer<T>>) f -> handleResolveDone0(f, resolutionObserver)); } } }
Example 3
Source File: VirtualClientConnection.java From quarkus with Apache License 2.0 | 6 votes |
private void finishPeerRead0(VirtualChannel peer) { Future<?> peerFinishReadFuture = peer.finishReadFuture; if (peerFinishReadFuture != null) { if (!peerFinishReadFuture.isDone()) { runFinishPeerReadTask(peer); return; } else { // Lazy unset to make sure we don't prematurely unset it while scheduling a new task. VirtualChannel.FINISH_READ_FUTURE_UPDATER.compareAndSet(peer, peerFinishReadFuture, null); } } // We should only set readInProgress to false if there is any data that was read as otherwise we may miss to // forward data later on. if (peer.readInProgress && !peer.inboundBuffer.isEmpty()) { peer.readInProgress = false; peer.readInbound(); } }
Example 4
Source File: SimpleChannelPool.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
private void doHealthCheckOnRelease(final Channel channel, final Promise<Void> promise) throws Exception { final Future<Boolean> f = healthCheck.isHealthy(channel); if (f.isDone()) { releaseAndOfferIfHealthy(channel, promise, f); } else { f.addListener(new FutureListener<Boolean>() { @Override public void operationComplete(Future<Boolean> future) throws Exception { releaseAndOfferIfHealthy(channel, promise, f); } }); } }
Example 5
Source File: ConnectionPool.java From drift with Apache License 2.0 | 5 votes |
@Override public Future<Channel> getConnection(ConnectionParameters connectionParameters, HostAndPort address) { ConnectionKey key = new ConnectionKey(connectionParameters, address); while (true) { synchronized (this) { if (closed) { return group.next().newFailedFuture(new TTransportException("Connection pool is closed")); } Future<Channel> future; try { future = cachedConnections.get(key, () -> createConnection(key)); } catch (ExecutionException e) { throw new RuntimeException(e); } // connection is still opening if (!future.isDone()) { return future; } // check if connection is failed or closed Channel channel = future.getNow(); // channel can be null if the future was canceled if (channel != null && channel.isOpen()) { return future; } // remove dead connection from cache cachedConnections.asMap().remove(key, future); } } }
Example 6
Source File: SpecialCake.java From netty.book.kor with MIT License | 5 votes |
public static void main(String[] args) throws InterruptedException { Bakery bakery = new Bakery(); // 케이크를 주문하고 주문서를 받는다. Future future = bakery.orderCake(); // 다른 일을 한다. //… doSomthing(); //… // 케이크가 완성되었는지 확인한다. if(future.isDone()){ // Cake cake = future.getCake()); } else{ // 케이크가 완성되었는지 확인한다. while(future.isDone() != true){ // 다른일을 한다. // ... doSomthing(); // ... } // while 루프를 빠져나왔으므로 완성된 케이크를 가져온다. // Cake cake = future.getCake()); } }
Example 7
Source File: Client.java From xio with Apache License 2.0 | 5 votes |
private void executeBufferedRequests(Future<? super Void> connectionResult) { boolean connectionSuccess = connectionResult.isDone() && connectionResult.isSuccess(); log.debug("== Connection success was " + connectionSuccess); // loop through the queue until it's empty and fire away // this will happen on the same event loop as the write so we don't need to worry about // trying to write to this queue at the same time we dequeue while (!requestQueue.isEmpty()) { Client.ClientPayload requestPayload = requestQueue.remove(); log.debug("== Dequeue req: " + requestPayload.request + " on client: " + this); if (connectionSuccess) { this.rawWrite(requestPayload.request) .addListener( (writeResult) -> { if (writeResult.isDone() && writeResult.isSuccess()) { log.debug( "== Req: " + requestPayload.request + " succeeded on client: " + this); requestPayload.promise.setSuccess(); } else { log.error("Req: failed on client: " + this); final Throwable cause; if (connectionResult.cause() != null) { cause = connectionResult.cause(); } else { cause = new RuntimeException("unknown cause"); } requestPayload.promise.setFailure(cause); } }); } else { log.error("Req: failed on client: " + this); requestPayload.promise.setFailure(connectionResult.cause()); } } }