Package redis.clients.jedis

Examples of redis.clients.jedis.HostAndPort


    private void waitForJedisSentinelPoolRecognizeNewMaster(
      JedisSentinelPool pool, HostAndPort newMaster)
      throws InterruptedException {

  while (true) {
      HostAndPort currentHostMaster = pool.getCurrentHostMaster();

      if (newMaster.equals(currentHostMaster))
    break;

      System.out
View Full Code Here


    commandJedis.sentinelFailover(masterName);
      }
  }, "*");

  String[] chunks = newmaster.get().split(" ");
  HostAndPort newMaster = new HostAndPort(chunks[3],
    Integer.parseInt(chunks[4]));

  return newMaster;
    }
View Full Code Here

    }

    @Test
    public void testParseNodeMyself() {
  String nodeInfo = "9b0d2ab38ee31482c95fdb2c7847a0d40e88d518 :7379 myself,master - 0 0 1 connected 0-5460";
  HostAndPort current = new HostAndPort("localhost", 7379);
  ClusterNodeInformation clusterNodeInfo = parser
    .parse(nodeInfo, current);
  assertEquals(clusterNodeInfo.getNode(), current);
    }
View Full Code Here

    }

    @Test
    public void testParseNormalState() {
  String nodeInfo = "5f4a2236d00008fba7ac0dd24b95762b446767bd 192.168.0.3:7380 master - 0 1400598804016 2 connected 5461-10922";
  HostAndPort current = new HostAndPort("localhost", 7379);
  ClusterNodeInformation clusterNodeInfo = parser
    .parse(nodeInfo, current);
  assertNotEquals(clusterNodeInfo.getNode(), current);
  assertEquals(clusterNodeInfo.getNode(), new HostAndPort("192.168.0.3",
    7380));

  for (int slot = 5461; slot <= 10922; slot++) {
      assertTrue(clusterNodeInfo.getAvailableSlots().contains(slot));
  }
View Full Code Here

    }

    @Test
    public void testParseSlotBeingMigrated() {
  String nodeInfo = "5f4a2236d00008fba7ac0dd24b95762b446767bd :7379 myself,master - 0 0 1 connected 0-5459 [5460->-5f4a2236d00008fba7ac0dd24b95762b446767bd] [5461-<-5f4a2236d00008fba7ac0dd24b95762b446767bd]";
  HostAndPort current = new HostAndPort("localhost", 7379);
  ClusterNodeInformation clusterNodeInfo = parser
    .parse(nodeInfo, current);
  assertEquals(clusterNodeInfo.getNode(), current);

  for (int slot = 0; slot <= 5459; slot++) {
View Full Code Here

    public static final int HOST_AND_PORT_INDEX = 1;

    public ClusterNodeInformation parse(String nodeInfo, HostAndPort current) {
  String[] nodeInfoPartArray = nodeInfo.split(" ");

  HostAndPort node = getHostAndPortFromNodeLine(nodeInfoPartArray,
    current);
  ClusterNodeInformation info = new ClusterNodeInformation(node);

  if (nodeInfoPartArray.length >= SLOT_INFORMATIONS_START_INDEX) {
      String[] slotInfoPartArray = extractSlotParts(nodeInfoPartArray);
View Full Code Here

    public HostAndPort getHostAndPortFromNodeLine(String[] nodeInfoPartArray,
      HostAndPort current) {
  String stringHostAndPort = nodeInfoPartArray[HOST_AND_PORT_INDEX];

  String[] arrayHostAndPort = stringHostAndPort.split(":");
  return new HostAndPort(
    arrayHostAndPort[0].isEmpty() ? current.getHost()
      : arrayHostAndPort[0],
    arrayHostAndPort[1].isEmpty() ? current.getPort() : Integer
      .valueOf(arrayHostAndPort[1]));
    }
View Full Code Here

        try {
          sentinelPool = pickupSentinel();

          if (sentinelPool != null) {

            HostAndPort masterAddress = queryMasterAddress();

            if ((internalPool != null) && isAddressChange(masterAddress)) {
              logger.info("The internalPool {} had changed, destroy it now.", previousMasterAddress);
              destroyInternelPool();
            }

            if (internalPool == null) {
              logger.info("The internalPool {} is not init or the address had changed, init it now.",
                  masterAddress);
              initInternalPool(masterAddress, masterConnectionInfo, masterPoolConfig);
              poolInit.countDown();
            }

            previousMasterAddress = masterAddress;

            sentinelJedis = sentinelPool.getResource();
            subscriber = new MasterSwitchSubscriber();
            sentinelJedis.subscribe(subscriber, "+switch-master", "+redirect-to-master");
          } else {
            logger.info("All sentinels down, sleep 2 seconds and try to connect again.");
            // When the system startup but the sentinels not yet, init a urgly address to prevent null point
            // exception. change the logic later.
            if (internalPool == null) {
              HostAndPort masterAddress = new HostAndPort(NO_ADDRESS_YET, 6379);
              initInternalPool(masterAddress, masterConnectionInfo, masterPoolConfig);
              previousMasterAddress = masterAddress;
            }
            sleep(2000);
          }
View Full Code Here

      if ((address == null) || address.isEmpty()) {
        throw new IllegalArgumentException("Master name " + masterName + " is not in sentinel.conf");
      }

      return new HostAndPort(address.get(0), Integer.valueOf(address.get(1)));
    }
View Full Code Here

        logger.info("Sentinel " + sentinelPool.getAddress() + " published: " + message);
        String[] switchMasterMsg = message.split(" ");
        // if the master name equals my master name, destroy the old pool and init a new pool
        if (masterName.equals(switchMasterMsg[0])) {

          HostAndPort masterAddress = new HostAndPort(switchMasterMsg[3],
              Integer.parseInt(switchMasterMsg[4]));
          logger.info("Switch master to " + masterAddress);
          destroyInternelPool();
          initInternalPool(masterAddress, masterConnectionInfo, masterPoolConfig);
          previousMasterAddress = masterAddress;
View Full Code Here

TOP

Related Classes of redis.clients.jedis.HostAndPort

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.