protected Set<Interest<InstanceInfo>> getBasicInterests(Interest<InstanceInfo> newInterests) { Set<Interest<InstanceInfo>> basicInterests; if (newInterests instanceof MultipleInterests) { basicInterests = ((MultipleInterests<InstanceInfo>) newInterests).flatten(); } else { basicInterests = Collections.singleton(newInterests); } return basicInterests; } }
public MultipleInterests<T> copyAndAppend(Interest<T> toAppend) { Set<Interest<T>> newInterests = flatten(); // flatten does the copy of the underlying set append(toAppend, newInterests); return new MultipleInterests<>(newInterests); }
private static <T> void remove(Interest<T> interest, Set<Interest<T>> collector) { if (interest instanceof MultipleInterests) { for (Interest<T> i : ((MultipleInterests<T>) interest).getInterests()) { remove(i, collector); } } else { collector.remove(interest); } }
public MultipleInterests<T> copyAndRemove(Interest<T> toAppend) { Set<Interest<T>> newInterests = flatten(); // flatten does the copy of the underlying set remove(toAppend, newInterests); return new MultipleInterests<>(newInterests); }
@Override public void call() { channelInterest = new MultipleInterests<>(interest); } }
private static <T> void append(Interest<T> interest, Set<Interest<T>> collector) { if (interest instanceof MultipleInterests) { for (Interest<T> i : ((MultipleInterests<T>) interest).getInterests()) { append(i, collector); } } else { collector.add(interest); } }
public synchronized void appendInterest(final Interest<InstanceInfo> interest) { Integer refCount = interests.putIfAbsent(interest, 1); if (refCount != null) { interests.put(interest, refCount + 1); } else { multipleInterests = multipleInterests.copyAndAppend(interest); interestSubject.onNext(multipleInterests); } }
@Override public Observable<Void> removeInterest(Interest<InstanceInfo> toRemove) { if (null == channelInterest) { return Observable.error(INTEREST_NOT_REGISTERED_EXCEPTION); } return change(channelInterest.copyAndRemove(toRemove)); }
/** * Given atomic or complex interest, tell if we are in the batch mode. We should batch * if at least one of the atomic interests of the given interest is eligible to batching. * If all atomic streams are in unknown state (there was no state notification * for it received), the unknown batching state is returned. */ @Override public BufferState shouldBatch(Interest<T> interest) { if (interest instanceof MultipleInterests) { Set<Interest<T>> interests = ((MultipleInterests<T>) interest).getInterests(); boolean allUnknown = true; for (Interest<T> atomic : interests) { BufferState state = shouldBatchAtomic(atomic); if (state == BufferState.BufferStart) { return BufferState.BufferStart; } allUnknown &= state == BufferState.Unknown; } return allUnknown ? BufferState.Unknown : BufferState.BufferEnd; } return shouldBatchAtomic(interest); }
public MultipleInterests(Iterable<Interest<T>> interests) { this.interests = new HashSet<>(); for (Interest<T> interest : interests) { append(interest, this.interests); // Unwraps if the interest itself is a MultipleInterest } }
public static Interest<InstanceInfo> forSome(Interest<InstanceInfo>... interests) { return new MultipleInterests<>(interests); } }
@Override public Observable<Void> appendInterest(Interest<InstanceInfo> toAppend) { if (null == channelInterest) { return Observable.error(INTEREST_NOT_REGISTERED_EXCEPTION); } return change(channelInterest.copyAndAppend(toAppend)); }
public synchronized void removeInterest(final Interest<InstanceInfo> interest) { Integer refCount = interests.get(interest); if (refCount != null) { if (refCount <= 1) { interests.remove(interest); multipleInterests = multipleInterests.copyAndRemove(interest); interestSubject.onNext(multipleInterests); } else { interests.put(interest, refCount - 1); } } }
@SafeVarargs public MultipleInterests(Interest<T>... interests) { this.interests = new HashSet<>(); for (Interest<T> interest : interests) { append(interest, this.interests); // Unwraps if the interest itself is a MultipleInterest } }
protected Set<Interest<InstanceInfo>> getBasicInterests(Interest<InstanceInfo> newInterests) { Set<Interest<InstanceInfo>> basicInterests; if (newInterests instanceof MultipleInterests) { basicInterests = ((MultipleInterests<InstanceInfo>) newInterests).flatten(); } else { basicInterests = Collections.singleton(newInterests); } return basicInterests; } }
public Interest<InstanceInfo> toComposite() { if(interests.length == 0) { return Interests.forNone(); } if (interests.length > 1) { return new MultipleInterests<InstanceInfo>(interests); } return interests[0]; }
public InterestRegistration(Interest<InstanceInfo> interest) { if (interest instanceof MultipleInterests) { Set<Interest<InstanceInfo>> set = ((MultipleInterests<InstanceInfo>) interest).flatten(); interests = set.toArray(new Interest[set.size()]); } else { interests = new Interest[]{interest}; } }
@Override public void call(final Subscriber<? super Void> subscriber) { // Resubscribe Interest<InstanceInfo> activeInterests = new MultipleInterests<InstanceInfo>(previousState.interests.keySet()); newChannel.appendInterest(activeInterests).subscribe(); // Wait until registry fills up to the expected level. newState.registry.forInterest(activeInterests).lift( new RegistrySwapOperator(previousState.registry, newState.registry, swapStrategyFactory) ).subscribe(Subscribers.from(subscriber)); } });
@Override public void retainAll(Interest<T> interest) { Set<Interest<T>> toKeep; if (interest instanceof MultipleInterests) { toKeep = ((MultipleInterests<T>) interest).flatten(); } else { toKeep = Collections.singleton(interest); } interestsBufferingState.keySet().retainAll(toKeep); }
public static Interest<InstanceInfo> forSecureVips(Operator operator, String... secureVips) { if (secureVips.length == 0) { return EmptyRegistryInterest.getInstance(); } if (secureVips.length == 1) { return new SecureVipInterest(secureVips[0], operator); } Interest[] interests = new Interest[secureVips.length]; for (int i = 0; i < interests.length; i++) { interests[i] = new SecureVipInterest(secureVips[i], operator); } return new MultipleInterests<InstanceInfo>(interests); }