private static Optional<LeaderFinder<URIMetadata>> getLeaderFinder(Config config) throws URISyntaxException, IOException { if (config.hasPath(ZK_STRING_KEY)) { Preconditions.checkArgument(config.hasPath(LISTENING_PORT), "Missing required config " + LISTENING_PORT); Preconditions.checkArgument(config.hasPath(HA_CLUSTER_NAME), "Missing required config " + HA_CLUSTER_NAME); int port = config.getInt(LISTENING_PORT); String hostname = config.hasPath(HOSTNAME) ? config.getString(HOSTNAME) : InetAddress.getLocalHost().getCanonicalHostName(); String clusterName = config.getString(HA_CLUSTER_NAME); String zkString = config.getString(ZK_STRING_KEY); return Optional.<LeaderFinder<URIMetadata>>of(new ZookeeperLeaderElection<>(zkString, clusterName, new URIMetadata(new URI("http", null, hostname, port, null, null, null)))); } return Optional.absent(); }
private static Optional<LeaderFinder<URIMetadata>> getLeaderFinder(Config config) throws URISyntaxException, IOException { if (config.hasPath(ZK_STRING_KEY)) { Preconditions.checkArgument(config.hasPath(LISTENING_PORT), "Missing required config " + LISTENING_PORT); Preconditions.checkArgument(config.hasPath(HA_CLUSTER_NAME), "Missing required config " + HA_CLUSTER_NAME); int port = config.getInt(LISTENING_PORT); String hostname = config.hasPath(HOSTNAME) ? config.getString(HOSTNAME) : InetAddress.getLocalHost().getCanonicalHostName(); String clusterName = config.getString(HA_CLUSTER_NAME); String zkString = config.getString(ZK_STRING_KEY); return Optional.<LeaderFinder<URIMetadata>>of(new ZookeeperLeaderElection<>(zkString, clusterName, new URIMetadata(new URI("http", null, hostname, port, null, null, null)))); } return Optional.absent(); }