@Override public Observable<ChangeNotification<InstanceInfo>> forInterest(Interest<InstanceInfo> interest) { return eurekaRegistry.forInterest(interest); }
@Override public Observable<Boolean> register(final InstanceInfo instanceInfo, final Source source) { Observable<Boolean> result = eurekaRegistry.register(instanceInfo, source); result.subscribe(increaseExpectedSize); return result; }
@Override public Observable<Boolean> unregister(InstanceInfo instanceInfo, Source source) { Observable<Boolean> result = eurekaRegistry.unregister(instanceInfo, source); result.subscribe(decreaseExpectedSize); return result; }
@Override public void onNext(ChangeNotification<InstanceInfo> notification) { switch (notification.getKind()) { // these are in-mem blocking ops case Add: case Modify: registry.register(notification.getData(), selfSource); break; case Delete: registry.unregister(notification.getData(), selfSource); break; case BufferSentinel: // No-op break; default: logger.error("Unrecognized notification kind"); } } });
@Override public int size() { return eurekaRegistry.size(); }
@PreDestroy @Override public Observable<Void> shutdown() { moveHealthTo(Status.DOWN); logger.info("Shutting down the preservable registry"); evictionSubscription.unsubscribe(); evictionQueue.shutdown(); return eurekaRegistry.shutdown(); }
@Override public Observable<InstanceInfo> forSnapshot(Interest<InstanceInfo> interest) { return eurekaRegistry.forSnapshot(interest); }
InstanceInfo older = currentSnapshot.get(instanceInfo.getId()); if (!older.equals(instanceInfo)) { registry.register(instanceInfo, selfSource); updateCount.incrementAndGet(); registry.register(instanceInfo, selfSource); registerCount.incrementAndGet(); registry.unregister(instanceInfo, selfSource); unregisterCount.incrementAndGet();
@Override public void call(Boolean status) { if (status) { expectedRegistrySize = Math.max(expectedRegistrySize, eurekaRegistry.size()); resumeEviction(); } } };
@Override public Observable<Void> shutdown(Throwable cause) { moveHealthTo(Status.DOWN); evictionSubscription.unsubscribe(); evictionQueue.shutdown(); return eurekaRegistry.shutdown(cause); }
@Override public Observable<InstanceInfo> forSnapshot(Interest<InstanceInfo> interest, Source.SourceMatcher sourceMatcher) { return eurekaRegistry.forSnapshot(interest, sourceMatcher); }
@Override public Observable<ChangeNotification<InstanceInfo>> forInterest(Interest<InstanceInfo> interest, Source.SourceMatcher sourceMatcher) { return eurekaRegistry.forInterest(interest, sourceMatcher); }
return registry.unregister(toUnregister, replicationSource) .map(new Func1<Boolean, Void>() { @Override
return registry.register(instanceInfo, replicationSource) .map(new Func1<Boolean, Void>() { @Override
/** * FIXME eviction strategies need a rethink * >= 0 as when both sizes are equal, we still allow eviction to happen as they may be stale copies */ private boolean allowedToEvict() { boolean allowed = evictionStrategy.allowedToEvict(expectedRegistrySize, eurekaRegistry.size()) >= 0; // TODO We decided that self preservation should not trigger component DOWN transition. Health check from PreservableEurekaRegistry might be not needed // moveHealthTo(allowed ? Status.UP : Status.DOWN); return allowed; }
@Override public void shutdown() { if (isShutdown.compareAndSet(false, true)) { logger.info("Shutting down InterestClient"); if (getRetryableConnection() != null) { getRetryableConnection().close(); } registry.shutdown(); } }
private void loadUpdatesFromV1Registry() { logger.info("Starting new round of replication from v1 to v2"); registry.forSnapshot(Interests.forFullRegistry(), Source.matcherFor(Source.Origin.LOCAL)) .filter(new Func1<InstanceInfo, Boolean>() { // filter self so it's not take into account @Override public Boolean call(InstanceInfo instanceInfo) { return !instanceInfo.getId().equals(self.getId()); } }) .toMap(new Func1<InstanceInfo, String>() { @Override public String call(InstanceInfo instanceInfo) { return instanceInfo.getId(); } }) .subscribe(new Subscriber<Map<String, InstanceInfo>>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { logger.warn("Error generating snapshot of registry", e); } @Override public void onNext(Map<String, InstanceInfo> currentSnapshot) { diff(currentSnapshot); } }); }
@Override protected void before() throws Throwable { when(registry.forInterest(any(Interest.class))).thenAnswer(new Answer<Observable<ChangeNotification<InstanceInfo>>>() { @Override public Observable<ChangeNotification<InstanceInfo>> answer(InvocationOnMock invocation) throws Throwable { return getInterestSubject((Interest) invocation.getArguments()[0]); } }); fullRegistrySubject = ReplaySubject.create(); }
@Override public void onNext(final EvictionItem evictionItem) { eurekaRegistry.unregister(evictionItem.getInstanceInfo(), evictionItem.getSource()) .doOnCompleted(new Action0() { @Override public void call() { logger.info("Successfully evicted registry entry {}/{}", evictionItem.getSource(), evictionItem.getInstanceInfo().getId()); } }) .retry(2) .subscribe(); if (allowedToEvict()) { resume(); } else { selfPreservation.set(true); metrics.setSelfPreservation(true); logger.info("Entering self preservation mode"); } }
return registry.register(instanceInfo, selfSource) .ignoreElements() .cast(Void.class)