@Override public Observable<InstanceInfo> forSnapshot(final Interest<InstanceInfo> interest, final Source.SourceMatcher sourceMatcher) { return forSnapshot(interest).filter(new Func1<InstanceInfo, Boolean>() { @Override public Boolean call(InstanceInfo instanceInfo) { MultiSourcedDataHolder<InstanceInfo> holder = internalStore.get(instanceInfo.getId()); return holder != null && sourceMatcher.match(holder.getSource()); } }); }
@Override public String toString() { return prettyString(); }
@Override protected EurekaInterestClient buildClient() { if (serverResolver == null) { throw new IllegalArgumentException("Cannot build client for discovery without read server resolver"); } if(clientId == null) { clientId = INTEREST_CLIENT_ID; } BatchingRegistry<InstanceInfo> remoteBatchingRegistry = new BatchingRegistryImpl<>(); BatchAwareIndexRegistry<InstanceInfo> indexRegistry = new BatchAwareIndexRegistry<>( new IndexRegistryImpl<InstanceInfo>(), remoteBatchingRegistry); PreservableEurekaRegistry registry = new PreservableEurekaRegistry( new SourcedEurekaRegistryImpl(indexRegistry, registryMetricFactory), registryConfig, registryMetricFactory); ClientChannelFactory<InterestChannel> channelFactory = new InterestChannelFactory(clientId, transportConfig, serverResolver, registry, remoteBatchingRegistry, clientMetricFactory); return new EurekaInterestClientImpl(registry, channelFactory); } }
@Override public Observable<Boolean> unregister(final InstanceInfo instanceInfo, final Source source) { final MultiSourcedDataHolder<InstanceInfo> currentHolder = internalStore.get(instanceInfo.getId()); if (currentHolder == null) { return Observable.just(false); } Observable<MultiSourcedDataHolder.Status> result = currentHolder.remove(source).doOnNext(new Action1<MultiSourcedDataHolder.Status>() { @Override public void call(MultiSourcedDataHolder.Status status) { if (status != MultiSourcedDataHolder.Status.RemoveExpired) { metrics.incrementUnregistrationCounter(source.getOrigin()); } } }); return subscribeToUpdateResult(result); }
@Override public Observable<ChangeNotification<InstanceInfo>> forInterest(Interest<InstanceInfo> interest, final Source.SourceMatcher sourceMatcher) { return forInterest(interest).filter(new Func1<ChangeNotification<InstanceInfo>, Boolean>() { @Override public Boolean call(ChangeNotification<InstanceInfo> changeNotification) { if (changeNotification instanceof Sourced) { Source notificationSource = ((Sourced) changeNotification).getSource(); return sourceMatcher.match(notificationSource); } else if (changeNotification instanceof StreamStateNotification) { return false; } else { logger.warn("Received notification without a source, {}", changeNotification); return false; } } }); }
@Override public Observable<Long> evictAllExcept(final Source.SourceMatcher retainMatcher) { return getHolders() .doOnNext(new Action1<MultiSourcedDataHolder<InstanceInfo>>() { @Override public void call(MultiSourcedDataHolder<InstanceInfo> holder) { for (Source source : holder.getAllSources()) { if (!retainMatcher.match(source)) { holder.remove(source).subscribe(new NoOpSubscriber<MultiSourcedDataHolder.Status>()); } } } }) .countLong() .doOnError(new Action1<Throwable>() { @Override public void call(Throwable throwable) { logger.error("Error evicting registry", throwable); } }) .doOnCompleted(new Action0() { @Override public void call() { logger.info("Completed evicting registry"); } }); }
/** * Return an observable of all matching InstanceInfo for the current registry snapshot, * as {@link ChangeNotification}s * @param interest * @return an observable of all matching InstanceInfo for the current registry snapshot, * as {@link ChangeNotification}s */ @Override public Observable<ChangeNotification<InstanceInfo>> forInterest(Interest<InstanceInfo> interest) { try { // TODO: this method can be run concurrently from different channels, unless we run everything on single server event loop. // It is possible that the same instanceinfo will be both in snapshot and paused notification queue. pauseableSubject.pause(); // Pause notifications till we get a snapshot of current registry (registry.values()) if (interest instanceof MultipleInterests) { return indexRegistry.forCompositeInterest((MultipleInterests) interest, this); } else { return indexRegistry.forInterest(interest, pauseableSubject, new InstanceInfoInitStateHolder(getSnapshotForInterest(interest), interest)); } } finally { pauseableSubject.resume(); } }
new SourcedEurekaRegistryImpl(indexRegistry, registryMetrics()), registryConfig, registryMetrics()
@Override public Observable<Boolean> register(final InstanceInfo instanceInfo, final Source source) { MultiSourcedDataHolder<InstanceInfo> holder = new NotifyingInstanceInfoHolder( internalStoreAccessor, pauseableSubject, invoker, instanceInfo.getId()); Observable<MultiSourcedDataHolder.Status> result = holder.update(source, instanceInfo).doOnNext(new Action1<MultiSourcedDataHolder.Status>() { @Override public void call(MultiSourcedDataHolder.Status status) { if (status != MultiSourcedDataHolder.Status.AddExpired) { metrics.incrementRegistrationCounter(source.getOrigin()); } } }); return subscribeToUpdateResult(result); }