public ServerResolver interestResolver() { return ServerResolvers.fromServerSource(clusterChangeObservable()); }
private ServerResolver getServerResolver(final Func1<ClusterAddress, Integer> portFunc) { Observable<ChangeNotification<Server>> serverSource = clusterChangeObservable().map(new Func1<ChangeNotification<ClusterAddress>, ChangeNotification<Server>>() { @Override public ChangeNotification<Server> call(ChangeNotification<ClusterAddress> notification) { if (notification.getKind() == Kind.BufferSentinel) { return ChangeNotification.bufferSentinel(); } ClusterAddress endpoints = notification.getData(); int port = portFunc.call(endpoints); switch (notification.getKind()) { case Add: return new ChangeNotification<>(Kind.Add, new Server(endpoints.getHostName(), port)); case Modify: throw new IllegalStateException("Modify not expected"); case Delete: return new ChangeNotification<>(Kind.Delete, new Server(endpoints.getHostName(), port)); default: //no-op } return null; } }).filter(RxFunctions.filterNullValuesFunc()); return ServerResolvers.fromServerSource(serverSource); }
ServerResolver resolver = ServerResolvers.fromServerSource( instanceInfoSource.map(InterestFunctions.instanceInfoToServer(serviceSelector)) );