@Inject public EurekaWriteServerSelfRegistrationService(SelfInfoResolver resolver, SourcedEurekaRegistry registry) { super(resolver); this.registry = registry; this.selfSource = new Source(Source.Origin.LOCAL); }
@Override public boolean match(Source another) { return (source == null) ? (another == null) : source.equals(another); } };
/** * Matches sources on origin:name:id. * - If a matching source already exist in the sourceMap, and has the same id as the input source, do removal * - If a matching source already exist in the sourceMap, but have a different id as the input source, no-op * - Otherwise, no-op */ public InstanceInfo remove(Source source) { String sourceKey = sourceKey(source); Source currIfExist = sourceMap.get(sourceKey); if (currIfExist != null) { if (currIfExist.getId().equals(source.getId())) { sourceMap.remove(sourceKey); return dataMap.remove(currIfExist); } else { // no-op return null; } } else { // no-op return null; } }
/** * @return true if the two sources have the same origin and name. Don't use a matcher from source * to avoid the object creation. */ private boolean matches(Source one, Source two) { if (one != null && two != null) { boolean originMatches = (one.getOrigin() == two.getOrigin()); boolean nameMatches = (one.getName() == null) ? (two.getName() == null) : one.getName().equals(two.getName()); return originMatches && nameMatches; } else { return one == null && two == null; } }
@Override public Observable<Void> call(final ReplicationChannel channel) { return registry.forInterest(Interests.forFullRegistry(), Source.matcherFor(Source.Origin.LOCAL)) .flatMap(new Func1<ChangeNotification<InstanceInfo>, Observable<Void>>() {// TODO concatMap once backpressure is properly working @Override public Observable<Void> call(ChangeNotification<InstanceInfo> notification) { switch (notification.getKind()) { case Add: return channel.register(notification.getData()); case Modify: return channel.register(notification.getData()); case Delete: return channel.unregister(notification.getData().getId()); default: logger.warn("Unrecognised notification kind {}", notification); return Observable.empty(); } } }); } }
@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 int hashCode() { int result = super.hashCode(); result = 31 * result + (source != null ? source.hashCode() : 0); return result; } }
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 public int hashCode() { int result = super.hashCode(); result = 31 * result + (source != null ? source.hashCode() : 0); return result; } }
public InterestChannelImpl(final SourcedEurekaRegistry<InstanceInfo> registry, BatchingRegistry<InstanceInfo> remoteBatchingRegistry, TransportClient client, InterestChannelMetrics metrics) { super(STATE.Idle, client, metrics); this.remoteBatchingRegistry = remoteBatchingRegistry; this.selfSource = new Source(Source.Origin.INTERESTED); this.registry = registry; channelInterestSubscriber = new ChannelInterestSubscriber(registry); channelInterestStream = createInterestStream(); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof SourcedChangeNotification)) return false; if (!super.equals(o)) return false; SourcedChangeNotification that = (SourcedChangeNotification) o; if (source != null ? !source.equals(that.source) : that.source != null) return false; return true; }
pauseableSubject.onNext(newSnapshot.getNotification()); result = Status.AddedFirst; } else if ((currSnapshot.getSource().getOrigin() != Source.Origin.LOCAL) && (source.getOrigin() == Source.Origin.LOCAL)) { // promote new update from local to snapshot snapshot = newSnapshot; pauseableSubject.onNext(newSnapshot.getNotification());
@Override public Observable<ReplicationHelloReply> hello(final ReplicationHello hello) { logger.debug("Replication hello message: {}", hello); if(!moveToState(STATE.Idle, STATE.Handshake)) { return Observable.error(state.get() == STATE.Closed ? CHANNEL_CLOSED_EXCEPTION : HANDSHAKE_FINISHED_EXCEPTION); } replicationSource = new Source(Source.Origin.REPLICATED, hello.getSourceId()); return selfIdentityService.resolve().take(1).flatMap(new Func1<InstanceInfo, Observable<ReplicationHelloReply>>() { @Override public Observable<ReplicationHelloReply> call(InstanceInfo instanceInfo) { replicationLoop = instanceInfo.getId().equals(hello.getSourceId()); ReplicationHelloReply reply = new ReplicationHelloReply(instanceInfo.getId(), false); sendOnTransport(reply); moveToState(STATE.Handshake, STATE.Connected); return Observable.just(reply); } }); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof SourcedModifyNotification)) return false; if (!super.equals(o)) return false; SourcedModifyNotification that = (SourcedModifyNotification) o; if (source != null ? !source.equals(that.source) : that.source != null) return false; return true; }
final Source source = new Source(Origin.BOOTSTRAP, "loaded@" + System.currentTimeMillis());
public BridgeChannelImpl(SourcedEurekaRegistry<InstanceInfo> registry, DiscoveryClient discoveryClient, int refreshRateSec, InstanceInfo self, BridgeChannelMetrics metrics, Scheduler scheduler) { super(STATE.Idle, null, registry, metrics); this.registry = registry; this.discoveryClient = discoveryClient; this.refreshRateSec = refreshRateSec; this.self = self; this.selfSource = new Source(Source.Origin.LOCAL); this.metrics = metrics; converter = new InstanceInfoConverterImpl(); worker = scheduler.createWorker(); lifecycle = ReplaySubject.create(); }
super(STATE.Idle, transport, registry, metrics); selfSource = new Source(Source.Origin.LOCAL); instanceInfoRef = new AtomicReference<>();