Package org.apache.helix

Examples of org.apache.helix.HelixParticipant


    ControllerId controllerId = ControllerId.from("exampleController");
    HelixController helixController = connection.createController(clusterId, controllerId);
    helixController.start();

    // start the specified participant
    HelixParticipant helixParticipant = connection.createParticipant(clusterId, participant.getId());
    helixParticipant.getStateMachineEngine().registerStateModelFactory(lockUnlock.getStateModelDefId(),
        new LockUnlockFactory());
    helixParticipant.start();

    // start another participant via auto join
    HelixParticipant autoJoinParticipant =
        connection.createParticipant(clusterId, ParticipantId.from("localhost_12120"));
    autoJoinParticipant.getStateMachineEngine().registerStateModelFactory(lockUnlock.getStateModelDefId(),
        new LockUnlockFactory());
    autoJoinParticipant.start();

    Thread.sleep(5000);
    printExternalView(connection, clusterId, resource.getId());

    // stop the participants
    helixParticipant.stop();
    autoJoinParticipant.stop();

    // stop the controller
    helixController.stop();

    // drop the cluster
View Full Code Here


    // start controller
    HelixController controller = connection.createController(clusterId, controllerId);
    controller.start();

    // start participant
    HelixParticipant participant = connection.createParticipant(clusterId, participantId);
    participant.getStateMachineEngine().registerStateModelFactory(
        StateModelDefId.from("MasterSlave"), new MockStateModelFactory());

    participant.start();
    Thread.sleep(1000);

    // verify
    final HelixDataAccessor accessor = connection.createDataAccessor(clusterId);
    final PropertyKey.Builder keyBuilder = accessor.keyBuilder();
    boolean success = TestHelper.verify(new TestHelper.Verifier() {

      @Override
      public boolean verify() throws Exception {
        ExternalView externalView = accessor.getProperty(keyBuilder.externalView("testDB"));
        Map<ParticipantId, State> stateMap = externalView.getStateMap(PartitionId.from("testDB_0"));

        if (stateMap == null || !stateMap.containsKey(participantId)) {
          return false;
        }

        return stateMap.get(participantId).equals(State.from("MASTER"));
      }
    }, 10 * 1000);

    Assert.assertTrue(success);

    // clean up
    controller.stop();
    participant.stop();
    connection.disconnect();

    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
  }
View Full Code Here

  @Override
  public StateMachineEngine getStateMachineEngine() {
    StateMachineEngine engine = null;
    switch (_role.getType()) {
    case PARTICIPANT: {
      HelixParticipant participant = (HelixParticipant) _role;
      engine = participant.getStateMachineEngine();
      break;
    }
    case CONTROLLER_PARTICIPANT: {
      HelixMultiClusterController multiClusterController = (HelixMultiClusterController) _role;
      engine = multiClusterController.getStateMachineEngine();
View Full Code Here

  @Override
  public void addPreConnectCallback(PreConnectCallback callback) {
    switch (_role.getType()) {
    case PARTICIPANT: {
      HelixParticipant participant = (HelixParticipant) _role;
      participant.addPreConnectCallback(callback);
      break;
    }
    case CONTROLLER_PARTICIPANT: {
      HelixMultiClusterController multiClusterController = (HelixMultiClusterController) _role;
      multiClusterController.addPreConnectCallback(callback);
View Full Code Here

  @Override
  public void setLiveInstanceInfoProvider(LiveInstanceInfoProvider liveInstanceInfoProvider) {
    switch (_role.getType()) {
    case PARTICIPANT: {
      HelixParticipant participant = (HelixParticipant) _role;
      participant.setLiveInstanceInfoProvider(liveInstanceInfoProvider);
      break;
    }
    case CONTROLLER_PARTICIPANT: {
      HelixMultiClusterController multiClusterController = (HelixMultiClusterController) _role;
      multiClusterController.setLiveInstanceInfoProvider(liveInstanceInfoProvider);
View Full Code Here

    ControllerId controllerId = ControllerId.from("exampleController");
    HelixController helixController = connection.createController(clusterId, controllerId);
    helixController.startAsync();

    // start the specified participant
    HelixParticipant helixParticipant =
        connection.createParticipant(clusterId, participant.getId());
    helixParticipant.getStateMachineEngine().registerStateModelFactory(
        lockUnlock.getStateModelDefId(), new LockUnlockFactory());
    helixParticipant.startAsync();

    // start another participant via auto join
    HelixParticipant autoJoinParticipant =
        connection.createParticipant(clusterId, ParticipantId.from("localhost_12120"));
    autoJoinParticipant.getStateMachineEngine().registerStateModelFactory(
        lockUnlock.getStateModelDefId(), new LockUnlockFactory());
    autoJoinParticipant.startAsync();

    Thread.sleep(5000);
    printExternalView(connection, clusterId, resource.getId());

    // stop the participants
    helixParticipant.stopAsync();
    autoJoinParticipant.stopAsync();

    // stop the controller
    helixController.stopAsync();

    // drop the cluster
View Full Code Here

  @Override
  public StateMachineEngine getStateMachineEngine() {
    StateMachineEngine engine = null;
    switch (_role.getType()) {
    case PARTICIPANT:
      HelixParticipant participant = (HelixParticipant) _role;
      engine = participant.getStateMachineEngine();
      break;
    case CONTROLLER_PARTICIPANT:
      HelixAutoController autoController = (HelixAutoController) _role;
      engine = autoController.getStateMachineEngine();
      break;
View Full Code Here

  @Override
  public void addPreConnectCallback(PreConnectCallback callback) {
    switch (_role.getType()) {
    case PARTICIPANT:
      HelixParticipant participant = (HelixParticipant) _role;
      participant.addPreConnectCallback(callback);
      break;
    case CONTROLLER_PARTICIPANT:
      HelixAutoController autoController = (HelixAutoController) _role;
      autoController.addPreConnectCallback(callback);
      break;
View Full Code Here

  @Override
  public void setLiveInstanceInfoProvider(LiveInstanceInfoProvider liveInstanceInfoProvider) {
    switch (_role.getType()) {
    case PARTICIPANT:
      HelixParticipant participant = (HelixParticipant) _role;
      participant.setLiveInstanceInfoProvider(liveInstanceInfoProvider);
      break;
    case CONTROLLER_PARTICIPANT:
      HelixAutoController autoController = (HelixAutoController) _role;
      autoController.setLiveInstanceInfoProvider(liveInstanceInfoProvider);
      break;
View Full Code Here

    // start controller
    HelixController controller = connection.createController(clusterId, controllerId);
    controller.startAsync();

    // start participant
    HelixParticipant participant = connection.createParticipant(clusterId, participantId);
    participant.getStateMachineEngine().registerStateModelFactory(
        StateModelDefId.from("MasterSlave"), new MockStateModelFactory());

    participant.startAsync();

    // verify
    final HelixDataAccessor accessor = connection.createDataAccessor(clusterId);
    final PropertyKey.Builder keyBuilder = accessor.keyBuilder();
    boolean success = TestHelper.verify(new TestHelper.Verifier() {

      @Override
      public boolean verify() throws Exception {
        ExternalView externalView = accessor.getProperty(keyBuilder.externalView("testDB"));
        Map<ParticipantId, State> stateMap = externalView.getStateMap(PartitionId.from("testDB_0"));

        if (stateMap == null || !stateMap.containsKey(participantId)) {
          return false;
        }

        return stateMap.get(participantId).equals(State.from("MASTER"));
      }
    }, 10 * 1000);

    Assert.assertTrue(success);

    // clean up
    controller.stopAsync();
    participant.stopAsync();
    connection.disconnect();

    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
  }
View Full Code Here

TOP

Related Classes of org.apache.helix.HelixParticipant

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.