コード例 #1
0
  @Override
  public void stop() {
    super.stop();

    for (RedisConnection conn : connections) {
      conn.stop();
    }
  }
コード例 #2
0
  public void reconnect() {
    List<RedisConnection> newConnections = new ArrayList<RedisConnection>();

    for (String host : REDIS_HOST.get().trim().split("\\s*,\\s*")) {
      String[] parts = host.split(":");
      if (parts.length > 2) {
        throw new IllegalArgumentException(
            "Invalid redis host [" + host + "] should be in host:port format");
      }

      String hostName = parts[0];
      int port = Protocol.DEFAULT_PORT;

      if (parts.length > 1) {
        try {
          port = Integer.parseInt(parts[1]);
        } catch (NumberFormatException e) {
          throw new IllegalArgumentException(
              "Invalid redis host [" + host + "] should be in host:port format", e);
        }
      }

      newConnections.add(new RedisConnection(this, hostName, port));
    }

    List<RedisConnection> oldConnections = connections;
    connections = newConnections;

    for (RedisConnection conn : newConnections) {
      getExecutorService().submit(conn);
    }

    for (RedisConnection conn : oldConnections) {
      conn.stop();
    }
  }