Search in sources :

Example 1 with FixedObjectPool

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

the class AbstractFakeRedisTest method sendInmemoryPsync.

protected InMemoryPsync sendInmemoryPsync(String ip, int port, String runid, long offset) throws Exception {
    SequenceCommandChain chain = new SequenceCommandChain(false);
    SimpleObjectPool<NettyClient> pool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress(ip, port));
    NettyClient nettyClient = null;
    try {
        nettyClient = pool.borrowObject();
        SimpleObjectPool<NettyClient> clientPool = new FixedObjectPool<NettyClient>(nettyClient);
        chain.add(new Replconf(clientPool, ReplConfType.CAPA, scheduled, CAPA.EOF.toString()));
        InMemoryPsync psync = new InMemoryPsync(clientPool, runid, offset, scheduled);
        chain.add(psync);
        psync.addPsyncObserver(new PsyncObserver() {

            private long masterRdbOffset = 0;

            @Override
            public void reFullSync() {
            }

            @Override
            public void onFullSync() {
            }

            @Override
            public void onContinue(String requestReplId, String responseReplId) {
            }

            @Override
            public void endWriteRdb() {
                new Replconf(clientPool, ReplConfType.ACK, scheduled, String.valueOf(masterRdbOffset)).execute();
            }

            @Override
            public void beginWriteRdb(EofType eofType, long masterRdbOffset) throws IOException {
                this.masterRdbOffset = masterRdbOffset;
            }
        });
        chain.execute();
        return psync;
    } finally {
        if (nettyClient != null) {
            pool.returnObject(nettyClient);
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Replconf(com.ctrip.xpipe.redis.core.protocal.cmd.Replconf) EofType(com.ctrip.xpipe.redis.core.protocal.protocal.EofType) IOException(java.io.IOException) SequenceCommandChain(com.ctrip.xpipe.command.SequenceCommandChain) NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) FixedObjectPool(com.ctrip.xpipe.pool.FixedObjectPool) InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) PsyncObserver(com.ctrip.xpipe.redis.core.protocal.PsyncObserver)

Example 2 with FixedObjectPool

use of com.ctrip.xpipe.pool.FixedObjectPool 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 3 with FixedObjectPool

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

the class AbstractCommandTest method createClientPool.

protected FixedObjectPool<NettyClient> createClientPool(String host, int port) throws Exception {
    NettyClientFactory nettyClientFactory = new NettyClientFactory(new InetSocketAddress(host, port));
    nettyClientFactory.start();
    stoppables.add(nettyClientFactory);
    NettyClient nettyClient = nettyClientFactory.makeObject().getObject();
    FixedObjectPool<NettyClient> clientPool = new FixedObjectPool<NettyClient>(nettyClient);
    return clientPool;
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) InetSocketAddress(java.net.InetSocketAddress) NettyClientFactory(com.ctrip.xpipe.netty.commands.NettyClientFactory) FixedObjectPool(com.ctrip.xpipe.pool.FixedObjectPool)

Aggregations

NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)3 FixedObjectPool (com.ctrip.xpipe.pool.FixedObjectPool)3 InetSocketAddress (java.net.InetSocketAddress)2 CommandExecutionException (com.ctrip.xpipe.command.CommandExecutionException)1 SequenceCommandChain (com.ctrip.xpipe.command.SequenceCommandChain)1 NettyClientFactory (com.ctrip.xpipe.netty.commands.NettyClientFactory)1 BorrowObjectException (com.ctrip.xpipe.pool.BorrowObjectException)1 ReturnObjectException (com.ctrip.xpipe.pool.ReturnObjectException)1 PsyncObserver (com.ctrip.xpipe.redis.core.protocal.PsyncObserver)1 InMemoryPsync (com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync)1 Replconf (com.ctrip.xpipe.redis.core.protocal.cmd.Replconf)1 EofType (com.ctrip.xpipe.redis.core.protocal.protocal.EofType)1 IOException (java.io.IOException)1