Java Code Examples for io.netty.util.concurrent.Future#isSuccess()

The following examples show how to use io.netty.util.concurrent.Future#isSuccess() . 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: PublishWritePromiseListener.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
@Override
public void operationComplete(final Future<? super Void> future) throws Exception {
    if (!future.isSuccess()) {
        final Throwable cause = future.cause();
        if (Exceptions.isConnectionClosedException(cause)) {
            log.trace("Failed to write publish. Client not connected anymore");
            statusFuture.set(PublishStatus.NOT_CONNECTED);

        } else if (cause instanceof EncoderException) {
            Exceptions.rethrowError("Failed to write publish. Encoding Failure.", cause);
            final Throwable rootCause = cause.getCause();
            if (cause != rootCause) {
                Exceptions.rethrowError("Failed to write publish. Encoding Failure, root cause:", rootCause);
            }
            statusFuture.set(PublishStatus.FAILED);
        } else {
            Exceptions.rethrowError("Failed to write publish.", cause);
            statusFuture.set(PublishStatus.FAILED);
        }
    }
}
 
Example 2
Source File: AsyncOlapNIOLayer.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void operationComplete(Future<Channel> channelFuture) throws Exception{
    if (LOG.isTraceEnabled())
        LOG.trace("Submit command ");
    if(!channelFuture.isSuccess()){
        olapFuture.fail(channelFuture.cause());
        return;
    }
    final Channel c=channelFuture.getNow();
    ChannelPipeline writePipeline=c.pipeline();
    writePipeline.addLast("handler",olapFuture.submitHandler);

    if (LOG.isTraceEnabled()) {
        LOG.trace("Submitted job " + olapFuture.job.getUniqueName());
    }

    OlapMessage.Submit submit=OlapMessage.Submit.newBuilder().setCommandBytes(olapFuture.data).build();
    OlapMessage.Command cmd=OlapMessage.Command.newBuilder()
            .setUniqueName(olapFuture.job.getUniqueName())
            .setExtension(OlapMessage.Submit.command,submit)
            .setType(OlapMessage.Command.Type.SUBMIT)
            .build();
    ChannelFuture writeFuture=c.writeAndFlush(cmd);
    writeFuture.addListener(olapFuture.failListener);

}
 
Example 3
Source File: TCPServer.java    From jt-808-protocol with MIT License 6 votes vote down vote up
public synchronized void stopServer() {
	if (!this.isRunning) {
		throw new IllegalStateException(this.getName() + " is not yet started .");
	}
	this.isRunning = false;

	try {
		Future<?> future = this.workerGroup.shutdownGracefully().await();
		if (!future.isSuccess()) {
			log.error("workerGroup 无法正常停止:{}", future.cause());
		}

		future = this.bossGroup.shutdownGracefully().await();
		if (!future.isSuccess()) {
			log.error("bossGroup 无法正常停止:{}", future.cause());
		}
	} catch (InterruptedException e) {
		e.printStackTrace();
	}

	this.log.info("TCP服务已经停止...");
}
 
Example 4
Source File: ServerApplication.java    From jt808 with Apache License 2.0 6 votes vote down vote up
public synchronized void stopServer() {
	if (!this.isRunning) {
		throw new IllegalStateException(this.getName() + "未启动");
	}
	this.isRunning = false;

	try {
		Future<?> future = this.workerGroup.shutdownGracefully().await();
		if (!future.isSuccess()) {
		}
		future = this.bossGroup.shutdownGracefully().await();
		if (!future.isSuccess()) {
		}
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
}
 
Example 5
Source File: FastdfsExecutor.java    From fastdfs-client with Apache License 2.0 5 votes vote down vote up
@Override
public void operationComplete(Future<Channel> cf) throws Exception {

    if (cf.isCancelled()) {
        promise.cancel(true);
        return;
    }

    if (!cf.isSuccess()) {
        promise.completeExceptionally(cf.cause());
        return;
    }

    Channel channel = cf.getNow();
    promise.whenComplete((result, error) -> {
        if (null != error) {
            channel.close().addListener(ignore -> pool.release(channel));
            return;
        }

        pool.release(channel);
    });

    try {

        FastdfsOperation<T> fastdfsOperation = new FastdfsOperation<>(channel, requestor, replier, promise);
        if (LOG.isDebugEnabled()) {
            LOG.debug("execute {}", fastdfsOperation);
        }

        fastdfsOperation.execute();
    } catch (Exception e) {
        promise.completeExceptionally(e);
    }
}
 
Example 6
Source File: HttpClientDelegate.java    From armeria with Apache License 2.0 5 votes vote down vote up
private void finishResolve(ClientRequestContext ctx, Endpoint endpointWithPort,
                           Future<InetSocketAddress> resolveFuture, HttpRequest req,
                           DecodedHttpResponse res, ClientConnectionTimingsBuilder timingsBuilder) {
    timingsBuilder.dnsResolutionEnd();
    if (resolveFuture.isSuccess()) {
        final String ipAddr = resolveFuture.getNow().getAddress().getHostAddress();
        acquireConnectionAndExecute(ctx, endpointWithPort, ipAddr, req, res, timingsBuilder);
    } else {
        ctx.logBuilder().session(null, ctx.sessionProtocol(), timingsBuilder.build());
        final UnprocessedRequestException cause = UnprocessedRequestException.of(resolveFuture.cause());
        handleEarlyRequestException(ctx, req, cause);
        res.close(cause);
    }
}
 
Example 7
Source File: Socks5ProxyServerHandlerBuilder.java    From sissi with Apache License 2.0 5 votes vote down vote up
@Override
public void operationComplete(Future<Void> future) throws Exception {
	if (future.isSuccess()) {
		ctx.pipeline().remove(IdleStateHandler.class);
		ctx.pipeline().addFirst(new BridgeExchangerServerHandler());
		ctx.pipeline().context(BridgeExchangerServerHandler.class).attr(Socks5ProxyServerHandlerBuilder.this.exchanger).set(this.exchanger);
	}
}
 
Example 8
Source File: FastdfsExecutor.java    From azeroth with Apache License 2.0 5 votes vote down vote up
@Override
public void operationComplete(Future<Channel> cf) throws Exception {

    if (cf.isCancelled()) {
        promise.cancel(true);
        return;
    }

    if (!cf.isSuccess()) {
        promise.completeExceptionally(cf.cause());
        return;
    }

    Channel channel = cf.getNow();
    promise.whenComplete((result, error) -> pool.release(channel));

    try {

        FastdfsOperation<T> fastdfsOperation = new FastdfsOperation<>(channel, requestor,
            replier, promise);
        if (LOG.isDebugEnabled()) {
            LOG.debug("execute {}", fastdfsOperation);
        }

        fastdfsOperation.execute();
    } catch (Exception e) {
        promise.completeExceptionally(e);
    }
}
 
Example 9
Source File: NioServer.java    From sissi with Apache License 2.0 5 votes vote down vote up
public void operationComplete(Future<Void> future) throws Exception {
	if (!future.isSuccess()) {
		NioServer.this.closeAll();
		NioServer.this.log.fatal(future.cause());
		Trace.trace(NioServer.this.log, future.cause());
	}
}
 
Example 10
Source File: NettyServer.java    From ClusterDeviceControlPlatform with MIT License 5 votes vote down vote up
private void startListenerHandle(Future future, SuccessfulListener listener) {
    try {
        Thread.sleep(10);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    if (!future.isSuccess()) future.cause().printStackTrace();
    if (listener != null) listener.onSuccess(future.isSuccess());
}
 
Example 11
Source File: DirectProxyHandler.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public void operationComplete(Future<Void> future) throws Exception {
    // This is invoked when the write operation on the paired connection
    // is completed
    if (future.isSuccess()) {
        outboundChannel.read();
    } else {
        log.warn("[{}] [{}] Failed to write on proxy connection. Closing both connections.", inboundChannel,
                outboundChannel, future.cause());
        inboundChannel.close();
    }
}
 
Example 12
Source File: PassportStateListener.java    From zuul with Apache License 2.0 5 votes vote down vote up
@Override
public void operationComplete(Future future) throws Exception
{
    if (future.isSuccess()) {
        passport.add(successState);
    }
    else {
        if (failState != null)
            passport.add(failState);
    }
}
 
Example 13
Source File: AsyncOlapNIOLayer.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void operationComplete(Future<Void> future) throws Exception{
    if(!future.isSuccess()){
        fail(future.cause());
        signal();
    }
}
 
Example 14
Source File: SimpleApnsClientCache.java    From aerogear-unifiedpush-server with Apache License 2.0 5 votes vote down vote up
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
    if (future.isSuccess()) {
        logger.debug("Successfully disconnected connection...");
    } else {
        final Throwable t = future.cause();
        logger.warn(t.getMessage(), t);
    }

}
 
Example 15
Source File: Client.java    From xio with Apache License 2.0 5 votes vote down vote up
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());
    }
  }
}
 
Example 16
Source File: SendHandlerAdapter.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
    if (future.isSuccess()) {
        handler.onResult(OK);
    } else {
        handler.onResult(new SendResult(future.cause()));
    }
}
 
Example 17
Source File: AsyncOlapNIOLayer.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void operationComplete(Future<Channel> channelFuture) throws Exception{
    if(!channelFuture.isSuccess()){
         /*
          * Unfortunately, no one is listening to this, so there's really no
          * way to communicate this back to the client (the client has moved on).
          * So just note the error and move on.
          */
        LOG.error("Unable to cancel job "+uniqueName+": Unable to obtain channel",channelFuture.cause());
        return;
    }

    final Channel c=channelFuture.getNow();

    OlapMessage.Cancel cancel=OlapMessage.Cancel.newBuilder().build();
    OlapMessage.Command cmd=OlapMessage.Command.newBuilder()
            .setUniqueName(uniqueName)
            .setType(OlapMessage.Command.Type.CANCEL)
            .setExtension(OlapMessage.Cancel.command,cancel).build();
    ChannelFuture writeFuture=c.writeAndFlush(cmd);
    writeFuture.addListener(new GenericFutureListener<Future<Void>>(){
        @Override
        public void operationComplete(Future<Void> future) throws Exception{
            if(future.isSuccess()){
                if(LOG.isTraceEnabled()){
                    LOG.trace("job "+uniqueName+" cancelled successfully");
                }
            }else{
                LOG.error("Unable to cancel job "+uniqueName+": Unable to write cancel command",future.cause());
            }
            //once the write is complete, release the channel from the pool
            channelPool.release(c);
        }
    });
}
 
Example 18
Source File: FixDomainStartTls.java    From sissi with Apache License 2.0 4 votes vote down vote up
public void operationComplete(Future<Void> future) throws Exception {
	if (future.isSuccess() && this.prepareTls.get()) {
		this.context.pipeline().addFirst(this.handler);
		this.prepareTls.compareAndSet(true, false);
	}
}
 
Example 19
Source File: DnsNameResolverContext.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
public void operationComplete(Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> future) {
    if (future.isSuccess()) {
        future.getNow().release();
    }
}
 
Example 20
Source File: BasicClient.java    From Bats with Apache License 2.0 4 votes vote down vote up
public void operationComplete(Future<? super Void> future) throws Exception {
  if (!future.isSuccess()) {
    logger.error("Unable to maintain connection {}.  Closing connection.", connection.getName());
    connection.close();
  }
}