You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by zz...@apache.org on 2014/08/07 22:46:39 UTC

[2/5] [HELIX-484] Remove CallbackHandler/ZkCallbackHandler code duplication, [HELIX-486] Remove StateModelFactory/HelixStateModelFactory code duplication, rb=24332

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionTimeout.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionTimeout.java b/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionTimeout.java
index c4304b0..b929d5e 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionTimeout.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionTimeout.java
@@ -30,8 +30,10 @@ import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.NotificationContext;
 import org.apache.helix.PropertyKey.Builder;
 import org.apache.helix.api.State;
+import org.apache.helix.api.StateTransitionHandlerFactory;
 import org.apache.helix.api.id.ParticipantId;
 import org.apache.helix.api.id.PartitionId;
+import org.apache.helix.api.id.StateModelDefId;
 import org.apache.helix.manager.zk.MockParticipant;
 import org.apache.helix.manager.zk.MockController;
 import org.apache.helix.messaging.handling.MessageHandler.ErrorCode;
@@ -41,7 +43,6 @@ import org.apache.helix.mock.participant.SleepTransition;
 import org.apache.helix.model.ExternalView;
 import org.apache.helix.model.IdealState;
 import org.apache.helix.model.Message;
-import org.apache.helix.participant.statemachine.StateModelFactory;
 import org.apache.helix.participant.statemachine.StateModelInfo;
 import org.apache.helix.participant.statemachine.StateTransitionError;
 import org.apache.helix.participant.statemachine.Transition;
@@ -146,26 +147,26 @@ public class TestStateTransitionTimeout extends ZkStandAloneCMTestBase {
     }
   }
 
-  public static class SleepStateModelFactory extends StateModelFactory<TimeOutStateModel> {
-    Set<String> partitionsToSleep = new HashSet<String>();
+  public static class SleepStateModelFactory extends StateTransitionHandlerFactory<TimeOutStateModel> {
+    Set<PartitionId> partitionsToSleep = new HashSet<PartitionId>();
     int _sleepTime;
 
     public SleepStateModelFactory(int sleepTime) {
       _sleepTime = sleepTime;
     }
 
-    public void setPartitions(Collection<String> partitions) {
+    public void setPartitions(Collection<PartitionId> partitions) {
       partitionsToSleep.addAll(partitions);
     }
 
-    public void addPartition(String partition) {
+    public void addPartition(PartitionId partition) {
       partitionsToSleep.add(partition);
     }
 
     @Override
-    public TimeOutStateModel createNewStateModel(String stateUnitKey) {
+    public TimeOutStateModel createStateTransitionHandler(PartitionId partition) {
       return new TimeOutStateModel(new SleepTransition(_sleepTime),
-          partitionsToSleep.contains(stateUnitKey));
+          partitionsToSleep.contains(partition));
     }
   }
 
@@ -181,12 +182,12 @@ public class TestStateTransitionTimeout extends ZkStandAloneCMTestBase {
       factories.put(instanceName, factory);
       for (PartitionId p : idealState.getPartitionIdSet()) {
         if (idealState.getPreferenceList(p).get(0).equals(ParticipantId.from(instanceName))) {
-          factory.addPartition(p.stringify());
+          factory.addPartition(p);
         }
       }
 
       _participants[i] = new MockParticipant(_zkaddr, CLUSTER_NAME, instanceName);
-      _participants[i].getStateMachineEngine().registerStateModelFactory("MasterSlave", factory);
+      _participants[i].getStateMachineEngine().registerStateModelFactory(StateModelDefId.from("MasterSlave"), factory);
       _participants[i].syncStart();
     }
     String controllerName = "controller_0";
@@ -205,7 +206,7 @@ public class TestStateTransitionTimeout extends ZkStandAloneCMTestBase {
       ParticipantId idealMaster = idealState.getPreferenceList(p).get(0);
       Assert.assertTrue(ev.getStateMap(p).get(idealMaster).equals(State.from("ERROR")));
 
-      TimeOutStateModel model = factories.get(idealMaster.stringify()).getStateModel(p.stringify());
+      TimeOutStateModel model = factories.get(idealMaster.stringify()).getTransitionHandler(p);
       Assert.assertEquals(model._errorCallcount, 1);
       Assert.assertEquals(model._error.getCode(), ErrorCode.TIMEOUT);
     }

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/integration/TestZkReconnect.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestZkReconnect.java b/helix-core/src/test/java/org/apache/helix/integration/TestZkReconnect.java
index 18f6fd7..08a2f18 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestZkReconnect.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestZkReconnect.java
@@ -32,14 +32,15 @@ import org.apache.helix.InstanceType;
 import org.apache.helix.NotificationContext;
 import org.apache.helix.TestHelper;
 import org.apache.helix.api.State;
+import org.apache.helix.api.StateTransitionHandlerFactory;
+import org.apache.helix.api.TransitionHandler;
 import org.apache.helix.api.id.ParticipantId;
 import org.apache.helix.api.id.PartitionId;
 import org.apache.helix.api.id.ResourceId;
+import org.apache.helix.api.id.StateModelDefId;
 import org.apache.helix.api.id.StateModelFactoryId;
 import org.apache.helix.model.IdealState;
 import org.apache.helix.model.Message;
-import org.apache.helix.participant.statemachine.StateModel;
-import org.apache.helix.participant.statemachine.StateModelFactory;
 import org.apache.helix.testutil.ZkTestUtil;
 import org.apache.helix.tools.ClusterSetup;
 import org.apache.helix.tools.ClusterStateVerifier;
@@ -86,13 +87,13 @@ public class TestZkReconnect {
 
     LOG.info("Register state machine");
     final CountDownLatch latch = new CountDownLatch(1);
-    participant.getStateMachineEngine().registerStateModelFactory("OnlineOffline",
-        new StateModelFactory<StateModel>() {
+    participant.getStateMachineEngine().registerStateModelFactory(
+        StateModelDefId.OnlineOffline, "test", new StateTransitionHandlerFactory<TransitionHandler>() {
           @Override
-          public StateModel createNewStateModel(String stateUnitKey) {
+          public TransitionHandler createStateTransitionHandler(PartitionId stateUnitKey) {
             return new SimpleStateModel(latch);
           }
-        }, "test");
+        });
 
     String resourceName = "test-resource";
     LOG.info("Ideal state assignment");
@@ -144,7 +145,7 @@ public class TestZkReconnect {
     }
   }
 
-  public static final class SimpleStateModel extends StateModel {
+  public static final class SimpleStateModel extends TransitionHandler {
 
     private final CountDownLatch latch;
 

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java b/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java
index 99986ef..1b55af5 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java
@@ -28,6 +28,7 @@ import org.apache.helix.PreConnectCallback;
 import org.apache.helix.PropertyKey;
 import org.apache.helix.TestHelper;
 import org.apache.helix.ZkTestHelper;
+import org.apache.helix.api.id.StateModelDefId;
 import org.apache.helix.manager.zk.MockParticipant;
 import org.apache.helix.manager.zk.MockMultiClusterController;
 import org.apache.helix.manager.zk.MockController;
@@ -186,7 +187,7 @@ public class TestConsecutiveZkSessionExpiry extends ZkTestBase {
     for (int i = 0; i < n; i++) {
       String contrllerName = "localhost_" + (12918 + i);
       distributedControllers[i] = new MockMultiClusterController(_zkaddr, clusterName, contrllerName);
-      distributedControllers[i].getStateMachineEngine().registerStateModelFactory("MasterSlave",
+      distributedControllers[i].getStateMachineEngine().registerStateModelFactory(StateModelDefId.MasterSlave,
           new MockMSModelFactory());
       if (i == 0) {
         distributedControllers[i].addPreConnectCallback(new PreConnectTestCallback(contrllerName,

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/integration/manager/TestDistributedControllerManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/TestDistributedControllerManager.java b/helix-core/src/test/java/org/apache/helix/integration/manager/TestDistributedControllerManager.java
deleted file mode 100644
index 18234b5..0000000
--- a/helix-core/src/test/java/org/apache/helix/integration/manager/TestDistributedControllerManager.java
+++ /dev/null
@@ -1,203 +0,0 @@
-package org.apache.helix.integration.manager;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.Date;
-import java.util.List;
-
-import org.apache.helix.HelixManager;
-import org.apache.helix.InstanceType;
-import org.apache.helix.PropertyKey;
-import org.apache.helix.TestHelper;
-import org.apache.helix.ZkTestHelper;
-import org.apache.helix.manager.zk.MockMultiClusterController;
-import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZKHelixManager;
-import org.apache.helix.manager.zk.ZkCallbackHandler;
-import org.apache.helix.mock.participant.MockMSModelFactory;
-import org.apache.helix.model.LiveInstance;
-import org.apache.helix.testutil.ZkTestBase;
-import org.apache.helix.tools.ClusterStateVerifier;
-import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
-import org.apache.log4j.Logger;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-public class TestDistributedControllerManager extends ZkTestBase {
-  private static Logger LOG = Logger.getLogger(TestDistributedControllerManager.class);
-
-  @Test
-  public void simpleIntegrationTest() throws Exception {
-    // Logger.getRootLogger().setLevel(Level.INFO);
-    String className = TestHelper.getTestClassName();
-    String methodName = TestHelper.getTestMethodName();
-    String clusterName = className + "_" + methodName;
-    int n = 2;
-
-    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
-
-    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
-        "localhost", // participant name prefix
-        "TestDB", // resource name prefix
-        1, // resources
-        4, // partitions per resource
-        n, // number of nodes
-        2, // replicas
-        "MasterSlave", true); // do rebalance
-
-    HelixManager[] distributedControllers = new HelixManager[n];
-    for (int i = 0; i < n; i++) {
-      int port = 12918 + i;
-      distributedControllers[i] =
-          new ZKHelixManager(clusterName, "localhost_" + port, InstanceType.CONTROLLER_PARTICIPANT,
-              _zkaddr);
-      distributedControllers[i].getStateMachineEngine().registerStateModelFactory("MasterSlave",
-          new MockMSModelFactory());
-      distributedControllers[i].connect();
-    }
-
-    boolean result =
-        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
-            clusterName));
-    Assert.assertTrue(result);
-
-    // disconnect first distributed-controller, and verify second takes leadership
-    distributedControllers[0].disconnect();
-
-    // verify leader changes to localhost_12919
-    Thread.sleep(100);
-    result =
-        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
-            clusterName));
-    Assert.assertTrue(result);
-
-    ZKHelixDataAccessor accessor =
-        new ZKHelixDataAccessor(clusterName, _baseAccessor);
-    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
-    Assert.assertNull(accessor.getProperty(keyBuilder.liveInstance("localhost_12918")));
-    LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
-    Assert.assertNotNull(leader);
-    Assert.assertEquals(leader.getId(), "localhost_12919");
-
-    // clean up
-    distributedControllers[1].disconnect();
-    Assert.assertNull(accessor.getProperty(keyBuilder.liveInstance("localhost_12919")));
-    Assert.assertNull(accessor.getProperty(keyBuilder.controllerLeader()));
-
-    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
-  }
-
-  /**
-   * expire a controller and make sure the other takes the leadership
-   * @param expireController
-   * @param newController
-   * @throws Exception
-   */
-  void expireController(MockMultiClusterController expireController,
-      MockMultiClusterController newController) throws Exception {
-    String clusterName = expireController.getClusterName();
-    LOG.info("Expiring distributedController: " + expireController.getInstanceName()
-        + ", session: " + expireController.getSessionId() + " ...");
-    String oldSessionId = expireController.getSessionId();
-
-    ZkTestHelper.expireSession(expireController.getZkClient());
-    String newSessionId = expireController.getSessionId();
-    LOG.debug("Expried distributedController: " + expireController.getInstanceName()
-        + ", oldSessionId: " + oldSessionId + ", newSessionId: " + newSessionId);
-
-    boolean result =
-        ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
-            _zkaddr, clusterName));
-    Assert.assertTrue(result);
-
-    // verify leader changes to localhost_12919
-    ZKHelixDataAccessor accessor =
-        new ZKHelixDataAccessor(clusterName, _baseAccessor);
-    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
-    Assert.assertNotNull(accessor.getProperty(keyBuilder.liveInstance(expireController
-        .getInstanceName())));
-    LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
-    Assert.assertNotNull(leader);
-    Assert.assertEquals(leader.getId(), newController.getInstanceName());
-
-    // check expired-controller has 2 handlers: message and leader-election
-    TestHelper.printHandlers(expireController, expireController.getHandlers());
-
-    List<ZkCallbackHandler> handlers = expireController.getHandlers();
-    Assert.assertEquals(handlers.size(), 2,
-        "Distributed controller should have 2 handler (message and leader-election) after lose leadership, but was "
-            + handlers.size());
-  }
-
-  @Test
-  public void simpleSessionExpiryTest() throws Exception {
-    // Logger.getRootLogger().setLevel(Level.INFO);
-    String className = TestHelper.getTestClassName();
-    String methodName = TestHelper.getTestMethodName();
-    String clusterName = className + "_" + methodName;
-    int n = 2;
-
-    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
-
-    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
-        "localhost", // participant name prefix
-        "TestDB", // resource name prefix
-        1, // resources
-        4, // partitions per resource
-        n, // number of nodes
-        2, // replicas
-        "MasterSlave", true); // do rebalance
-
-    MockMultiClusterController[] distributedControllers = new MockMultiClusterController[n];
-
-    for (int i = 0; i < n; i++) {
-      String contrllerName = "localhost_" + (12918 + i);
-      distributedControllers[i] =
-          new MockMultiClusterController(_zkaddr, clusterName, contrllerName);
-      distributedControllers[i].getStateMachineEngine().registerStateModelFactory("MasterSlave",
-          new MockMSModelFactory());
-      distributedControllers[i].connect();
-    }
-
-    boolean result =
-        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
-            clusterName));
-    Assert.assertTrue(result);
-
-    // expire localhost_12918
-    expireController(distributedControllers[0], distributedControllers[1]);
-
-    // expire localhost_12919
-    expireController(distributedControllers[1], distributedControllers[0]);
-
-    // clean up
-    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
-    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
-
-    for (int i = 0; i < n; i++) {
-      distributedControllers[i].disconnect();
-      Assert.assertNull(accessor.getProperty(keyBuilder.liveInstance(distributedControllers[i]
-          .getInstanceName())));
-    }
-    Assert.assertNull(accessor.getProperty(keyBuilder.controllerLeader()));
-
-    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
-  }
-}

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/integration/manager/TestHelixMultiClusterController.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/TestHelixMultiClusterController.java b/helix-core/src/test/java/org/apache/helix/integration/manager/TestHelixMultiClusterController.java
new file mode 100644
index 0000000..51e7e19
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/integration/manager/TestHelixMultiClusterController.java
@@ -0,0 +1,204 @@
+package org.apache.helix.integration.manager;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Date;
+import java.util.List;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.InstanceType;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.TestHelper;
+import org.apache.helix.ZkTestHelper;
+import org.apache.helix.api.id.StateModelDefId;
+import org.apache.helix.manager.zk.MockMultiClusterController;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZKHelixManager;
+import org.apache.helix.manager.zk.ZkCallbackHandler;
+import org.apache.helix.mock.participant.MockMSModelFactory;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.testutil.ZkTestBase;
+import org.apache.helix.tools.ClusterStateVerifier;
+import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
+import org.apache.log4j.Logger;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TestHelixMultiClusterController extends ZkTestBase {
+  private static Logger LOG = Logger.getLogger(TestHelixMultiClusterController.class);
+
+  @Test
+  public void simpleIntegrationTest() throws Exception {
+    // Logger.getRootLogger().setLevel(Level.INFO);
+    String className = TestHelper.getTestClassName();
+    String methodName = TestHelper.getTestMethodName();
+    String clusterName = className + "_" + methodName;
+    int n = 2;
+
+    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
+
+    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
+        "localhost", // participant name prefix
+        "TestDB", // resource name prefix
+        1, // resources
+        4, // partitions per resource
+        n, // number of nodes
+        2, // replicas
+        "MasterSlave", true); // do rebalance
+
+    HelixManager[] distributedControllers = new HelixManager[n];
+    for (int i = 0; i < n; i++) {
+      int port = 12918 + i;
+      distributedControllers[i] =
+          new ZKHelixManager(clusterName, "localhost_" + port, InstanceType.CONTROLLER_PARTICIPANT,
+              _zkaddr);
+      distributedControllers[i].getStateMachineEngine().registerStateModelFactory(StateModelDefId.MasterSlave,
+          new MockMSModelFactory());
+      distributedControllers[i].connect();
+    }
+
+    boolean result =
+        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
+            clusterName));
+    Assert.assertTrue(result);
+
+    // disconnect first distributed-controller, and verify second takes leadership
+    distributedControllers[0].disconnect();
+
+    // verify leader changes to localhost_12919
+    Thread.sleep(100);
+    result =
+        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
+            clusterName));
+    Assert.assertTrue(result);
+
+    ZKHelixDataAccessor accessor =
+        new ZKHelixDataAccessor(clusterName, _baseAccessor);
+    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+    Assert.assertNull(accessor.getProperty(keyBuilder.liveInstance("localhost_12918")));
+    LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
+    Assert.assertNotNull(leader);
+    Assert.assertEquals(leader.getId(), "localhost_12919");
+
+    // clean up
+    distributedControllers[1].disconnect();
+    Assert.assertNull(accessor.getProperty(keyBuilder.liveInstance("localhost_12919")));
+    Assert.assertNull(accessor.getProperty(keyBuilder.controllerLeader()));
+
+    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
+  }
+
+  /**
+   * expire a controller and make sure the other takes the leadership
+   * @param expireController
+   * @param newController
+   * @throws Exception
+   */
+  void expireController(MockMultiClusterController expireController,
+      MockMultiClusterController newController) throws Exception {
+    String clusterName = expireController.getClusterName();
+    LOG.info("Expiring distributedController: " + expireController.getInstanceName()
+        + ", session: " + expireController.getSessionId() + " ...");
+    String oldSessionId = expireController.getSessionId();
+
+    ZkTestHelper.expireSession(expireController.getZkClient());
+    String newSessionId = expireController.getSessionId();
+    LOG.debug("Expried distributedController: " + expireController.getInstanceName()
+        + ", oldSessionId: " + oldSessionId + ", newSessionId: " + newSessionId);
+
+    boolean result =
+        ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
+            _zkaddr, clusterName));
+    Assert.assertTrue(result);
+
+    // verify leader changes to localhost_12919
+    ZKHelixDataAccessor accessor =
+        new ZKHelixDataAccessor(clusterName, _baseAccessor);
+    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+    Assert.assertNotNull(accessor.getProperty(keyBuilder.liveInstance(expireController
+        .getInstanceName())));
+    LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
+    Assert.assertNotNull(leader);
+    Assert.assertEquals(leader.getId(), newController.getInstanceName());
+
+    // check expired-controller has 2 handlers: message and leader-election
+    TestHelper.printHandlers(expireController, expireController.getHandlers());
+
+    List<ZkCallbackHandler> handlers = expireController.getHandlers();
+    Assert.assertEquals(handlers.size(), 2,
+        "Distributed controller should have 2 handler (message and leader-election) after lose leadership, but was "
+            + handlers.size());
+  }
+
+  @Test
+  public void simpleSessionExpiryTest() throws Exception {
+    // Logger.getRootLogger().setLevel(Level.INFO);
+    String className = TestHelper.getTestClassName();
+    String methodName = TestHelper.getTestMethodName();
+    String clusterName = className + "_" + methodName;
+    int n = 2;
+
+    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
+
+    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
+        "localhost", // participant name prefix
+        "TestDB", // resource name prefix
+        1, // resources
+        4, // partitions per resource
+        n, // number of nodes
+        2, // replicas
+        "MasterSlave", true); // do rebalance
+
+    MockMultiClusterController[] distributedControllers = new MockMultiClusterController[n];
+
+    for (int i = 0; i < n; i++) {
+      String contrllerName = "localhost_" + (12918 + i);
+      distributedControllers[i] =
+          new MockMultiClusterController(_zkaddr, clusterName, contrllerName);
+      distributedControllers[i].getStateMachineEngine().registerStateModelFactory(StateModelDefId.MasterSlave,
+          new MockMSModelFactory());
+      distributedControllers[i].connect();
+    }
+
+    boolean result =
+        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
+            clusterName));
+    Assert.assertTrue(result);
+
+    // expire localhost_12918
+    expireController(distributedControllers[0], distributedControllers[1]);
+
+    // expire localhost_12919
+    expireController(distributedControllers[1], distributedControllers[0]);
+
+    // clean up
+    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
+    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+
+    for (int i = 0; i < n; i++) {
+      distributedControllers[i].disconnect();
+      Assert.assertNull(accessor.getProperty(keyBuilder.liveInstance(distributedControllers[i]
+          .getInstanceName())));
+    }
+    Assert.assertNull(accessor.getProperty(keyBuilder.controllerLeader()));
+
+    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
+  }
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/integration/manager/TestParticipantManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/TestParticipantManager.java b/helix-core/src/test/java/org/apache/helix/integration/manager/TestParticipantManager.java
index 309ab18..9ce0941 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/manager/TestParticipantManager.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/manager/TestParticipantManager.java
@@ -34,6 +34,7 @@ import org.apache.helix.TestHelper;
 import org.apache.helix.ZNRecord;
 import org.apache.helix.ZkTestHelper;
 import org.apache.helix.api.id.PartitionId;
+import org.apache.helix.api.id.StateModelDefId;
 import org.apache.helix.manager.zk.MockParticipant;
 import org.apache.helix.manager.zk.MockController;
 import org.apache.helix.manager.zk.ZKHelixDataAccessor;
@@ -74,7 +75,7 @@ public class TestParticipantManager extends ZkTestBase {
 
     HelixManager participant =
         new ZKHelixManager(clusterName, "localhost_12918", InstanceType.PARTICIPANT, _zkaddr);
-    participant.getStateMachineEngine().registerStateModelFactory("MasterSlave",
+    participant.getStateMachineEngine().registerStateModelFactory(StateModelDefId.MasterSlave,
         new MockMSModelFactory());
     participant.connect();
 

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/integration/manager/TestStateModelLeak.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/TestStateModelLeak.java b/helix-core/src/test/java/org/apache/helix/integration/manager/TestStateModelLeak.java
index d6d7bab..eaf74bb 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/manager/TestStateModelLeak.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/manager/TestStateModelLeak.java
@@ -28,13 +28,15 @@ import java.util.TreeMap;
 
 import org.apache.helix.HelixAdmin;
 import org.apache.helix.TestHelper;
+import org.apache.helix.api.StateTransitionHandlerFactory;
+import org.apache.helix.api.TransitionHandler;
+import org.apache.helix.api.id.PartitionId;
+import org.apache.helix.api.id.StateModelDefId;
 import org.apache.helix.manager.zk.MockParticipant;
 import org.apache.helix.manager.zk.MockController;
 import org.apache.helix.manager.zk.ZKHelixAdmin;
 import org.apache.helix.mock.participant.ErrTransition;
 import org.apache.helix.participant.HelixStateMachineEngine;
-import org.apache.helix.participant.statemachine.StateModel;
-import org.apache.helix.participant.statemachine.StateModelFactory;
 import org.apache.helix.testutil.ZkTestBase;
 import org.apache.helix.tools.ClusterStateVerifier;
 import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
@@ -72,8 +74,7 @@ public class TestStateModelLeak extends ZkTestBase {
         "MasterSlave", true); // do rebalance
 
     // start controller
-    MockController controller =
-        new MockController(_zkaddr, clusterName, "controller");
+    MockController controller = new MockController(_zkaddr, clusterName, "controller");
     controller.syncStart();
 
     MockParticipant[] participants = new MockParticipant[n];
@@ -92,15 +93,16 @@ public class TestStateModelLeak extends ZkTestBase {
     // check state-models in state-machine
     HelixStateMachineEngine stateMachine =
         (HelixStateMachineEngine) participants[0].getStateMachineEngine();
-    StateModelFactory<? extends StateModel> fty = stateMachine.getStateModelFactory("MasterSlave");
-    Map<String, String> expectStateModelMap = new TreeMap<String, String>();
-    expectStateModelMap.put("TestDB0_0", "SLAVE");
-    expectStateModelMap.put("TestDB0_1", "MASTER");
-    expectStateModelMap.put("TestDB0_2", "SLAVE");
-    expectStateModelMap.put("TestDB0_3", "MASTER");
+    StateTransitionHandlerFactory<? extends TransitionHandler> fty =
+        stateMachine.getStateModelFactory(StateModelDefId.from("MasterSlave"));
+    Map<PartitionId, String> expectStateModelMap = new TreeMap<PartitionId, String>();
+    expectStateModelMap.put(PartitionId.from("TestDB0_0"), "SLAVE");
+    expectStateModelMap.put(PartitionId.from("TestDB0_1"), "MASTER");
+    expectStateModelMap.put(PartitionId.from("TestDB0_2"), "SLAVE");
+    expectStateModelMap.put(PartitionId.from("TestDB0_3"), "MASTER");
     checkStateModelMap(fty, expectStateModelMap);
 
-    // drop resource
+    // drop resourcePartitionId
     HelixAdmin admin = new ZKHelixAdmin(_zkclient);
     admin.dropResource(clusterName, "TestDB0");
 
@@ -146,8 +148,7 @@ public class TestStateModelLeak extends ZkTestBase {
         "MasterSlave", true); // do rebalance
 
     // start controller
-    MockController controller =
-        new MockController(_zkaddr, clusterName, "controller");
+    MockController controller = new MockController(_zkaddr, clusterName, "controller");
     controller.syncStart();
 
     MockParticipant[] participants = new MockParticipant[n];
@@ -177,12 +178,13 @@ public class TestStateModelLeak extends ZkTestBase {
     // check state-models in state-machine
     HelixStateMachineEngine stateMachine =
         (HelixStateMachineEngine) participants[0].getStateMachineEngine();
-    StateModelFactory<? extends StateModel> fty = stateMachine.getStateModelFactory("MasterSlave");
-    Map<String, String> expectStateModelMap = new TreeMap<String, String>();
-    expectStateModelMap.put("TestDB0_0", "ERROR");
-    expectStateModelMap.put("TestDB0_1", "MASTER");
-    expectStateModelMap.put("TestDB0_2", "SLAVE");
-    expectStateModelMap.put("TestDB0_3", "MASTER");
+    StateTransitionHandlerFactory<? extends TransitionHandler> fty =
+        stateMachine.getStateModelFactory(StateModelDefId.from("MasterSlave"));
+    Map<PartitionId, String> expectStateModelMap = new TreeMap<PartitionId, String>();
+    expectStateModelMap.put(PartitionId.from("TestDB0_0"), "ERROR");
+    expectStateModelMap.put(PartitionId.from("TestDB0_1"), "MASTER");
+    expectStateModelMap.put(PartitionId.from("TestDB0_2"), "SLAVE");
+    expectStateModelMap.put(PartitionId.from("TestDB0_3"), "MASTER");
     checkStateModelMap(fty, expectStateModelMap);
 
     // drop resource
@@ -212,11 +214,11 @@ public class TestStateModelLeak extends ZkTestBase {
    * @param fty
    * @param expectStateModelMap
    */
-  static void checkStateModelMap(StateModelFactory<? extends StateModel> fty,
-      Map<String, String> expectStateModelMap) {
+  static void checkStateModelMap(StateTransitionHandlerFactory<? extends TransitionHandler> fty,
+      Map<PartitionId, String> expectStateModelMap) {
     Assert.assertEquals(fty.getPartitionSet().size(), expectStateModelMap.size());
-    for (String partition : fty.getPartitionSet()) {
-      StateModel stateModel = fty.getStateModel(partition);
+    for (PartitionId partition : fty.getPartitionSet()) {
+      TransitionHandler stateModel = fty.getTransitionHandler(partition);
       String actualState = stateModel.getCurrentState();
       String expectState = expectStateModelMap.get(partition);
       LOG.debug(partition + " actual state: " + actualState + ", expect state: " + expectState);

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/integration/manager/ZkTestManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/ZkTestManager.java b/helix-core/src/test/java/org/apache/helix/integration/manager/ZkTestManager.java
deleted file mode 100644
index 280786c..0000000
--- a/helix-core/src/test/java/org/apache/helix/integration/manager/ZkTestManager.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.apache.helix.integration.manager;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.List;
-
-import org.apache.helix.manager.zk.CallbackHandler;
-import org.apache.helix.manager.zk.ZkClient;
-
-public interface ZkTestManager {
-  ZkClient getZkClient();
-
-  List<CallbackHandler> getHandlers();
-
-  String getInstanceName();
-
-  String getClusterName();
-}

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/manager/zk/MockMultiClusterController.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/MockMultiClusterController.java b/helix-core/src/test/java/org/apache/helix/manager/zk/MockMultiClusterController.java
index 7f8b1a3..a39bd84 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/MockMultiClusterController.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/MockMultiClusterController.java
@@ -24,6 +24,7 @@ import java.util.List;
 import java.util.concurrent.CountDownLatch;
 
 import org.apache.helix.InstanceType;
+import org.apache.helix.api.id.StateModelDefId;
 import org.apache.helix.participant.DistClusterControllerStateModelFactory;
 import org.apache.helix.participant.StateMachineEngine;
 import org.apache.log4j.Logger;
@@ -64,7 +65,7 @@ public class MockMultiClusterController extends ZKHelixManager implements Runnab
       StateMachineEngine stateMach = getStateMachineEngine();
       DistClusterControllerStateModelFactory lsModelFactory =
           new DistClusterControllerStateModelFactory(_zkAddress);
-      stateMach.registerStateModelFactory("LeaderStandby", lsModelFactory);
+      stateMach.registerStateModelFactory(StateModelDefId.LeaderStandby, lsModelFactory);
 
       connect();
       _startCountDown.countDown();

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/manager/zk/MockParticipant.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/MockParticipant.java b/helix-core/src/test/java/org/apache/helix/manager/zk/MockParticipant.java
index f107d3d..3936680 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/MockParticipant.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/MockParticipant.java
@@ -24,6 +24,7 @@ import java.util.concurrent.CountDownLatch;
 
 import org.apache.helix.HelixConnection;
 import org.apache.helix.InstanceType;
+import org.apache.helix.api.id.StateModelDefId;
 import org.apache.helix.mock.participant.DummyProcess.DummyLeaderStandbyStateModelFactory;
 import org.apache.helix.mock.participant.DummyProcess.DummyOnlineOfflineStateModelFactory;
 import org.apache.helix.mock.participant.MockMSModelFactory;
@@ -72,17 +73,17 @@ public class MockParticipant extends ZKHelixManager implements Runnable {
   public void run() {
     try {
       StateMachineEngine stateMach = getStateMachineEngine();
-      stateMach.registerStateModelFactory("MasterSlave", _msModelFactory);
+      stateMach.registerStateModelFactory(StateModelDefId.MasterSlave, _msModelFactory);
 
       DummyLeaderStandbyStateModelFactory lsModelFactory =
           new DummyLeaderStandbyStateModelFactory(10);
       DummyOnlineOfflineStateModelFactory ofModelFactory =
           new DummyOnlineOfflineStateModelFactory(10);
-      stateMach.registerStateModelFactory("LeaderStandby", lsModelFactory);
-      stateMach.registerStateModelFactory("OnlineOffline", ofModelFactory);
+      stateMach.registerStateModelFactory(StateModelDefId.LeaderStandby, lsModelFactory);
+      stateMach.registerStateModelFactory(StateModelDefId.OnlineOffline, ofModelFactory);
 
       MockSchemataModelFactory schemataFactory = new MockSchemataModelFactory();
-      stateMach.registerStateModelFactory("STORAGE_DEFAULT_SM_SCHEMATA", schemataFactory);
+      stateMach.registerStateModelFactory(StateModelDefId.from("STORAGE_DEFAULT_SM_SCHEMATA"), schemataFactory);
 
       connect();
       _startCountDown.countDown();

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/manager/zk/TestDefaultControllerMsgHandlerFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestDefaultControllerMsgHandlerFactory.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestDefaultControllerMsgHandlerFactory.java
index 8b5b30c..aba12b4 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestDefaultControllerMsgHandlerFactory.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestDefaultControllerMsgHandlerFactory.java
@@ -20,14 +20,11 @@ package org.apache.helix.manager.zk;
  */
 
 import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
 
 import org.apache.helix.HelixException;
 import org.apache.helix.NotificationContext;
 import org.apache.helix.api.id.MessageId;
 import org.apache.helix.manager.zk.DefaultControllerMessageHandlerFactory.DefaultControllerMessageHandler;
-import org.apache.helix.messaging.handling.MessageHandler;
 import org.apache.helix.model.Message;
 import org.apache.helix.model.Message.MessageType;
 import org.apache.log4j.Logger;
@@ -49,7 +46,7 @@ public class TestDefaultControllerMsgHandlerFactory {
 
     boolean exceptionCaught = false;
     try {
-      MessageHandler handler = facotry.createHandler(message, context);
+      facotry.createHandler(message, context);
     } catch (HelixException e) {
       exceptionCaught = true;
     }
@@ -58,13 +55,12 @@ public class TestDefaultControllerMsgHandlerFactory {
     message = new Message(MessageType.CONTROLLER_MSG, MessageId.from("1"));
     exceptionCaught = false;
     try {
-      MessageHandler handler = facotry.createHandler(message, context);
+      facotry.createHandler(message, context);
     } catch (HelixException e) {
       exceptionCaught = true;
     }
     AssertJUnit.assertFalse(exceptionCaught);
 
-    Map<String, String> resultMap = new HashMap<String, String>();
     message = new Message(MessageType.NO_OP, MessageId.from("3"));
     DefaultControllerMessageHandler defaultHandler =
         new DefaultControllerMessageHandler(message, context);

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/messaging/TestAsyncCallbackSvc.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/messaging/TestAsyncCallbackSvc.java b/helix-core/src/test/java/org/apache/helix/messaging/TestAsyncCallbackSvc.java
index da686fe..f0b3507 100644
--- a/helix-core/src/test/java/org/apache/helix/messaging/TestAsyncCallbackSvc.java
+++ b/helix-core/src/test/java/org/apache/helix/messaging/TestAsyncCallbackSvc.java
@@ -20,10 +20,8 @@ package org.apache.helix.messaging;
  */
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.UUID;
 
 import org.apache.helix.HelixException;
@@ -62,9 +60,7 @@ public class TestAsyncCallbackSvc {
 
   }
 
-  @Test(groups = {
-    "unitTest"
-  })
+  @Test()
   public void testAsyncCallbackSvc() throws Exception {
     AsyncCallbackService svc = new AsyncCallbackService();
     HelixManager manager = new MockHelixManager();
@@ -73,14 +69,14 @@ public class TestAsyncCallbackSvc {
     Message msg = new Message(svc.getMessageType(), MessageId.from(UUID.randomUUID().toString()));
     msg.setTgtSessionId(SessionId.from(manager.getSessionId()));
     try {
-      MessageHandler aHandler = svc.createHandler(msg, changeContext);
+      svc.createHandler(msg, changeContext);
     } catch (HelixException e) {
       AssertJUnit.assertTrue(e.getMessage().indexOf(msg.getMessageId().stringify()) != -1);
     }
     Message msg2 = new Message("RandomType", MessageId.from(UUID.randomUUID().toString()));
     msg2.setTgtSessionId(SessionId.from(manager.getSessionId()));
     try {
-      MessageHandler aHandler = svc.createHandler(msg2, changeContext);
+      svc.createHandler(msg2, changeContext);
     } catch (HelixException e) {
       AssertJUnit.assertTrue(e.getMessage().indexOf(msg2.getMessageId().stringify()) != -1);
     }
@@ -88,7 +84,7 @@ public class TestAsyncCallbackSvc {
     msg3.setTgtSessionId(SessionId.from(manager.getSessionId()));
     msg3.setCorrelationId("wfwegw");
     try {
-      MessageHandler aHandler = svc.createHandler(msg3, changeContext);
+      svc.createHandler(msg3, changeContext);
     } catch (HelixException e) {
       AssertJUnit.assertTrue(e.getMessage().indexOf(msg3.getMessageId().stringify()) != -1);
     }
@@ -107,7 +103,6 @@ public class TestAsyncCallbackSvc {
     msg.setCorrelationId(corrId);
 
     MessageHandler aHandler = svc.createHandler(msg, changeContext);
-    Map<String, String> resultMap = new HashMap<String, String>();
     aHandler.handleMessage();
 
     AssertJUnit.assertTrue(callback.isDone());

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/mock/participant/DummyProcess.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/mock/participant/DummyProcess.java b/helix-core/src/test/java/org/apache/helix/mock/participant/DummyProcess.java
index 9880605..4b55935 100644
--- a/helix-core/src/test/java/org/apache/helix/mock/participant/DummyProcess.java
+++ b/helix-core/src/test/java/org/apache/helix/mock/participant/DummyProcess.java
@@ -32,11 +32,12 @@ import org.apache.helix.HelixManager;
 import org.apache.helix.HelixManagerFactory;
 import org.apache.helix.InstanceType;
 import org.apache.helix.NotificationContext;
+import org.apache.helix.api.StateTransitionHandlerFactory;
+import org.apache.helix.api.TransitionHandler;
 import org.apache.helix.api.id.PartitionId;
+import org.apache.helix.api.id.StateModelDefId;
 import org.apache.helix.model.Message;
 import org.apache.helix.participant.StateMachineEngine;
-import org.apache.helix.participant.statemachine.StateModel;
-import org.apache.helix.participant.statemachine.StateModelFactory;
 import org.apache.log4j.Logger;
 
 public class DummyProcess {
@@ -49,13 +50,11 @@ public class DummyProcess {
   public static final String help = "help";
   public static final String transDelay = "transDelay";
   public static final String helixManagerType = "helixManagerType";
-  // public static final String rootNamespace = "rootNamespace";
 
   private final String _zkConnectString;
   private final String _clusterName;
   private final String _instanceName;
   private DummyStateModelFactory stateModelFactory;
-  // private StateMachineEngine genericStateMachineHandler;
 
   private int _transDelayInMs = 0;
   private final String _clusterMangerType;
@@ -96,19 +95,16 @@ public class DummyProcess {
         new DummyLeaderStandbyStateModelFactory(_transDelayInMs);
     DummyOnlineOfflineStateModelFactory stateModelFactory2 =
         new DummyOnlineOfflineStateModelFactory(_transDelayInMs);
-    // genericStateMachineHandler = new StateMachineEngine();
     StateMachineEngine stateMach = manager.getStateMachineEngine();
-    stateMach.registerStateModelFactory("MasterSlave", stateModelFactory);
-    stateMach.registerStateModelFactory("LeaderStandby", stateModelFactory1);
-    stateMach.registerStateModelFactory("OnlineOffline", stateModelFactory2);
+    stateMach.registerStateModelFactory(StateModelDefId.MasterSlave, stateModelFactory);
+    stateMach.registerStateModelFactory(StateModelDefId.LeaderStandby, stateModelFactory1);
+    stateMach.registerStateModelFactory(StateModelDefId.OnlineOffline, stateModelFactory2);
 
     manager.connect();
-    // manager.getMessagingService().registerMessageHandlerFactory(MessageType.STATE_TRANSITION.toString(),
-    // genericStateMachineHandler);
     return manager;
   }
 
-  public static class DummyStateModelFactory extends StateModelFactory<DummyStateModel> {
+  public static class DummyStateModelFactory extends StateTransitionHandlerFactory<DummyStateModel> {
     int _delay;
 
     public DummyStateModelFactory(int delay) {
@@ -116,7 +112,7 @@ public class DummyProcess {
     }
 
     @Override
-    public DummyStateModel createNewStateModel(String stateUnitKey) {
+    public DummyStateModel createStateTransitionHandler(PartitionId partition) {
       DummyStateModel model = new DummyStateModel();
       model.setDelay(_delay);
       return model;
@@ -124,7 +120,7 @@ public class DummyProcess {
   }
 
   public static class DummyLeaderStandbyStateModelFactory extends
-      StateModelFactory<DummyLeaderStandbyStateModel> {
+      StateTransitionHandlerFactory<DummyLeaderStandbyStateModel> {
     int _delay;
 
     public DummyLeaderStandbyStateModelFactory(int delay) {
@@ -132,7 +128,7 @@ public class DummyProcess {
     }
 
     @Override
-    public DummyLeaderStandbyStateModel createNewStateModel(String stateUnitKey) {
+    public DummyLeaderStandbyStateModel createStateTransitionHandler(PartitionId partition) {
       DummyLeaderStandbyStateModel model = new DummyLeaderStandbyStateModel();
       model.setDelay(_delay);
       return model;
@@ -140,7 +136,7 @@ public class DummyProcess {
   }
 
   public static class DummyOnlineOfflineStateModelFactory extends
-      StateModelFactory<DummyOnlineOfflineStateModel> {
+      StateTransitionHandlerFactory<DummyOnlineOfflineStateModel> {
     int _delay;
 
     public DummyOnlineOfflineStateModelFactory(int delay) {
@@ -148,14 +144,14 @@ public class DummyProcess {
     }
 
     @Override
-    public DummyOnlineOfflineStateModel createNewStateModel(String stateUnitKey) {
+    public DummyOnlineOfflineStateModel createStateTransitionHandler(PartitionId partition) {
       DummyOnlineOfflineStateModel model = new DummyOnlineOfflineStateModel();
       model.setDelay(_delay);
       return model;
     }
   }
 
-  public static class DummyStateModel extends StateModel {
+  public static class DummyStateModel extends TransitionHandler {
     int _transDelay = 0;
 
     public void setDelay(int delay) {
@@ -200,7 +196,7 @@ public class DummyProcess {
     }
   }
 
-  public static class DummyOnlineOfflineStateModel extends StateModel {
+  public static class DummyOnlineOfflineStateModel extends TransitionHandler {
     int _transDelay = 0;
 
     public void setDelay(int delay) {
@@ -231,7 +227,7 @@ public class DummyProcess {
     }
   }
 
-  public static class DummyLeaderStandbyStateModel extends StateModel {
+  public static class DummyLeaderStandbyStateModel extends TransitionHandler {
     int _transDelay = 0;
 
     public void setDelay(int delay) {
@@ -353,7 +349,6 @@ public class DummyProcess {
   public static CommandLine processCommandLineArgs(String[] cliArgs) throws Exception {
     CommandLineParser cliParser = new GnuParser();
     Options cliOptions = constructCommandLineOptions();
-    // CommandLine cmd = null;
 
     try {
       return cliParser.parse(cliOptions, cliArgs);
@@ -371,8 +366,6 @@ public class DummyProcess {
     String zkConnectString = "localhost:2181";
     String clusterName = "testCluster";
     String instanceName = "localhost_8900";
-    String cvFileStr = null;
-    // String rootNs = null;
     int delay = 0;
 
     if (args.length > 0) {

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/mock/participant/MockBootstrapModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/mock/participant/MockBootstrapModelFactory.java b/helix-core/src/test/java/org/apache/helix/mock/participant/MockBootstrapModelFactory.java
index 177e7c4..0e01b60 100644
--- a/helix-core/src/test/java/org/apache/helix/mock/participant/MockBootstrapModelFactory.java
+++ b/helix-core/src/test/java/org/apache/helix/mock/participant/MockBootstrapModelFactory.java
@@ -1,5 +1,8 @@
 package org.apache.helix.mock.participant;
 
+import org.apache.helix.api.StateTransitionHandlerFactory;
+import org.apache.helix.api.id.PartitionId;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -19,12 +22,11 @@ package org.apache.helix.mock.participant;
  * under the License.
  */
 
-import org.apache.helix.participant.statemachine.StateModelFactory;
 
 // mock Bootstrap state model factory
-public class MockBootstrapModelFactory extends StateModelFactory<MockBootstrapStateModel> {
+public class MockBootstrapModelFactory extends StateTransitionHandlerFactory<MockBootstrapStateModel> {
   @Override
-  public MockBootstrapStateModel createNewStateModel(String partitionKey) {
+  public MockBootstrapStateModel createStateTransitionHandler(PartitionId partitionKey) {
     MockBootstrapStateModel model = new MockBootstrapStateModel();
     return model;
   }

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/mock/participant/MockBootstrapStateModel.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/mock/participant/MockBootstrapStateModel.java b/helix-core/src/test/java/org/apache/helix/mock/participant/MockBootstrapStateModel.java
index 79367db..ceb3442 100644
--- a/helix-core/src/test/java/org/apache/helix/mock/participant/MockBootstrapStateModel.java
+++ b/helix-core/src/test/java/org/apache/helix/mock/participant/MockBootstrapStateModel.java
@@ -20,8 +20,8 @@ package org.apache.helix.mock.participant;
  */
 
 import org.apache.helix.NotificationContext;
+import org.apache.helix.api.TransitionHandler;
 import org.apache.helix.model.Message;
-import org.apache.helix.participant.statemachine.StateModel;
 import org.apache.helix.participant.statemachine.StateModelInfo;
 import org.apache.helix.participant.statemachine.Transition;
 import org.apache.log4j.Logger;
@@ -30,7 +30,7 @@ import org.apache.log4j.Logger;
 @StateModelInfo(initialState = "OFFLINE", states = {
     "ONLINE", "BOOTSTRAP", "OFFLINE", "IDLE"
 })
-public class MockBootstrapStateModel extends StateModel {
+public class MockBootstrapStateModel extends TransitionHandler {
   private static Logger LOG = Logger.getLogger(MockBootstrapStateModel.class);
 
   // Overwrite the default value of intial state

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/mock/participant/MockMSModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/mock/participant/MockMSModelFactory.java b/helix-core/src/test/java/org/apache/helix/mock/participant/MockMSModelFactory.java
index 9325934..853b157 100644
--- a/helix-core/src/test/java/org/apache/helix/mock/participant/MockMSModelFactory.java
+++ b/helix-core/src/test/java/org/apache/helix/mock/participant/MockMSModelFactory.java
@@ -1,5 +1,8 @@
 package org.apache.helix.mock.participant;
 
+import org.apache.helix.api.StateTransitionHandlerFactory;
+import org.apache.helix.api.id.PartitionId;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -19,10 +22,9 @@ package org.apache.helix.mock.participant;
  * under the License.
  */
 
-import org.apache.helix.participant.statemachine.StateModelFactory;
 
 // mock master slave state model factory
-public class MockMSModelFactory extends StateModelFactory<MockMSStateModel> {
+public class MockMSModelFactory extends StateTransitionHandlerFactory<MockMSStateModel> {
   private MockTransition _transition;
 
   public MockMSModelFactory() {
@@ -37,14 +39,14 @@ public class MockMSModelFactory extends StateModelFactory<MockMSStateModel> {
     _transition = transition;
 
     // set existing transition
-    for (String partition : getPartitionSet()) {
-      MockMSStateModel stateModel = getStateModel(partition);
+    for (PartitionId partition : getPartitionSet()) {
+      MockMSStateModel stateModel = getTransitionHandler(partition);
       stateModel.setTransition(transition);
     }
   }
 
   @Override
-  public MockMSStateModel createNewStateModel(String partitionKey) {
+  public MockMSStateModel createStateTransitionHandler(PartitionId partitionKey) {
     MockMSStateModel model = new MockMSStateModel(_transition);
 
     return model;

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/mock/participant/MockMSStateModel.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/mock/participant/MockMSStateModel.java b/helix-core/src/test/java/org/apache/helix/mock/participant/MockMSStateModel.java
index 78d9832..18652cd 100644
--- a/helix-core/src/test/java/org/apache/helix/mock/participant/MockMSStateModel.java
+++ b/helix-core/src/test/java/org/apache/helix/mock/participant/MockMSStateModel.java
@@ -20,8 +20,8 @@ package org.apache.helix.mock.participant;
  */
 
 import org.apache.helix.NotificationContext;
+import org.apache.helix.api.TransitionHandler;
 import org.apache.helix.model.Message;
-import org.apache.helix.participant.statemachine.StateModel;
 import org.apache.helix.participant.statemachine.StateModelInfo;
 import org.apache.helix.participant.statemachine.Transition;
 import org.apache.log4j.Logger;
@@ -30,7 +30,7 @@ import org.apache.log4j.Logger;
 @StateModelInfo(initialState = "OFFLINE", states = {
     "MASTER", "SLAVE", "ERROR"
 })
-public class MockMSStateModel extends StateModel {
+public class MockMSStateModel extends TransitionHandler {
   private static Logger LOG = Logger.getLogger(MockMSStateModel.class);
 
   protected MockTransition _transition;

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/mock/participant/MockSchemataModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/mock/participant/MockSchemataModelFactory.java b/helix-core/src/test/java/org/apache/helix/mock/participant/MockSchemataModelFactory.java
index 525e764..7cc43ef 100644
--- a/helix-core/src/test/java/org/apache/helix/mock/participant/MockSchemataModelFactory.java
+++ b/helix-core/src/test/java/org/apache/helix/mock/participant/MockSchemataModelFactory.java
@@ -19,12 +19,15 @@ package org.apache.helix.mock.participant;
  * under the License.
  */
 
-import org.apache.helix.participant.statemachine.StateModelFactory;
+import org.apache.helix.api.StateTransitionHandlerFactory;
+import org.apache.helix.api.id.PartitionId;
 
-// mock STORAGE_DEFAULT_SM_SCHEMATA state model factory
-public class MockSchemataModelFactory extends StateModelFactory<MockSchemataStateModel> {
+/**
+ * Mock STORAGE_DEFAULT_SM_SCHEMATA state model factory
+ */
+public class MockSchemataModelFactory extends StateTransitionHandlerFactory<MockSchemataStateModel> {
   @Override
-  public MockSchemataStateModel createNewStateModel(String partitionKey) {
+  public MockSchemataStateModel createStateTransitionHandler(PartitionId partitionKey) {
     MockSchemataStateModel model = new MockSchemataStateModel();
     return model;
   }

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/mock/participant/MockSchemataStateModel.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/mock/participant/MockSchemataStateModel.java b/helix-core/src/test/java/org/apache/helix/mock/participant/MockSchemataStateModel.java
index c3c1fa5..e3c9844 100644
--- a/helix-core/src/test/java/org/apache/helix/mock/participant/MockSchemataStateModel.java
+++ b/helix-core/src/test/java/org/apache/helix/mock/participant/MockSchemataStateModel.java
@@ -20,8 +20,8 @@ package org.apache.helix.mock.participant;
  */
 
 import org.apache.helix.NotificationContext;
+import org.apache.helix.api.TransitionHandler;
 import org.apache.helix.model.Message;
-import org.apache.helix.participant.statemachine.StateModel;
 import org.apache.helix.participant.statemachine.StateModelInfo;
 import org.apache.helix.participant.statemachine.Transition;
 import org.apache.log4j.Logger;
@@ -30,7 +30,7 @@ import org.apache.log4j.Logger;
 @StateModelInfo(initialState = "OFFLINE", states = {
     "MASTER", "DROPPED", "ERROR"
 })
-public class MockSchemataStateModel extends StateModel {
+public class MockSchemataStateModel extends TransitionHandler {
   private static Logger LOG = Logger.getLogger(MockSchemataStateModel.class);
 
   @Transition(to = "MASTER", from = "OFFLINE")

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/model/TestConstraint.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/model/TestConstraint.java b/helix-core/src/test/java/org/apache/helix/model/TestConstraint.java
index 6f78427..6a3ccd9 100644
--- a/helix-core/src/test/java/org/apache/helix/model/TestConstraint.java
+++ b/helix-core/src/test/java/org/apache/helix/model/TestConstraint.java
@@ -107,7 +107,7 @@ public class TestConstraint extends ZkTestBase {
     ConstraintItem constraint5 = new ConstraintItem(record.getMapField("constraint5"));
 
     ZKHelixDataAccessor accessor =
-        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_zkclient));
+        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkclient));
     Builder keyBuilder = accessor.keyBuilder();
 
     accessor.setProperty(keyBuilder.constraint(ConstraintType.MESSAGE_CONSTRAINT.toString()),

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java b/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
index efa30da..3efbffb 100644
--- a/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
+++ b/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
@@ -58,7 +58,7 @@ public class MockZKHelixManager implements HelixManager {
     _instanceName = instanceName;
     _clusterName = clusterName;
     _type = type;
-    _accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient));
+    _accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModelFactory.java b/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModelFactory.java
index 26d65f0..7055500 100644
--- a/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModelFactory.java
+++ b/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModelFactory.java
@@ -19,6 +19,7 @@ package org.apache.helix.participant;
  * under the License.
  */
 
+import org.apache.helix.api.id.PartitionId;
 import org.testng.annotations.Test;
 
 public class TestDistControllerStateModelFactory {
@@ -27,7 +28,7 @@ public class TestDistControllerStateModelFactory {
   public void testDistControllerStateModelFactory() {
     DistClusterControllerStateModelFactory factory =
         new DistClusterControllerStateModelFactory("localhost:2181");
-    DistClusterControllerStateModel stateModel = factory.createNewStateModel("key");
+    DistClusterControllerStateModel stateModel = factory.createStateTransitionHandler(PartitionId.from("key"));
     stateModel.onBecomeStandbyFromOffline(null, null);
   }
 }

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-core/src/test/java/org/apache/helix/participant/statemachine/TestStateModelParser.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/participant/statemachine/TestStateModelParser.java b/helix-core/src/test/java/org/apache/helix/participant/statemachine/TestStateModelParser.java
index 7c128fb..d6968f5 100644
--- a/helix-core/src/test/java/org/apache/helix/participant/statemachine/TestStateModelParser.java
+++ b/helix-core/src/test/java/org/apache/helix/participant/statemachine/TestStateModelParser.java
@@ -22,6 +22,7 @@ package org.apache.helix.participant.statemachine;
 import java.lang.reflect.Method;
 
 import org.apache.helix.NotificationContext;
+import org.apache.helix.api.TransitionHandler;
 import org.apache.helix.model.Message;
 import org.apache.log4j.Logger;
 import org.testng.Assert;
@@ -34,7 +35,7 @@ public class TestStateModelParser {
   @StateModelInfo(initialState = "OFFLINE", states = {
       "MASTER", "SLAVE", "ERROR"
   })
-  class StateModelUsingAnnotation extends StateModel {
+  class StateModelUsingAnnotation extends TransitionHandler {
     @Transition(to = "SLAVE", from = "OFFLINE")
     public void onBecomeSlaveFromOffline(Message message, NotificationContext context) {
       LOG.info("Become SLAVE from OFFLINE");
@@ -58,7 +59,7 @@ public class TestStateModelParser {
     }
   }
 
-  class StateModelUsingNameConvention extends StateModel {
+  class StateModelUsingNameConvention extends TransitionHandler {
     // empty state model
   }
 

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-examples/src/main/java/org/apache/helix/examples/BootstrapHandler.java
----------------------------------------------------------------------
diff --git a/helix-examples/src/main/java/org/apache/helix/examples/BootstrapHandler.java b/helix-examples/src/main/java/org/apache/helix/examples/BootstrapHandler.java
index f0922f3..d4b2817 100644
--- a/helix-examples/src/main/java/org/apache/helix/examples/BootstrapHandler.java
+++ b/helix-examples/src/main/java/org/apache/helix/examples/BootstrapHandler.java
@@ -26,30 +26,27 @@ import org.apache.helix.Criteria;
 import org.apache.helix.HelixManager;
 import org.apache.helix.InstanceType;
 import org.apache.helix.NotificationContext;
+import org.apache.helix.api.StateTransitionHandlerFactory;
+import org.apache.helix.api.TransitionHandler;
 import org.apache.helix.api.id.MessageId;
+import org.apache.helix.api.id.PartitionId;
 import org.apache.helix.model.Message;
 import org.apache.helix.model.Message.MessageState;
 import org.apache.helix.model.Message.MessageType;
-import org.apache.helix.participant.statemachine.StateModel;
-import org.apache.helix.participant.statemachine.StateModelFactory;
 import org.apache.helix.participant.statemachine.StateModelInfo;
 import org.apache.helix.participant.statemachine.Transition;
 
-public class BootstrapHandler extends StateModelFactory<StateModel> {
+public class BootstrapHandler extends StateTransitionHandlerFactory<TransitionHandler> {
 
   @Override
-  public StateModel createNewStateModel(String stateUnitKey) {
+  public TransitionHandler createStateTransitionHandler(PartitionId stateUnitKey) {
     return new BootstrapStateModel(stateUnitKey);
   }
 
   @StateModelInfo(initialState = "OFFLINE", states = "{'OFFLINE','SLAVE','MASTER'}")
-  public static class BootstrapStateModel extends StateModel {
-
-    private final String _stateUnitKey;
-
-    public BootstrapStateModel(String stateUnitKey) {
-      _stateUnitKey = stateUnitKey;
+  public static class BootstrapStateModel extends TransitionHandler {
 
+    public BootstrapStateModel(PartitionId stateUnitKey) {
     }
 
     @Transition(from = "MASTER", to = "SLAVE")

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-examples/src/main/java/org/apache/helix/examples/BootstrapProcess.java
----------------------------------------------------------------------
diff --git a/helix-examples/src/main/java/org/apache/helix/examples/BootstrapProcess.java b/helix-examples/src/main/java/org/apache/helix/examples/BootstrapProcess.java
index 2506c01..337c484 100644
--- a/helix-examples/src/main/java/org/apache/helix/examples/BootstrapProcess.java
+++ b/helix-examples/src/main/java/org/apache/helix/examples/BootstrapProcess.java
@@ -36,6 +36,9 @@ import org.apache.helix.HelixManager;
 import org.apache.helix.HelixManagerFactory;
 import org.apache.helix.InstanceType;
 import org.apache.helix.NotificationContext;
+import org.apache.helix.api.StateTransitionHandlerFactory;
+import org.apache.helix.api.TransitionHandler;
+import org.apache.helix.api.id.StateModelDefId;
 import org.apache.helix.messaging.AsyncCallback;
 import org.apache.helix.messaging.handling.HelixTaskResult;
 import org.apache.helix.messaging.handling.MessageHandler;
@@ -43,8 +46,6 @@ import org.apache.helix.messaging.handling.MessageHandlerFactory;
 import org.apache.helix.model.Message;
 import org.apache.helix.model.Message.MessageType;
 import org.apache.helix.participant.StateMachineEngine;
-import org.apache.helix.participant.statemachine.StateModel;
-import org.apache.helix.participant.statemachine.StateModelFactory;
 
 /**
  * This process does little more than handling the state transition messages.
@@ -77,21 +78,15 @@ public class BootstrapProcess {
   private final String zkConnectString;
   private final String clusterName;
   private final String instanceName;
-  private final String stateModelType;
   private HelixManager manager;
 
-  // private StateMachineEngine genericStateMachineHandler;
-
-  private StateModelFactory<StateModel> stateModelFactory;
-  private final int delay;
+  private StateTransitionHandlerFactory<TransitionHandler> stateModelFactory;
 
   public BootstrapProcess(String zkConnectString, String clusterName, String instanceName,
       String stateModel, int delay) {
     this.zkConnectString = zkConnectString;
     this.clusterName = clusterName;
     this.instanceName = instanceName;
-    stateModelType = stateModel;
-    this.delay = delay;
   }
 
   public void start() throws Exception {
@@ -100,11 +95,9 @@ public class BootstrapProcess {
             zkConnectString);
 
     stateModelFactory = new BootstrapHandler();
-    // genericStateMachineHandler = new StateMachineEngine();
-    // genericStateMachineHandler.registerStateModelFactory("MasterSlave", stateModelFactory);
 
     StateMachineEngine stateMach = manager.getStateMachineEngine();
-    stateMach.registerStateModelFactory("MasterSlave", stateModelFactory);
+    stateMach.registerStateModelFactory(StateModelDefId.MasterSlave, stateModelFactory);
 
     manager.getMessagingService().registerMessageHandlerFactory(
         MessageType.STATE_TRANSITION.toString(), stateMach);

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-examples/src/main/java/org/apache/helix/examples/DummyParticipant.java
----------------------------------------------------------------------
diff --git a/helix-examples/src/main/java/org/apache/helix/examples/DummyParticipant.java b/helix-examples/src/main/java/org/apache/helix/examples/DummyParticipant.java
index c6ab3a4..7dcdd8a 100644
--- a/helix-examples/src/main/java/org/apache/helix/examples/DummyParticipant.java
+++ b/helix-examples/src/main/java/org/apache/helix/examples/DummyParticipant.java
@@ -23,11 +23,12 @@ import org.apache.helix.HelixManager;
 import org.apache.helix.HelixManagerFactory;
 import org.apache.helix.InstanceType;
 import org.apache.helix.NotificationContext;
+import org.apache.helix.api.StateTransitionHandlerFactory;
+import org.apache.helix.api.TransitionHandler;
 import org.apache.helix.api.id.PartitionId;
+import org.apache.helix.api.id.StateModelDefId;
 import org.apache.helix.model.Message;
 import org.apache.helix.participant.StateMachineEngine;
-import org.apache.helix.participant.statemachine.StateModel;
-import org.apache.helix.participant.statemachine.StateModelFactory;
 import org.apache.helix.participant.statemachine.StateModelInfo;
 import org.apache.helix.participant.statemachine.Transition;
 
@@ -36,7 +37,7 @@ public class DummyParticipant {
   @StateModelInfo(initialState = "OFFLINE", states = {
       "MASTER", "SLAVE", "ERROR"
   })
-  public static class DummyMSStateModel extends StateModel {
+  public static class DummyMSStateModel extends TransitionHandler {
     @Transition(to = "SLAVE", from = "OFFLINE")
     public void onBecomeSlaveFromOffline(Message message, NotificationContext context) {
       PartitionId partitionId = message.getPartitionId();
@@ -86,9 +87,9 @@ public class DummyParticipant {
   }
 
   // dummy master slave state model factory
-  public static class DummyMSModelFactory extends StateModelFactory<DummyMSStateModel> {
+  public static class DummyMSModelFactory extends StateTransitionHandlerFactory<DummyMSStateModel> {
     @Override
-    public DummyMSStateModel createNewStateModel(String partitionName) {
+    public DummyMSStateModel createStateTransitionHandler(PartitionId partitionName) {
       DummyMSStateModel model = new DummyMSStateModel();
       return model;
     }
@@ -112,7 +113,7 @@ public class DummyParticipant {
 
       StateMachineEngine stateMach = manager.getStateMachineEngine();
       DummyMSModelFactory msModelFactory = new DummyMSModelFactory();
-      stateMach.registerStateModelFactory("MasterSlave", msModelFactory);
+      stateMach.registerStateModelFactory(StateModelDefId.MasterSlave, msModelFactory);
 
       manager.connect();
 

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-examples/src/main/java/org/apache/helix/examples/ExampleProcess.java
----------------------------------------------------------------------
diff --git a/helix-examples/src/main/java/org/apache/helix/examples/ExampleProcess.java b/helix-examples/src/main/java/org/apache/helix/examples/ExampleProcess.java
index 840a963..ac19a27 100644
--- a/helix-examples/src/main/java/org/apache/helix/examples/ExampleProcess.java
+++ b/helix-examples/src/main/java/org/apache/helix/examples/ExampleProcess.java
@@ -33,11 +33,12 @@ import org.apache.commons.cli.ParseException;
 import org.apache.helix.HelixManager;
 import org.apache.helix.HelixManagerFactory;
 import org.apache.helix.InstanceType;
+import org.apache.helix.api.StateTransitionHandlerFactory;
+import org.apache.helix.api.TransitionHandler;
+import org.apache.helix.api.id.StateModelDefId;
 import org.apache.helix.manager.zk.HelixManagerShutdownHook;
 import org.apache.helix.model.Message.MessageType;
 import org.apache.helix.participant.StateMachineEngine;
-import org.apache.helix.participant.statemachine.StateModel;
-import org.apache.helix.participant.statemachine.StateModelFactory;
 import org.apache.log4j.Logger;
 
 public class ExampleProcess {
@@ -59,7 +60,7 @@ public class ExampleProcess {
   private final String stateModelType;
   private HelixManager manager;
 
-  private StateModelFactory<StateModel> stateModelFactory;
+  private StateTransitionHandlerFactory<TransitionHandler> stateModelFactory;
   private final int delay;
 
   public ExampleProcess(String zkConnectString, String clusterName, String instanceName,
@@ -83,12 +84,9 @@ public class ExampleProcess {
     } else if ("LeaderStandby".equalsIgnoreCase(stateModelType)) {
       stateModelFactory = new LeaderStandbyStateModelFactory(delay);
     }
-    // genericStateMachineHandler = new StateMachineEngine();
-    // genericStateMachineHandler.registerStateModelFactory(stateModelType,
-    // stateModelFactory);
 
     StateMachineEngine stateMach = manager.getStateMachineEngine();
-    stateMach.registerStateModelFactory(stateModelType, stateModelFactory);
+    stateMach.registerStateModelFactory(StateModelDefId.from(stateModelType), stateModelFactory);
     manager.connect();
     manager.getMessagingService().registerMessageHandlerFactory(
         MessageType.STATE_TRANSITION.toString(), stateMach);

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-examples/src/main/java/org/apache/helix/examples/LeaderStandbyStateModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-examples/src/main/java/org/apache/helix/examples/LeaderStandbyStateModelFactory.java b/helix-examples/src/main/java/org/apache/helix/examples/LeaderStandbyStateModelFactory.java
index 43ac5de..74027d4 100644
--- a/helix-examples/src/main/java/org/apache/helix/examples/LeaderStandbyStateModelFactory.java
+++ b/helix-examples/src/main/java/org/apache/helix/examples/LeaderStandbyStateModelFactory.java
@@ -20,11 +20,12 @@ package org.apache.helix.examples;
  */
 
 import org.apache.helix.NotificationContext;
+import org.apache.helix.api.StateTransitionHandlerFactory;
+import org.apache.helix.api.TransitionHandler;
+import org.apache.helix.api.id.PartitionId;
 import org.apache.helix.model.Message;
-import org.apache.helix.participant.statemachine.StateModel;
-import org.apache.helix.participant.statemachine.StateModelFactory;
 
-public class LeaderStandbyStateModelFactory extends StateModelFactory<StateModel> {
+public class LeaderStandbyStateModelFactory extends StateTransitionHandlerFactory<TransitionHandler> {
   int _delay;
 
   public LeaderStandbyStateModelFactory(int delay) {
@@ -32,13 +33,13 @@ public class LeaderStandbyStateModelFactory extends StateModelFactory<StateModel
   }
 
   @Override
-  public StateModel createNewStateModel(String stateUnitKey) {
+  public TransitionHandler createStateTransitionHandler(PartitionId stateUnitKey) {
     LeaderStandbyStateModel stateModel = new LeaderStandbyStateModel();
     stateModel.setDelay(_delay);
     return stateModel;
   }
 
-  public static class LeaderStandbyStateModel extends StateModel {
+  public static class LeaderStandbyStateModel extends TransitionHandler {
     int _transDelay = 0;
 
     public void setDelay(int delay) {

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-examples/src/main/java/org/apache/helix/examples/LogicalModelExample.java
----------------------------------------------------------------------
diff --git a/helix-examples/src/main/java/org/apache/helix/examples/LogicalModelExample.java b/helix-examples/src/main/java/org/apache/helix/examples/LogicalModelExample.java
index 6075d22..2ac5d37 100644
--- a/helix-examples/src/main/java/org/apache/helix/examples/LogicalModelExample.java
+++ b/helix-examples/src/main/java/org/apache/helix/examples/LogicalModelExample.java
@@ -10,6 +10,8 @@ import org.apache.helix.NotificationContext;
 import org.apache.helix.api.Cluster;
 import org.apache.helix.api.Scope;
 import org.apache.helix.api.State;
+import org.apache.helix.api.StateTransitionHandlerFactory;
+import org.apache.helix.api.TransitionHandler;
 import org.apache.helix.api.accessor.ClusterAccessor;
 import org.apache.helix.api.config.ClusterConfig;
 import org.apache.helix.api.config.ParticipantConfig;
@@ -27,8 +29,6 @@ import org.apache.helix.model.Message;
 import org.apache.helix.model.StateModelDefinition;
 import org.apache.helix.model.Transition;
 import org.apache.helix.model.builder.AutoRebalanceModeISBuilder;
-import org.apache.helix.participant.statemachine.HelixStateModelFactory;
-import org.apache.helix.participant.statemachine.StateModel;
 import org.apache.helix.participant.statemachine.StateModelInfo;
 import org.apache.log4j.Logger;
 
@@ -240,7 +240,7 @@ public class LogicalModelExample {
    * Dummy state model that just prints state transitions for the lock-unlock model
    */
   @StateModelInfo(initialState = "OFFLINE", states = { "LOCKED", "RELEASED", "DROPPED", "ERROR" })
-  public static class LockUnlockStateModel extends StateModel {
+  public static class LockUnlockStateModel extends TransitionHandler {
     private final PartitionId _partitionId;
 
     /**
@@ -272,9 +272,9 @@ public class LogicalModelExample {
   /**
    * State model factory for lock-unlock
    */
-  public static class LockUnlockFactory extends HelixStateModelFactory<LockUnlockStateModel> {
+  public static class LockUnlockFactory extends StateTransitionHandlerFactory<LockUnlockStateModel> {
     @Override
-    public LockUnlockStateModel createNewStateModel(PartitionId partitionId) {
+    public LockUnlockStateModel createStateTransitionHandler(PartitionId partitionId) {
       return new LockUnlockStateModel(partitionId);
     }
   }

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-examples/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-examples/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java b/helix-examples/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java
index 71d1412..2befd61 100644
--- a/helix-examples/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java
+++ b/helix-examples/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java
@@ -20,11 +20,12 @@ package org.apache.helix.examples;
  */
 
 import org.apache.helix.NotificationContext;
+import org.apache.helix.api.StateTransitionHandlerFactory;
+import org.apache.helix.api.TransitionHandler;
+import org.apache.helix.api.id.PartitionId;
 import org.apache.helix.model.Message;
-import org.apache.helix.participant.statemachine.StateModel;
-import org.apache.helix.participant.statemachine.StateModelFactory;
 
-public class MasterSlaveStateModelFactory extends StateModelFactory<StateModel> {
+public class MasterSlaveStateModelFactory extends StateTransitionHandlerFactory<TransitionHandler> {
   int _delay;
 
   String _instanceName = "";
@@ -43,15 +44,15 @@ public class MasterSlaveStateModelFactory extends StateModelFactory<StateModel>
   }
 
   @Override
-  public StateModel createNewStateModel(String partitionName) {
+  public TransitionHandler createStateTransitionHandler(PartitionId partitionName) {
     MasterSlaveStateModel stateModel = new MasterSlaveStateModel();
     stateModel.setInstanceName(_instanceName);
     stateModel.setDelay(_delay);
-    stateModel.setPartitionName(partitionName);
+    stateModel.setPartitionName(partitionName.stringify());
     return stateModel;
   }
 
-  public static class MasterSlaveStateModel extends StateModel {
+  public static class MasterSlaveStateModel extends TransitionHandler {
     int _transDelay = 0;
     String partitionName;
     String _instanceName = "";

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-examples/src/main/java/org/apache/helix/examples/OnlineOfflineStateModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-examples/src/main/java/org/apache/helix/examples/OnlineOfflineStateModelFactory.java b/helix-examples/src/main/java/org/apache/helix/examples/OnlineOfflineStateModelFactory.java
index daf03a9..f6fb2fa 100644
--- a/helix-examples/src/main/java/org/apache/helix/examples/OnlineOfflineStateModelFactory.java
+++ b/helix-examples/src/main/java/org/apache/helix/examples/OnlineOfflineStateModelFactory.java
@@ -20,11 +20,12 @@ package org.apache.helix.examples;
  */
 
 import org.apache.helix.NotificationContext;
+import org.apache.helix.api.StateTransitionHandlerFactory;
+import org.apache.helix.api.TransitionHandler;
+import org.apache.helix.api.id.PartitionId;
 import org.apache.helix.model.Message;
-import org.apache.helix.participant.statemachine.StateModel;
-import org.apache.helix.participant.statemachine.StateModelFactory;
 
-public class OnlineOfflineStateModelFactory extends StateModelFactory<StateModel> {
+public class OnlineOfflineStateModelFactory extends StateTransitionHandlerFactory<TransitionHandler> {
   int _delay;
 
   public OnlineOfflineStateModelFactory(int delay) {
@@ -32,13 +33,13 @@ public class OnlineOfflineStateModelFactory extends StateModelFactory<StateModel
   }
 
   @Override
-  public StateModel createNewStateModel(String stateUnitKey) {
+  public TransitionHandler createStateTransitionHandler(PartitionId stateUnitKey) {
     OnlineOfflineStateModel stateModel = new OnlineOfflineStateModel();
     stateModel.setDelay(_delay);
     return stateModel;
   }
 
-  public static class OnlineOfflineStateModel extends StateModel {
+  public static class OnlineOfflineStateModel extends TransitionHandler {
     int _transDelay = 0;
 
     public void setDelay(int delay) {

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-examples/src/main/java/org/apache/helix/examples/Quickstart.java
----------------------------------------------------------------------
diff --git a/helix-examples/src/main/java/org/apache/helix/examples/Quickstart.java b/helix-examples/src/main/java/org/apache/helix/examples/Quickstart.java
index 2f3a677..d0d881e 100644
--- a/helix-examples/src/main/java/org/apache/helix/examples/Quickstart.java
+++ b/helix-examples/src/main/java/org/apache/helix/examples/Quickstart.java
@@ -252,7 +252,7 @@ public class Quickstart {
           new MasterSlaveStateModelFactory(instanceName);
 
       StateMachineEngine stateMach = manager.getStateMachineEngine();
-      stateMach.registerStateModelFactory(STATE_MODEL_NAME.stringify(), stateModelFactory);
+      stateMach.registerStateModelFactory(STATE_MODEL_NAME, stateModelFactory);
       manager.connect();
     }
 

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-provisioning/src/main/java/org/apache/helix/provisioning/participant/StatelessServiceStateModel.java
----------------------------------------------------------------------
diff --git a/helix-provisioning/src/main/java/org/apache/helix/provisioning/participant/StatelessServiceStateModel.java b/helix-provisioning/src/main/java/org/apache/helix/provisioning/participant/StatelessServiceStateModel.java
index f653de8..c179b6c 100644
--- a/helix-provisioning/src/main/java/org/apache/helix/provisioning/participant/StatelessServiceStateModel.java
+++ b/helix-provisioning/src/main/java/org/apache/helix/provisioning/participant/StatelessServiceStateModel.java
@@ -20,9 +20,9 @@ package org.apache.helix.provisioning.participant;
  */
 
 import org.apache.helix.NotificationContext;
+import org.apache.helix.api.TransitionHandler;
 import org.apache.helix.api.id.PartitionId;
 import org.apache.helix.model.Message;
-import org.apache.helix.participant.statemachine.StateModel;
 import org.apache.helix.participant.statemachine.StateModelInfo;
 import org.apache.helix.participant.statemachine.Transition;
 import org.apache.log4j.Logger;
@@ -30,7 +30,7 @@ import org.apache.log4j.Logger;
 @StateModelInfo(initialState = "OFFLINE", states = {
     "OFFLINE", "ONLINE", "ERROR"
 })
-public class StatelessServiceStateModel extends StateModel {
+public class StatelessServiceStateModel extends TransitionHandler {
   private static final Logger LOG = Logger.getLogger(StatelessServiceStateModel.class);
 
   private final StatelessParticipantService _service;

http://git-wip-us.apache.org/repos/asf/helix/blob/4ae1ff79/helix-provisioning/src/main/java/org/apache/helix/provisioning/participant/StatelessServiceStateModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-provisioning/src/main/java/org/apache/helix/provisioning/participant/StatelessServiceStateModelFactory.java b/helix-provisioning/src/main/java/org/apache/helix/provisioning/participant/StatelessServiceStateModelFactory.java
index 19c1488..21f32ce 100644
--- a/helix-provisioning/src/main/java/org/apache/helix/provisioning/participant/StatelessServiceStateModelFactory.java
+++ b/helix-provisioning/src/main/java/org/apache/helix/provisioning/participant/StatelessServiceStateModelFactory.java
@@ -19,11 +19,11 @@ package org.apache.helix.provisioning.participant;
  * under the License.
  */
 
+import org.apache.helix.api.StateTransitionHandlerFactory;
 import org.apache.helix.api.id.PartitionId;
-import org.apache.helix.participant.statemachine.HelixStateModelFactory;
 
 public class StatelessServiceStateModelFactory extends
-    HelixStateModelFactory<StatelessServiceStateModel> {
+    StateTransitionHandlerFactory<StatelessServiceStateModel> {
 
   private final StatelessParticipantService _service;
 
@@ -32,7 +32,7 @@ public class StatelessServiceStateModelFactory extends
   }
 
   @Override
-  public StatelessServiceStateModel createNewStateModel(PartitionId partitionId) {
+  public StatelessServiceStateModel createStateTransitionHandler(PartitionId partitionId) {
     return new StatelessServiceStateModel(partitionId, _service);
   }