public InstanceInfo getMatching(Source source) { Source currIfExist = getMatchingSource(source); if (currIfExist != null) { return dataMap.get(currIfExist); } return null; }
/** * 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; } }
dataStore.put(source, data);
InstanceInfo removed = dataStore.remove(source); Snapshot<InstanceInfo> currSnapshot = snapshot; Status result = Status.RemovedFragment; result = Status.RemoveExpired; } else if (matches(source, currSnapshot.getSource())) { // remove of current snapshot Map.Entry<Source, InstanceInfo> newHead = dataStore.nextEntry(); if (newHead == null) { // removed last copy snapshot = null;
/** * Matches sources on origin:name only. * - If a matching source already exist in the sourceMap, remove from the dataStore first before add (as the * curr source may not equal due to a different source id). * - Otherwise, just add to the dataStore * - finally, add the source and sourceKey to the sourceMap */ public void put(Source source, InstanceInfo instanceInfo) { String sourceKey = sourceKey(source); Source currIfExist = sourceMap.get(sourceKey); if (currIfExist != null) { dataMap.remove(currIfExist); } dataMap.put(source, instanceInfo); sourceMap.put(sourceKey, source); }
@Override public int size() { return dataStore.size(); }
/** * @return the current stored source that matches the given source's origin and name (but not necessarily id). */ private Source getMatchingSource(Source source) { String key = sourceKey(source); return sourceMap.get(key); }
@Override public InstanceInfo get(Source source) { return dataStore.getExact(source); }
@Override public Collection<Source> getAllSources() { return dataStore.getAllSources(); }
public NotifyingInstanceInfoHolder( HolderStoreAccessor<NotifyingInstanceInfoHolder> holderStoreAccessor, PauseableSubject<ChangeNotification<InstanceInfo>> pauseableSubject, NotificationTaskInvoker invoker, String id) { this.holderStoreAccessor = holderStoreAccessor; this.pauseableSubject = pauseableSubject; this.invoker = invoker; this.id = id; this.dataStore = new DataStore(); }