View Javadoc

1   package org.apache.helix;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.helix.mock.participant.DummyProcess.DummyLeaderStandbyStateModelFactory;
23  import org.apache.helix.mock.participant.DummyProcess.DummyOnlineOfflineStateModelFactory;
24  import org.apache.helix.mock.participant.DummyProcess.DummyStateModelFactory;
25  import org.apache.helix.participant.StateMachineEngine;
26  import org.apache.log4j.Logger;
27  
28  
29  public class DummyProcessThread implements Runnable
30  {
31    private static final Logger LOG = Logger.getLogger(DummyProcessThread.class);
32  
33    HelixManager _manager;
34    String _instanceName;
35  
36    public DummyProcessThread(HelixManager manager, String instanceName)
37    {
38      _manager = manager;
39      _instanceName = instanceName;
40    }
41  
42    @Override
43    public void run()
44    {
45      try
46      {
47        DummyStateModelFactory stateModelFactory = new DummyStateModelFactory(0);
48  //      StateMachineEngine genericStateMachineHandler =
49  //          new StateMachineEngine();
50        StateMachineEngine stateMach = _manager.getStateMachineEngine();
51        stateMach.registerStateModelFactory("MasterSlave", stateModelFactory);
52  
53        DummyLeaderStandbyStateModelFactory stateModelFactory1 = new DummyLeaderStandbyStateModelFactory(10);
54        DummyOnlineOfflineStateModelFactory stateModelFactory2 = new DummyOnlineOfflineStateModelFactory(10);
55        stateMach.registerStateModelFactory("LeaderStandby", stateModelFactory1);
56        stateMach.registerStateModelFactory("OnlineOffline", stateModelFactory2);
57  //      _manager.getMessagingService()
58  //              .registerMessageHandlerFactory(MessageType.STATE_TRANSITION.toString(),
59  //                                             genericStateMachineHandler);
60  
61        _manager.connect();
62        Thread.currentThread().join();
63      }
64      catch (InterruptedException e)
65      {
66        String msg =
67            "participant:" + _instanceName + ", " + Thread.currentThread().getName()
68                + " interrupted";
69        LOG.info(msg);
70        // System.err.println(msg);
71      }
72      catch (Exception e)
73      {
74        // TODO Auto-generated catch block
75        e.printStackTrace();
76      }
77    }
78  
79  }