helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject [03/33] helix git commit: Fix the statemodelFactories in Example Process.
Date Wed, 17 Aug 2016 04:26:59 GMT
Fix the statemodelFactories in Example Process.


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

Branch: refs/heads/helix-0.6.x
Commit: 37819298939b61d8f7a589a3404fd3414fbdbd06
Parents: 03b9001
Author: Lei Xia <lxia@linkedin.com>
Authored: Wed Jan 27 18:04:23 2016 -0800
Committer: Lei Xia <lxia@linkedin.com>
Committed: Tue Jul 5 14:34:37 2016 -0700

----------------------------------------------------------------------
 .../apache/helix/examples/ExampleProcess.java   |  6 +-
 .../LeaderStandbyStateModelFactory.java         | 69 ++++++++++++++++++--
 .../examples/MasterSlaveStateModelFactory.java  |  7 +-
 .../OnlineOfflineStateModelFactory.java         | 37 +++++++++--
 4 files changed, 106 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/37819298/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java b/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java
index 840a963..9328cf4 100644
--- a/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java
+++ b/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java
@@ -77,11 +77,11 @@ public class ExampleProcess {
             zkConnectString);
 
     if ("MasterSlave".equalsIgnoreCase(stateModelType)) {
-      stateModelFactory = new MasterSlaveStateModelFactory(delay);
+      stateModelFactory = new MasterSlaveStateModelFactory(this.instanceName, delay);
     } else if ("OnlineOffline".equalsIgnoreCase(stateModelType)) {
-      stateModelFactory = new OnlineOfflineStateModelFactory(delay);
+      stateModelFactory = new OnlineOfflineStateModelFactory(this.instanceName, delay);
     } else if ("LeaderStandby".equalsIgnoreCase(stateModelType)) {
-      stateModelFactory = new LeaderStandbyStateModelFactory(delay);
+      stateModelFactory = new LeaderStandbyStateModelFactory(this.instanceName, delay);
     }
     // genericStateMachineHandler = new StateMachineEngine();
     // genericStateMachineHandler.registerStateModelFactory(stateModelType,

http://git-wip-us.apache.org/repos/asf/helix/blob/37819298/helix-core/src/main/java/org/apache/helix/examples/LeaderStandbyStateModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/examples/LeaderStandbyStateModelFactory.java
b/helix-core/src/main/java/org/apache/helix/examples/LeaderStandbyStateModelFactory.java
index c0fff7c..a2ca091 100644
--- a/helix-core/src/main/java/org/apache/helix/examples/LeaderStandbyStateModelFactory.java
+++ b/helix-core/src/main/java/org/apache/helix/examples/LeaderStandbyStateModelFactory.java
@@ -26,35 +26,96 @@ import org.apache.helix.participant.statemachine.StateModelFactory;
 
 public class LeaderStandbyStateModelFactory extends StateModelFactory<StateModel> {
   int _delay;
+  String _instanceName = "";
 
   public LeaderStandbyStateModelFactory(int delay) {
     _delay = delay;
   }
 
-  @Override
-  public StateModel createNewStateModel(String resourceName, String stateUnitKey) {
+  public LeaderStandbyStateModelFactory(String instanceName) {
+    _instanceName = instanceName;
+    _delay = 10;
+  }
+
+  public LeaderStandbyStateModelFactory(String instanceName, int delay) {
+    _instanceName = instanceName;
+    _delay = delay;
+  }
+
+  public LeaderStandbyStateModelFactory() {
+    this(10);
+  }
+
+  public void setInstanceName(String instanceName) {
+    _instanceName = instanceName;
+  }
+
+  @Override public StateModel createNewStateModel(String resourceName, String partitionName)
{
     LeaderStandbyStateModel stateModel = new LeaderStandbyStateModel();
     stateModel.setDelay(_delay);
+    stateModel.setInstanceName(_instanceName);
+    stateModel.setPartitionName(partitionName);
     return stateModel;
   }
 
   public static class LeaderStandbyStateModel extends StateModel {
     int _transDelay = 0;
+    String partitionName;
+    String _instanceName = "";
+
+    public String getPartitionName() {
+      return partitionName;
+    }
+
+    public void setPartitionName(String partitionName) {
+      this.partitionName = partitionName;
+    }
+
+    public void setInstanceName(String instanceName) {
+      _instanceName = instanceName;
+    }
+
 
     public void setDelay(int delay) {
       _transDelay = delay > 0 ? delay : 0;
     }
 
     public void onBecomeLeaderFromStandby(Message message, NotificationContext context) {
-      System.out.println("LeaderStandbyStateModel.onBecomeLeaderFromStandby()");
+      System.out.println("LeaderStandbyStateModel.onBecomeLeaderFromStandby():" + _instanceName
+          + " transitioning from " + message.getFromState() + " to " + message.getToState()
+          + " for " + message.getResourceName() + " " + message.getPartitionName());
       sleep();
     }
 
     public void onBecomeStandbyFromLeader(Message message, NotificationContext context) {
-      System.out.println("LeaderStandbyStateModel.onBecomeStandbyFromLeader()");
+      System.out.println("LeaderStandbyStateModel.onBecomeStandbyFromLeader():" + _instanceName
+          + " transitioning from " + message.getFromState() + " to " + message.getToState()
+          + " for " + message.getResourceName() + " " + message.getPartitionName());
       sleep();
     }
 
+    public void onBecomeStandbyFromOffline(Message message, NotificationContext context)
{
+      System.out.println("LeaderStandbyStateModel.onBecomeStandbyFromOffline():" + _instanceName
+          + " transitioning from " + message.getFromState() + " to " + message.getToState()
+          + " for " + message.getResourceName() + " " + message.getPartitionName());
+      sleep();
+    }
+
+    public void onBecomeOfflineFromStandby(Message message, NotificationContext context)
{
+      System.out.println("LeaderStandbyStateModel.onBecomeOfflineFromStandby():" + _instanceName
+          + " transitioning from " + message.getFromState() + " to " + message.getToState()
+          + " for " + message.getResourceName() + " " + message.getPartitionName());
+      sleep();
+    }
+
+    public void onBecomeDroppedFromOffline(Message message, NotificationContext context)
{
+      System.out.println("LeaderStandbyStateModel.onBecomeDroppedFromOffline():" + _instanceName
+          + " transitioning from " + message.getFromState() + " to " + message.getToState()
+          + " for " + message.getResourceName() + " " + message.getPartitionName());
+      sleep();
+
+    }
+
     private void sleep() {
       try {
         Thread.sleep(_transDelay);

http://git-wip-us.apache.org/repos/asf/helix/blob/37819298/helix-core/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java
b/helix-core/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java
index 85d90b2..1d5e790 100644
--- a/helix-core/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java
+++ b/helix-core/src/main/java/org/apache/helix/examples/MasterSlaveStateModelFactory.java
@@ -27,7 +27,6 @@ import org.apache.helix.participant.statemachine.StateModelFactory;
 @SuppressWarnings("rawtypes")
 public class MasterSlaveStateModelFactory extends StateModelFactory<StateModel> {
   int _delay;
-
   String _instanceName = "";
 
   public MasterSlaveStateModelFactory(int delay) {
@@ -39,6 +38,11 @@ public class MasterSlaveStateModelFactory extends StateModelFactory<StateModel>
     _delay = 10;
   }
 
+  public MasterSlaveStateModelFactory(String instanceName, int delay) {
+    _instanceName = instanceName;
+    _delay = delay;
+  }
+
   public MasterSlaveStateModelFactory() {
     this(10);
   }
@@ -74,7 +78,6 @@ public class MasterSlaveStateModelFactory extends StateModelFactory<StateModel>
     }
 
     public void onBecomeSlaveFromOffline(Message message, NotificationContext context) {
-
       System.out.println(_instanceName + " transitioning from " + message.getFromState()
+ " to "
           + message.getToState() + " for " + partitionName);
       sleep();

http://git-wip-us.apache.org/repos/asf/helix/blob/37819298/helix-core/src/main/java/org/apache/helix/examples/OnlineOfflineStateModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/examples/OnlineOfflineStateModelFactory.java
b/helix-core/src/main/java/org/apache/helix/examples/OnlineOfflineStateModelFactory.java
index e11c6d1..d6edb05 100644
--- a/helix-core/src/main/java/org/apache/helix/examples/OnlineOfflineStateModelFactory.java
+++ b/helix-core/src/main/java/org/apache/helix/examples/OnlineOfflineStateModelFactory.java
@@ -26,39 +26,68 @@ import org.apache.helix.participant.statemachine.StateModelFactory;
 
 public class OnlineOfflineStateModelFactory extends StateModelFactory<StateModel> {
   int _delay;
+  String _instanceName = "";
 
   public OnlineOfflineStateModelFactory(int delay) {
     _delay = delay;
   }
 
+  public OnlineOfflineStateModelFactory(String instanceName) {
+    _instanceName = instanceName;
+    _delay = 10;
+  }
+
+  public OnlineOfflineStateModelFactory(String instanceName, int delay) {
+    _instanceName = instanceName;
+    _delay = delay;
+  }
+
+  public OnlineOfflineStateModelFactory() {
+    this(10);
+  }
+
   @Override
   public StateModel createNewStateModel(String resourceName, String stateUnitKey) {
     OnlineOfflineStateModel stateModel = new OnlineOfflineStateModel();
     stateModel.setDelay(_delay);
+    stateModel.setInstanceName(_instanceName);
     return stateModel;
   }
 
   public static class OnlineOfflineStateModel extends StateModel {
     int _transDelay = 0;
+    String _instanceName = "";
 
     public void setDelay(int delay) {
       _transDelay = delay > 0 ? delay : 0;
     }
 
+    public void setInstanceName(String instanceName) {
+      _instanceName = instanceName;
+    }
+
     public void onBecomeOnlineFromOffline(Message message, NotificationContext context) {
-      System.out.println("OnlineOfflineStateModel.onBecomeOnlineFromOffline()");
+      System.out.println(
+          "OnlineOfflineStateModelFactory.onBecomeOnlineFromOffline():" + _instanceName
+              + " transitioning from " + message.getFromState() + " to " + message.getToState()
+              + " for " + message.getResourceName() + " " + message.getPartitionName());
       sleep();
     }
 
     public void onBecomeOfflineFromOnline(Message message, NotificationContext context) {
-      System.out.println("OnlineOfflineStateModel.onBecomeOfflineFromOnline()");
+      System.out.println(
+          "OnlineOfflineStateModelFactory.onBecomeOfflineFromOnline():" + _instanceName
+              + " transitioning from " + message.getFromState() + " to " + message.getToState()
+              + " for " + message.getResourceName() + " " + message.getPartitionName());
       sleep();
     }
 
     public void onBecomeDroppedFromOffline(Message message, NotificationContext context)
{
-      System.out.println("OnlineOfflineStateModel.onBecomeDroppedFromOffline()");
+      System.out.println(
+          "OnlineOfflineStateModelFactory.onBecomeDroppedFromOffline():" + _instanceName
+              + " transitioning from " + message.getFromState() + " to " + message.getToState()
+              + " for " + message.getResourceName() + " " + message.getPartitionName());
       sleep();
-
     }
 
     private void sleep() {


Mime
View raw message