private static Map<String, CollectionRef> getRefMap(Map<String, DocCollection> collectionStates) { Map<String, CollectionRef> collRefs = new LinkedHashMap<>(collectionStates.size()); for (Entry<String, DocCollection> entry : collectionStates.entrySet()) { final DocCollection c = entry.getValue(); collRefs.put(entry.getKey(), new CollectionRef(c)); } return collRefs; }
private static Map<String, CollectionRef> getRefMap(Map<String, DocCollection> collectionStates) { Map<String, CollectionRef> collRefs = new LinkedHashMap<>(collectionStates.size()); for (Entry<String, DocCollection> entry : collectionStates.entrySet()) { final DocCollection c = entry.getValue(); collRefs.put(entry.getKey(), new CollectionRef(c)); } return collRefs; }
public static ClusterState load(Integer version, Map<String, Object> stateMap, Set<String> liveNodes, String znode) { Map<String,CollectionRef> collections = new LinkedHashMap<>(stateMap.size()); for (Entry<String, Object> entry : stateMap.entrySet()) { String collectionName = entry.getKey(); DocCollection coll = collectionFromObjects(collectionName, (Map<String,Object>)entry.getValue(), version, znode); collections.put(collectionName, new CollectionRef(coll)); } return new ClusterState( liveNodes, collections,version); }
result.putIfAbsent(entry.getKey(), new ClusterState.CollectionRef(entry.getValue()));
updateWatchedCollection(live); result.put(s, new ClusterState.CollectionRef(live)); result.put(s, new ClusterState.CollectionRef(null) { @Override public DocCollection get() {
/** * Create ClusterState from json string that is typically stored in zookeeper. * * @param version zk version of the clusterstate.json file (bytes) * @param bytes clusterstate.json as a byte array * @param liveNodes list of live nodes * @return the ClusterState */ public static ClusterState load(Integer version, byte[] bytes, Set<String> liveNodes, String znode) { // System.out.println("######## ClusterState.load:" + (bytes==null ? null : new String(bytes))); if (bytes == null || bytes.length == 0) { return new ClusterState(version, liveNodes, Collections.<String, DocCollection>emptyMap()); } Map<String, Object> stateMap = (Map<String, Object>) Utils.fromJSON(bytes); Map<String,CollectionRef> collections = new LinkedHashMap<>(stateMap.size()); for (Entry<String, Object> entry : stateMap.entrySet()) { String collectionName = entry.getKey(); DocCollection coll = collectionFromObjects(collectionName, (Map<String,Object>)entry.getValue(), version, znode); collections.put(collectionName, new CollectionRef(coll)); } return new ClusterState( liveNodes, collections,version); }
/** * Returns a new cluster state object modified with the given collection. * * @param collectionName the name of the modified (or deleted) collection * @param collection the collection object. A null value deletes the collection from the state * @return the updated cluster state which preserves the current live nodes and zk node version */ public ClusterState copyWith(String collectionName, DocCollection collection) { ClusterState result = new ClusterState(liveNodes, new LinkedHashMap<>(collectionStates), znodeVersion); if (collection == null) { result.collectionStates.remove(collectionName); } else { result.collectionStates.put(collectionName, new CollectionRef(collection)); } return result; }
/** * Returns a new cluster state object modified with the given collection. * * @param collectionName the name of the modified (or deleted) collection * @param collection the collection object. A null value deletes the collection from the state * @return the updated cluster state which preserves the current live nodes and zk node version */ public ClusterState copyWith(String collectionName, DocCollection collection) { ClusterState result = new ClusterState(liveNodes, new LinkedHashMap<>(collectionStates), znodeVersion); if (collection == null) { result.collectionStates.remove(collectionName); } else { result.collectionStates.put(collectionName, new CollectionRef(collection)); } return result; }