Repository: helix
Updated Branches:
  refs/heads/helix-0.6.x 86b2b25ac -> 86638bc8f


[HELIX-567] Make StateModelFactory change backward compatible, rb=32068


Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/86638bc8
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/86638bc8
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/86638bc8

Branch: refs/heads/helix-0.6.x
Commit: 86638bc8fdacf8ebb8572c1e409407e625330de8
Parents: 86b2b25
Author: zzhang <[email protected]>
Authored: Fri Mar 13 23:25:44 2015 -0700
Committer: zzhang <[email protected]>
Committed: Fri Mar 13 23:25:44 2015 -0700

----------------------------------------------------------------------
 .../statemachine/StateModelFactory.java         | 62 ++++++++++++++++++--
 1 file changed, 57 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/86638bc8/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 b775016..880531c 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
@@ -20,6 +20,7 @@ package org.apache.helix.participant.statemachine;
  */
 
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
@@ -42,13 +43,29 @@ public abstract class StateModelFactory<T extends 
StateModel> {
 
   /**
    * This method will be invoked only once per resource per partition per 
session
-   * Replacing old StateModelFactory#createNewStateModel(String partitionName)
+   * Replace deprecating StateModelFactory#createNewStateModel(String 
partitionName)
    * Add "resourceName" to signature @see HELIX-552
    * @param resourceName
    * @param partitionName
    * @return state model
    */
-  public abstract T createNewStateModel(String resourceName, String 
partitionName);
+  public T createNewStateModel(String resourceName, String partitionName) {
+    // default implementation ignores resourceName
+    return createNewStateModel(partitionName);
+  }
+
+  /**
+   * NOTE: This method is deprecated. Bring it back to keep backward 
compatible.
+   * Replaced by StateModelFactory#createNewStateModel(String resourceName, 
String partitionName)
+   * This method will be invoked only once per partitionName per session
+   * @param partitionName
+   * @return state model
+   */
+  @Deprecated
+  public T createNewStateModel(String partitionName) {
+    throw new UnsupportedOperationException(
+        "Please implement StateModelFactory#createNewStateModel(String 
resourceName, String partitionName)");
+  }
 
   /**
    * Create a state model for a partition
@@ -77,6 +94,25 @@ public abstract class StateModelFactory<T extends 
StateModel> {
   }
 
   /**
+   * NOTE: This method is deprecated. Bring it back to keep backward 
compatible.
+   * Replaced by StateModelFactory#getStateModel(String resourceName, String 
partitionKey)
+   * Get the state model for a partition
+   * @param partitionName
+   * @return state model if exists, null otherwise
+   */
+  @Deprecated
+  public T getStateModel(String partitionName) {
+    // return 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.get(partitionName);
+      }
+    }
+    return null;
+  }
+
+  /**
    * remove state model for a partition
    * @param resourceName
    * @param partitionKey
@@ -116,9 +152,25 @@ public abstract class StateModelFactory<T extends 
StateModel> {
   }
 
   /**
+   * NOTE: This method is deprecated. Bring it back to keep backward 
compatible.
+   * Replaced by StateModelFactory#getPartitionSet(String resourceName)
+   * get partition set
+   * @return partition key set
+   */
+  @Deprecated
+  public Set<String> getPartitionSet() {
+    // return union of all partitions, assuming partitionName is unique across 
all resources
+    Set<String> allPartitions = new HashSet<String>();
+    for (ConcurrentMap<String, T> map : _stateModelMap.values()) {
+      allPartitions.addAll(map.keySet());
+    }
+    return allPartitions;
+  }
+
+  /**
    * create a default batch-message-wrapper for a resource
    * @param resourceName
-   * @return
+   * @return batch message handler
    */
   public BatchMessageWrapper createBatchMessageWrapper(String resourceName) {
     return new BatchMessageWrapper();
@@ -127,7 +179,7 @@ public abstract class StateModelFactory<T extends 
StateModel> {
   /**
    * create a batch-message-wrapper for a resource and put it into map
    * @param resourceName
-   * @return
+   * @return batch message handler
    */
   public BatchMessageWrapper createAndAddBatchMessageWrapper(String 
resourceName) {
     BatchMessageWrapper wrapper = createBatchMessageWrapper(resourceName);
@@ -138,7 +190,7 @@ public abstract class StateModelFactory<T extends 
StateModel> {
   /**
    * get batch-message-wrapper for a resource
    * @param resourceName
-   * @return
+   * @return batch message handler
    */
   public BatchMessageWrapper getBatchMessageWrapper(String resourceName) {
     return _batchMsgWrapperMap.get(resourceName);

Reply via email to