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);
}
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;
}
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);
}
});
}
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);
}
}
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;
}
Aggregations