Repository: helix Updated Branches: refs/heads/helix-0.6.x 86638bc8f -> 8f31d651b
[HELIX-567] Make StateModelFactory change backward compatible, add missing part, rb=32068 Project: http://git-wip-us.apache.org/repos/asf/helix/repo Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/8f31d651 Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/8f31d651 Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/8f31d651 Branch: refs/heads/helix-0.6.x Commit: 8f31d651b785a193d40bbb9f295ba2e9141427ea Parents: 86638bc Author: zzhang <[email protected]> Authored: Sat Mar 14 00:17:10 2015 -0700 Committer: zzhang <[email protected]> Committed: Sat Mar 14 00:17:10 2015 -0700 ---------------------------------------------------------------------- .../statemachine/StateModelFactory.java | 41 ++++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/helix/blob/8f31d651/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateModelFactory.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateModelFactory.java b/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateModelFactory.java index 880531c..2878620 100644 --- a/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateModelFactory.java +++ b/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateModelFactory.java @@ -70,10 +70,11 @@ public abstract class StateModelFactory<T extends StateModel> { /** * Create a state model for a partition * @param partitionKey + * @return state model */ public T createAndAddStateModel(String resourceName, String partitionKey) { T stateModel = createNewStateModel(resourceName, partitionKey); - synchronized(_stateModelMap) { + synchronized (_stateModelMap) { if (!_stateModelMap.containsKey(resourceName)) { _stateModelMap.put(resourceName, new ConcurrentHashMap<String, T>()); } @@ -83,6 +84,19 @@ public abstract class StateModelFactory<T extends StateModel> { } /** + * NOTE: This method is deprecated. Bring it back to keep backward compatible. + * Replaced by StateModelFactory#createAndAddStateModel(String resourceName, String partitionKey) + * Create a state model for a partition + * @param partitionName + * @return state model + */ + @Deprecated + public T createAndAddStateModel(String partitionName) { + throw new UnsupportedOperationException( + "This method is replaced by StateModelFactory#createAndAddStateModel(String resourceName, String partitionKey)"); + } + + /** * Get the state model for a partition * @param resourceName * @param partitionKey @@ -90,7 +104,7 @@ public abstract class StateModelFactory<T extends StateModel> { */ public T getStateModel(String resourceName, String partitionKey) { Map<String, T> map = _stateModelMap.get(resourceName); - return map == null? null : map.get(partitionKey); + return map == null ? null : map.get(partitionKey); } /** @@ -120,7 +134,7 @@ public abstract class StateModelFactory<T extends StateModel> { */ public T removeStateModel(String resourceName, String partitionKey) { T stateModel = null; - synchronized(_stateModelMap) { + synchronized (_stateModelMap) { Map<String, T> map = _stateModelMap.get(resourceName); if (map != null) { stateModel = map.remove(partitionKey); @@ -133,6 +147,25 @@ public abstract class StateModelFactory<T extends StateModel> { } /** + * NOTE: This method is deprecated. Bring it back to keep backward compatible. + * Replaced by StateModelFactory#removeStateModel(String resourceName, String partitionKey) + * remove state model for a partition + * @param partitionName + * @return state model removed or null if not exist + */ + @Deprecated + public T removeStateModel(String partitionName) { + // remove the first state model that match partitionName + // assuming partitionName is unique across all resources + for (ConcurrentMap<String, T> map : _stateModelMap.values()) { + if (map.containsKey(partitionName)) { + return map.remove(partitionName); + } + } + return null; + } + + /** * get resource set * @param resourceName * @return resource name set @@ -148,7 +181,7 @@ public abstract class StateModelFactory<T extends StateModel> { */ public Set<String> getPartitionSet(String resourceName) { Map<String, T> map = _stateModelMap.get(resourceName); - return (map == null? Collections.<String>emptySet() : map.keySet()); + return (map == null ? Collections.<String> emptySet() : map.keySet()); } /**
