Search in sources :

Example 6 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.

the class KeeperStateChangeJob method createKeeperSetStateCommand.

private Command<?> createKeeperSetStateCommand(KeeperMeta keeper, Pair<String, Integer> masterAddress) {
    SimpleObjectPool<NettyClient> pool = new XpipeObjectPoolFromKeyed<InetSocketAddress, NettyClient>(clientPool, new InetSocketAddress(keeper.getIp(), keeper.getPort()));
    KeeperSetStateCommand command = new KeeperSetStateCommand(pool, keeper.isActive() ? KeeperState.ACTIVE : KeeperState.BACKUP, masterAddress, scheduled);
    return CommandRetryWrapper.buildCountRetry(retryTimes, new RetryDelay(delayBaseMilli), command, scheduled);
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) XpipeObjectPoolFromKeyed(com.ctrip.xpipe.pool.XpipeObjectPoolFromKeyed) InetSocketAddress(java.net.InetSocketAddress) RetryDelay(com.ctrip.xpipe.retry.RetryDelay) KeeperSetStateCommand(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractKeeperCommand.KeeperSetStateCommand)

Example 7 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.

the class DefaultSentinelManager method getRealSentinels.

private List<Sentinel> getRealSentinels(List<InetSocketAddress> sentinels, String sentinelMonitorName, ExecutionLog executionLog) {
    List<Sentinel> realSentinels = null;
    for (InetSocketAddress sentinelAddress : sentinels) {
        SimpleObjectPool<NettyClient> clientPool = keyedClientPool.getKeyPool(sentinelAddress);
        Sentinels sentinelsCommand = new Sentinels(clientPool, sentinelMonitorName, scheduled);
        try {
            realSentinels = sentinelsCommand.execute().get();
            executionLog.info(String.format("get sentinels from %s : %s", sentinelAddress, realSentinels));
            if (realSentinels.size() > 0) {
                realSentinels.add(new Sentinel(sentinelAddress.toString(), sentinelAddress.getHostString(), sentinelAddress.getPort()));
                break;
            }
        } catch (InterruptedException | ExecutionException e) {
            logger.warn("[getRealSentinels]get sentinels from " + sentinelAddress, e);
            executionLog.warn("[getRealSentinels]get sentinels from " + sentinelAddress + "," + e.getMessage());
        }
    }
    return realSentinels;
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) Sentinel(com.ctrip.xpipe.redis.core.protocal.pojo.Sentinel) InetSocketAddress(java.net.InetSocketAddress) ExecutionException(java.util.concurrent.ExecutionException) Sentinels(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.Sentinels)

Example 8 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.

the class XpipeNettyClientKeyedObjectPoolTest method testIdleClose.

@Test
public void testIdleClose() throws Exception {
    Server echoServer = startEchoServer();
    InetSocketAddress key = new InetSocketAddress("localhost", echoServer.getPort());
    pool.setKeyPooConfig(0, 200, 500, 100);
    SimpleObjectPool<NettyClient> objectPool = pool.getKeyPool(key);
    NettyClient nettyClient1 = objectPool.borrowObject();
    NettyClient nettyClient2 = objectPool.borrowObject();
    waitConditionUntilTimeOut(() -> echoServer.getConnected() == 2);
    objectPool.returnObject(nettyClient1);
    objectPool.returnObject(nettyClient2);
    waitConditionUntilTimeOut(() -> echoServer.getConnected() == 0, 60000);
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) Server(com.ctrip.xpipe.simpleserver.Server) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 9 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.

the class XpipeNettyClientKeyedObjectPoolTest method testKeyPoolReuse.

@Test
public void testKeyPoolReuse() throws Exception {
    Server echoServer = startEchoServer();
    InetSocketAddress key = new InetSocketAddress("localhost", echoServer.getPort());
    Assert.assertEquals(0, echoServer.getConnected());
    SimpleObjectPool<NettyClient> objectPool = pool.getKeyPool(key);
    for (int i = 0; i < testCount; i++) {
        NettyClient client = objectPool.borrowObject();
        sleep(10);
        Assert.assertEquals(1, echoServer.getTotalConnected());
        objectPool.returnObject(client);
    }
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) Server(com.ctrip.xpipe.simpleserver.Server) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 10 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.

the class XpipeNettyClientKeyedObjectPool method borrowObject.

@Override
public NettyClient borrowObject(InetSocketAddress key) throws BorrowObjectException {
    try {
        logger.debug("[borrowObject][begin]{}", key);
        NettyClient value = this.objectPool.borrowObject(key);
        logger.debug("[borrowObject][end]{}, {}", key, value);
        return value;
    } catch (Exception e) {
        logger.error("[borrowObject]" + key, e);
        throw new BorrowObjectException("borrow " + key, e);
    }
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) ObjectPoolException(com.ctrip.xpipe.api.pool.ObjectPoolException)

Aggregations

NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)37 InetSocketAddress (java.net.InetSocketAddress)31 Test (org.junit.Test)8 ExecutionException (java.util.concurrent.ExecutionException)6 AbstractTest (com.ctrip.xpipe.AbstractTest)4 InfoCommand (com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand)4 Server (com.ctrip.xpipe.simpleserver.Server)4 IOException (java.io.IOException)4 CommandExecutionException (com.ctrip.xpipe.command.CommandExecutionException)3 SequenceCommandChain (com.ctrip.xpipe.command.SequenceCommandChain)3 FixedObjectPool (com.ctrip.xpipe.pool.FixedObjectPool)3 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)3 AbstractSentinelCommand (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand)3 Replconf (com.ctrip.xpipe.redis.core.protocal.cmd.Replconf)3 DefaultEndPoint (com.ctrip.xpipe.endpoint.DefaultEndPoint)2 XpipeException (com.ctrip.xpipe.exception.XpipeException)2 NettyClientFactory (com.ctrip.xpipe.netty.commands.NettyClientFactory)2 XpipeObjectPoolFromKeyed (com.ctrip.xpipe.pool.XpipeObjectPoolFromKeyed)2 DefaultSlaveOfCommand (com.ctrip.xpipe.redis.core.protocal.cmd.DefaultSlaveOfCommand)2 InMemoryPsync (com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync)2