private static Observable<ChangeNotification<InetSocketAddress>> fromList(ServerBootstrap[] bootstraps) { List<ChangeNotification<InetSocketAddress>> addresses = new ArrayList<>(bootstraps.length); for (ServerBootstrap sb : bootstraps) { addresses.add(new ChangeNotification<>( Kind.Add, new InetSocketAddress(sb.getHostname(), sb.getReplicationPort())) ); } return Observable.from(addresses); } }
private static Observable<ChangeNotification<InetSocketAddress>> fromDns(ServerBootstrap[] bootstraps) { List<Observable<ChangeNotification<InetSocketAddress>>> addresses = new ArrayList<>(bootstraps.length); for (final ServerBootstrap sb : bootstraps) { Observable<ChangeNotification<InetSocketAddress>> stream = new DnsChangeNotificationSource(sb.getHostname()) .forInterest(null) .map(new Func1<ChangeNotification<String>, ChangeNotification<InetSocketAddress>>() { @Override public ChangeNotification<InetSocketAddress> call(ChangeNotification<String> notification) { return new ChangeNotification<>( notification.getKind(), new InetSocketAddress(notification.getData(), sb.getReplicationPort()) ); } }); addresses.add(stream); } return Observable.merge(addresses); }
private static ServerResolver forDNS(ServerBootstrap[] bootstraps) { if (bootstraps.length != 1) { throw new IllegalArgumentException("Expected one DNS name for server resolver, while got " + bootstraps.length); } return ServerResolvers.forDnsName(bootstraps[0].getHostname(), bootstraps[0].getDiscoveryPort()); }
private static ServerResolver forDNS(ServerBootstrap[] bootstraps, Func1<ServerBootstrap, Integer> getPortFunc) { if (bootstraps.length != 1) { throw new IllegalArgumentException("Expected one DNS name for server resolver, while got " + bootstraps.length); } return ServerResolvers.forDnsName(bootstraps[0].getHostname(), getPortFunc.call(bootstraps[0])); }
private static ServerResolver forFixed(ServerBootstrap[] bootstraps, Func1<ServerBootstrap, Integer> getPortFunc) { Server[] servers = new Server[bootstraps.length]; for (int i = 0; i < bootstraps.length; i++) { servers[i] = new Server(bootstraps[i].getHostname(), getPortFunc.call(bootstraps[i])); } return ServerResolvers.from(servers); } }
private static ServerResolver forFixed(ServerBootstrap[] bootstraps) { Server[] servers = new Server[bootstraps.length]; for (int i = 0; i < bootstraps.length; i++) { servers[i] = new Server(bootstraps[i].getHostname(), bootstraps[i].getDiscoveryPort()); } return ServerResolvers.from(servers); } }