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