Search in sources :

Example 1 with BorrowObjectException

use of com.ctrip.xpipe.pool.BorrowObjectException in project x-pipe by ctripcorp.

the class TransactionalCommand method doExecute.

@Override
protected void doExecute() throws CommandExecutionException {
    try {
        final NettyClient nettyClient = parentClientPool.borrowObject();
        SimpleObjectPool<NettyClient> clientPool = new FixedObjectPool<NettyClient>(nettyClient);
        startTransaction(clientPool);
        future().addListener(new CommandFutureListener<Object[]>() {

            @Override
            public void operationComplete(CommandFuture<Object[]> commandFuture) throws Exception {
                if (nettyClient != null) {
                    try {
                        parentClientPool.returnObject(nettyClient);
                    } catch (ReturnObjectException e) {
                        logger.error("[doExecute]" + this, e);
                    }
                }
            }
        });
    } catch (BorrowObjectException e) {
        throw new CommandExecutionException("execute " + this, e);
    }
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) ReturnObjectException(com.ctrip.xpipe.pool.ReturnObjectException) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) FixedObjectPool(com.ctrip.xpipe.pool.FixedObjectPool) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) ReturnObjectException(com.ctrip.xpipe.pool.ReturnObjectException) BorrowObjectException(com.ctrip.xpipe.pool.BorrowObjectException) BorrowObjectException(com.ctrip.xpipe.pool.BorrowObjectException)

Example 2 with BorrowObjectException

use of com.ctrip.xpipe.pool.BorrowObjectException in project x-pipe by ctripcorp.

the class AbstractNettyCommand method doExecute.

@Override
protected void doExecute() throws CommandExecutionException {
    NettyClient nettyClient = null;
    try {
        logger.debug("[doExecute]{}", this);
        nettyClient = clientPool.borrowObject();
        ByteBuf byteBuf = getRequest();
        doSendRequest(nettyClient, byteBuf);
    } catch (BorrowObjectException e) {
        throw new CommandExecutionException("execute " + this, e);
    } finally {
        if (nettyClient != null) {
            try {
                clientPool.returnObject(nettyClient);
            } catch (ReturnObjectException e) {
                logger.error("[doExecute]", e);
            }
        }
        if (poolCreated) {
            future().addListener(new CommandFutureListener<V>() {

                @Override
                public void operationComplete(CommandFuture<V> commandFuture) throws Exception {
                    LifecycleHelper.stopIfPossible(clientPool);
                    LifecycleHelper.disposeIfPossible(clientPool);
                }
            });
        }
    }
}
Also used : ReturnObjectException(com.ctrip.xpipe.pool.ReturnObjectException) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) ByteBuf(io.netty.buffer.ByteBuf) BorrowObjectException(com.ctrip.xpipe.pool.BorrowObjectException) ReturnObjectException(com.ctrip.xpipe.pool.ReturnObjectException) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) BorrowObjectException(com.ctrip.xpipe.pool.BorrowObjectException)

Aggregations

CommandExecutionException (com.ctrip.xpipe.command.CommandExecutionException)2 BorrowObjectException (com.ctrip.xpipe.pool.BorrowObjectException)2 ReturnObjectException (com.ctrip.xpipe.pool.ReturnObjectException)2 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)1 FixedObjectPool (com.ctrip.xpipe.pool.FixedObjectPool)1 ByteBuf (io.netty.buffer.ByteBuf)1