Search in sources :

Example 31 with NettyClient

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

the class AbstractRedisTest method getInfoKey.

protected String getInfoKey(RedisMeta slaveMeta, String infoSection, String key) throws Exception {
    SimpleObjectPool<NettyClient> keyPool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress(slaveMeta.getIp(), slaveMeta.getPort()));
    String info = new InfoCommand(keyPool, infoSection, scheduled).execute().get();
    return new InfoResultExtractor(info).extract(key);
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) InfoResultExtractor(com.ctrip.xpipe.redis.core.protocal.cmd.InfoResultExtractor) InetSocketAddress(java.net.InetSocketAddress) InfoCommand(com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand)

Example 32 with NettyClient

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

the class AbstractRedisTest method getRedisServerRole.

protected SERVER_ROLE getRedisServerRole(RedisMeta slave) throws Exception {
    SimpleObjectPool<NettyClient> clientPool = NettyPoolUtil.createNettyPool(new InetSocketAddress(slave.getIp(), slave.getPort()));
    String info = new InfoCommand(clientPool, "replication", scheduled).execute().get();
    for (String line : info.split("\r\n")) {
        String[] parts = line.split(":");
        if (parts.length >= 2 && parts[0].equals("role")) {
            String role = parts[1].trim();
            return SERVER_ROLE.of(role);
        }
    }
    return SERVER_ROLE.UNKNOWN;
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) InetSocketAddress(java.net.InetSocketAddress) InfoCommand(com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand)

Example 33 with NettyClient

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

the class RedisSlaveReplAllTest method slaveWritable.

private void slaveWritable(List<RedisMeta> redises) {
    redises.forEach((redis) -> {
        try {
            logger.info("{} readonly no", redis.desc());
            SimpleObjectPool<NettyClient> keyPool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress(redis.getIp(), redis.getPort()));
            new ConfigSetCommand.ConfigSetSlaveReadOnly(false, keyPool, scheduled).execute().get();
        } catch (Exception e) {
            logger.error("[slaveWritable]" + redis.desc(), e);
        }
    });
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException)

Example 34 with NettyClient

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

the class XpipeNettyClientKeyedObjectPoolTest method testSingleReuse.

@Test
public void testSingleReuse() throws Exception {
    Server echoServer = startEchoServer();
    Assert.assertEquals(0, echoServer.getTotalConnected());
    for (int i = 0; i < testCount; i++) {
        InetSocketAddress key = new InetSocketAddress("localhost", echoServer.getPort());
        NettyClient client = pool.borrowObject(key);
        sleep(10);
        Assert.assertEquals(1, echoServer.getTotalConnected());
        pool.returnObject(key, 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 35 with NettyClient

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

the class XpipeNettyClientKeyedObjectPool method doInitialize.

@Override
protected void doInitialize() throws Exception {
    this.pooledObjectFactory = new NettyKeyedPoolClientFactory();
    pooledObjectFactory.start();
    GenericKeyedObjectPool<InetSocketAddress, NettyClient> genericKeyedObjectPool = new GenericKeyedObjectPool<>(pooledObjectFactory, config);
    genericKeyedObjectPool.setTestOnBorrow(true);
    genericKeyedObjectPool.setTestOnCreate(true);
    genericKeyedObjectPool.setSoftMinEvictableIdleTimeMillis(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    genericKeyedObjectPool.setMinEvictableIdleTimeMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    genericKeyedObjectPool.setTimeBetweenEvictionRunsMillis(DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
    this.objectPool = genericKeyedObjectPool;
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) NettyKeyedPoolClientFactory(com.ctrip.xpipe.netty.commands.NettyKeyedPoolClientFactory) GenericKeyedObjectPool(org.apache.commons.pool2.impl.GenericKeyedObjectPool) InetSocketAddress(java.net.InetSocketAddress)

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