Search in sources :

Example 1 with Endpoint

use of com.ctrip.xpipe.api.endpoint.Endpoint in project x-pipe by ctripcorp.

the class RedisFakeSlaveTest method startKeeperCreateReplicationLogClient.

private void startKeeperCreateReplicationLogClient() throws UnknownHostException, IOException {
    try {
        Endpoint endpoint = new DefaultEndPoint(redisMasterUri);
        socket = new Socket(endpoint.getHost(), endpoint.getPort());
        if (logger.isInfoEnabled()) {
            logger.info("[startKeeperClient]" + socket);
        }
        final OutputStream ous = socket.getOutputStream();
        InputStream ins = socket.getInputStream();
        ous.write(("replconf listening-port " + fakeSlavePort + "\r\n").getBytes());
        ous.flush();
        readLine(ins);
        ous.write("fsync\r\n".getBytes());
        ous.flush();
        readLine(ins);
        scheduled.scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                try {
                    ous.write("replconf ack 0\r\n".getBytes());
                    ous.flush();
                } catch (IOException e) {
                    closeSocket();
                    logger.error("[run]", e);
                }
            }
        }, 0, 1, TimeUnit.SECONDS);
    } catch (IOException e) {
        closeSocket();
        logger.error("[startKeeperCreateReplicationLogClient]" + socket, e);
    }
}
Also used : Endpoint(com.ctrip.xpipe.api.endpoint.Endpoint) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) DefaultEndPoint(com.ctrip.xpipe.endpoint.DefaultEndPoint) IOException(java.io.IOException) Socket(java.net.Socket)

Example 2 with Endpoint

use of com.ctrip.xpipe.api.endpoint.Endpoint in project x-pipe by ctripcorp.

the class DefaultPsyncTest method beforeDefaultPsyncTest.

@Before
public void beforeDefaultPsyncTest() throws Exception {
    FakeRedisServer fakeRedisServer = startFakeRedisServer();
    Endpoint masterEndPoint = new DefaultEndPoint("localhost", fakeRedisServer.getPort());
    SimpleObjectPool<NettyClient> pool = NettyPoolUtil.createNettyPool(new InetSocketAddress("localhost", fakeRedisServer.getPort()));
    when(replicationStoreManager.createIfNotExist()).thenReturn(replicationStore);
    when(replicationStore.getMetaStore()).thenReturn(metaStore);
    when(metaStore.getReplId()).thenReturn("?");
    when(replicationStore.getEndOffset()).thenReturn(-1L);
    defaultPsync = new DefaultPsync(pool, masterEndPoint, replicationStoreManager, scheduled);
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) Endpoint(com.ctrip.xpipe.api.endpoint.Endpoint) InetSocketAddress(java.net.InetSocketAddress) DefaultEndPoint(com.ctrip.xpipe.endpoint.DefaultEndPoint) FakeRedisServer(com.ctrip.xpipe.redis.core.server.FakeRedisServer) Before(org.junit.Before)

Example 3 with Endpoint

use of com.ctrip.xpipe.api.endpoint.Endpoint in project x-pipe by ctripcorp.

the class DefaultEndPointTest method testEndPoint.

@Test
public void testEndPoint() {
    String url = "redis://:password@10.2.58.242:6379";
    Endpoint endpoint = new DefaultEndPoint(url);
    Assert.assertEquals("redis", endpoint.getScheme());
    Assert.assertEquals("", endpoint.getUser());
    Assert.assertEquals("password", endpoint.getPassword());
    Assert.assertEquals("10.2.58.242", endpoint.getHost());
    Assert.assertEquals(6379, endpoint.getPort());
}
Also used : Endpoint(com.ctrip.xpipe.api.endpoint.Endpoint) Test(org.junit.Test)

Example 4 with Endpoint

use of com.ctrip.xpipe.api.endpoint.Endpoint in project x-pipe by ctripcorp.

the class AbstractRedisMasterReplication method tryConnect.

protected ChannelFuture tryConnect(Bootstrap b) {
    Endpoint endpoint = redisMaster.masterEndPoint();
    logger.info("[tryConnect][begin]{}", endpoint);
    return b.connect(endpoint.getHost(), endpoint.getPort());
}
Also used : Endpoint(com.ctrip.xpipe.api.endpoint.Endpoint)

Example 5 with Endpoint

use of com.ctrip.xpipe.api.endpoint.Endpoint in project x-pipe by ctripcorp.

the class DefaultRedisKeeperServer method reconnectMaster.

@Override
public synchronized void reconnectMaster() {
    Endpoint target = redisKeeperServerState.getMaster();
    logger.info("[reconnectMaster]{} -> {}", this, target);
    if (keeperRedisMaster != null && target != null && keeperRedisMaster.getLifecycleState().isStarted()) {
        Endpoint current = keeperRedisMaster.masterEndPoint();
        if (current != null && current.getHost().equals(target.getHost()) && current.getPort() == target.getPort()) {
            logger.info("[reconnectMaster][master the same]{},{}", current, target);
            return;
        }
    }
    stopAndDisposeMaster();
    if (target == null) {
        logger.info("[reconnectMaster][target null][close master connection]{}, {}", this, redisKeeperServerState);
        return;
    }
    initAndStartMaster(target);
}
Also used : Endpoint(com.ctrip.xpipe.api.endpoint.Endpoint)

Aggregations

Endpoint (com.ctrip.xpipe.api.endpoint.Endpoint)6 DefaultEndPoint (com.ctrip.xpipe.endpoint.DefaultEndPoint)2 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)1 FakeRedisServer (com.ctrip.xpipe.redis.core.server.FakeRedisServer)1 ReplicationStore (com.ctrip.xpipe.redis.core.store.ReplicationStore)1 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)1 RedisMaster (com.ctrip.xpipe.redis.keeper.RedisMaster)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1 Before (org.junit.Before)1 Test (org.junit.Test)1