当前位置: 首页>>代码示例>>Java>>正文


Java NotificationContext.getManager方法代码示例

本文整理汇总了Java中org.apache.helix.NotificationContext.getManager方法的典型用法代码示例。如果您正苦于以下问题:Java NotificationContext.getManager方法的具体用法?Java NotificationContext.getManager怎么用?Java NotificationContext.getManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.helix.NotificationContext的用法示例。


在下文中一共展示了NotificationContext.getManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onBecomeLeaderFromStandby

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
@Transition(to = "LEADER", from = "STANDBY")
public void onBecomeLeaderFromStandby(Message message, NotificationContext context)
    throws Exception {
  LOG.info("Become LEADER from STANDBY");
  HelixManager manager = context.getManager();
  if (manager == null) {
    throw new IllegalArgumentException("Require HelixManager in notification conext");
  }
  for (ChangeType notificationType : _notificationTypes) {
    if (notificationType == ChangeType.LIVE_INSTANCE) {
      manager.addLiveInstanceChangeListener(_particHolder);
    } else if (notificationType == ChangeType.CONFIG) {
      manager.addConfigChangeListener(_particHolder);
    } else if (notificationType == ChangeType.EXTERNAL_VIEW) {
      manager.addExternalViewChangeListener(_particHolder);
    } else {
      LOG.error("Unsupport notificationType:" + notificationType.toString());
    }
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:21,代码来源:GenericLeaderStandbyModel.java

示例2: onBecomeStandbyFromLeader

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
@Transition(to = "STANDBY", from = "LEADER")
public void onBecomeStandbyFromLeader(Message message, NotificationContext context) {
  LOG.info("Become STANDBY from LEADER");
  HelixManager manager = context.getManager();
  if (manager == null) {
    throw new IllegalArgumentException("Require HelixManager in notification conext");
  }

  Builder keyBuilder = new Builder(manager.getClusterName());
  for (ChangeType notificationType : _notificationTypes) {
    if (notificationType == ChangeType.LIVE_INSTANCE) {
      manager.removeListener(keyBuilder.liveInstances(), _particHolder);
    } else if (notificationType == ChangeType.CONFIG) {
      manager.removeListener(keyBuilder.instanceConfigs(), _particHolder);
    } else if (notificationType == ChangeType.EXTERNAL_VIEW) {
      manager.removeListener(keyBuilder.externalViews(), _particHolder);
    } else {
      LOG.error("Unsupport notificationType:" + notificationType.toString());
    }
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:22,代码来源:GenericLeaderStandbyModel.java

示例3: doTransition

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
@Override
public void doTransition(Message message, NotificationContext context) {
  MockParticipantManager manager = (MockParticipantManager) context.getManager();

  String instance = message.getTgtName();
  String partition = message.getPartitionName();
  if (instance.equals("localhost_12918") && partition.equals("TestDB0_1") // TestDB0_1 is SLAVE
                                                                          // on localhost_12918
      && _done.getAndSet(true) == false) {
    try {
      ZkTestHelper.expireSession(manager.getZkClient());
    } catch (Exception e) {
      LOG.error("Exception expire zk-session", e);
    }
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:17,代码来源:TestSessionExpiryInTransition.java

示例4: onBecomeOnlineFromOffline

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
@Transition(to = "ONLINE", from = "OFFLINE")
public void onBecomeOnlineFromOffline(Message message, NotificationContext context)
    throws Exception {
  LOG.debug(_workerId + " becomes ONLINE from OFFLINE for " + _partition);
  ConfigAccessor clusterConfig = context.getManager().getConfigAccessor();
  HelixManager manager = context.getManager();
  HelixConfigScope clusterScope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(
          manager.getClusterName()).build();
  String json = clusterConfig.get(clusterScope, message.getResourceName());
  Dag.Node node = Dag.Node.fromJson(json);
  Set<String> parentIds = node.getParentIds();
  String resourceName = message.getResourceName();
  int numPartitions = node.getNumPartitions();
  Task task = _taskFactory.createTask(resourceName, parentIds, manager, _taskResultStore);
  manager.addExternalViewChangeListener(task);

  LOG.debug("Starting task for " + _partition + "...");
  int partitionNum = Integer.parseInt(_partition.split("_")[1]);
  task.execute(resourceName, numPartitions, partitionNum);
  LOG.debug("Task for " + _partition + " done");
}
 
开发者ID:apache,项目名称:helix,代码行数:23,代码来源:TaskStateModel.java

示例5: offlineToSlave

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
@Transition(from = "OFFLINE", to = "SLAVE")
public void offlineToSlave(Message message, NotificationContext context) {
  System.out.println("BootstrapProcess.BootstrapStateModel.offlineToSlave()");
  HelixManager manager = context.getManager();
  ClusterMessagingService messagingService = manager.getMessagingService();
  Message requestBackupUriRequest =
      new Message(MessageType.USER_DEFINE_MSG, UUID.randomUUID().toString());
  requestBackupUriRequest.setMsgSubType(BootstrapProcess.REQUEST_BOOTSTRAP_URL);
  requestBackupUriRequest.setMsgState(MessageState.NEW);
  Criteria recipientCriteria = new Criteria();
  recipientCriteria.setInstanceName("*");
  recipientCriteria.setRecipientInstanceType(InstanceType.PARTICIPANT);
  recipientCriteria.setResource(message.getResourceName());
  recipientCriteria.setPartition(message.getPartitionName());
  recipientCriteria.setSessionSpecific(true);
  // wait for 30 seconds
  int timeout = 30000;
  BootstrapReplyHandler responseHandler = new BootstrapReplyHandler();

  int sentMessageCount =
      messagingService.sendAndWait(recipientCriteria, requestBackupUriRequest, responseHandler,
          timeout);
  if (sentMessageCount == 0) {
    // could not find any other node hosting the partition
  } else if (responseHandler.getBootstrapUrl() != null) {
    System.out.println("Got bootstrap url:" + responseHandler.getBootstrapUrl());
    System.out.println("Got backup time:" + responseHandler.getBootstrapTime());
    // Got the url fetch it
  } else {
    // Either go to error state
    // throw new Exception("Cant find backup/bootstrap data");
    // Request some node to start backup process
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:35,代码来源:BootstrapHandler.java

示例6: callParticipantCode

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
private void callParticipantCode(NotificationContext context) {
  // since ZkClient.unsubscribe() does not immediately remove listeners
  // from zk, it is possible that two listeners exist when leadership transfers
  // therefore, double check to make sure only one participant invokes the code
  if (context.getType() == Type.CALLBACK) {
    HelixManager manager = context.getManager();
    // DataAccessor accessor = manager.getDataAccessor();
    HelixDataAccessor accessor = manager.getHelixDataAccessor();
    Builder keyBuilder = accessor.keyBuilder();

    String instance = manager.getInstanceName();
    String sessionId = manager.getSessionId();

    // get resource name from partition key: "PARTICIPANT_LEADER_XXX_0"
    String resourceName = _partitionKey.substring(0, _partitionKey.lastIndexOf('_'));

    CurrentState curState =
        accessor.getProperty(keyBuilder.currentState(instance, sessionId, resourceName));
    if (curState == null) {
      return;
    }

    String state = curState.getState(_partitionKey);
    if (state == null || !state.equalsIgnoreCase("LEADER")) {
      return;
    }
  }

  try {
    _callback.onCallback(context);
  } catch (Exception e) {
    LOG.error("Error invoking callback:" + _callback, e);
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:35,代码来源:CustomCodeInvoker.java

示例7: HelixTask

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
public HelixTask(Message message, NotificationContext notificationContext,
    MessageHandler handler, HelixTaskExecutor executor) {
  this._notificationContext = notificationContext;
  this._message = message;
  this._handler = handler;
  this._manager = notificationContext.getManager();
  _statusUpdateUtil = new StatusUpdateUtil();
  _executor = executor;
}
 
开发者ID:apache,项目名称:helix,代码行数:10,代码来源:HelixTask.java

示例8: onBecomeOnlineFromOffline

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
/**
 * Run the task. The parallelism of this is dictated by the constraints that are set.
 * @param message
 * @param context
 * @throws InterruptedException
 */
public void onBecomeOnlineFromOffline(final Message message, NotificationContext context)
    throws InterruptedException {
  // Do the work, and then finally remove the instance from the preference list for this
  // partition
  HelixManager manager = context.getManager();
  LOG.info("START onBecomeOnlineFromOffline for " + message.getPartitionName() + " on "
      + manager.getInstanceName());
  int oldSize;
  synchronized (_instanceList) {
    oldSize = _instanceList.size();
    _instanceList.add(manager.getInstanceName());
  }
  Assert.assertEquals(oldSize, 0); // ensure these transitions are fully synchronized

  Thread.sleep(TRANSITION_TIME); // a sleep simulates work

  // Need to disable in order to get the transition the next time
  HelixDataAccessor accessor = manager.getHelixDataAccessor();
  removeInstanceFromPreferences(accessor, manager.getInstanceName(), message.getResourceName(),
      message.getPartitionName());
  LOG.info("FINISH onBecomeOnlineFromOffline for " + message.getPartitionName() + " on "
      + manager.getInstanceName());

  int newSize;
  synchronized (_instanceList) {
    _instanceList.remove(_instanceList.size() - 1);
    newSize = _instanceList.size();
  }
  Assert.assertEquals(newSize, oldSize); // ensure nothing came in during this time
  _onlineLatch.countDown();
}
 
开发者ID:apache,项目名称:helix,代码行数:38,代码来源:TestPreferenceListAsQueue.java

示例9: doTransition

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
@Override
public void doTransition(Message message, NotificationContext context) {
  HelixManager manager = context.getManager();
  String clusterName = manager.getClusterName();

  String instance = message.getTgtName();
  String partitionName = message.getPartitionName();
  String fromState = message.getFromState();
  String toState = message.getToState();
  if (instance.equals("localhost_12919") && partitionName.equals("TestDB0_0")) {
    if (fromState.equals("SLAVE") && toState.equals("OFFLINE")) {
      slaveToOfflineCnt++;

      try {
        String command =
            "--zkSvr " + ZK_ADDR + " --enablePartition true " + clusterName
                + " localhost_12919 TestDB0 TestDB0_0";

        ClusterSetup.processCommandLineArgs(command.split("\\s+"));
      } catch (Exception e) {
        LOG.error("Exception in cluster setup", e);
      }

    } else if (slaveToOfflineCnt > 0 && fromState.equals("OFFLINE") && toState.equals("SLAVE")) {
      offlineToSlave++;
    }
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:29,代码来源:TestEnablePartitionDuringDisable.java

示例10: onCallback

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
@Override
public void onCallback(NotificationContext context) {
  HelixManager manager = context.getManager();
  Type type = context.getType();
  _isCallbackInvoked = true;
  // System.out.println(type + ": TestCallback invoked on " + manager.getInstanceName());
}
 
开发者ID:apache,项目名称:helix,代码行数:8,代码来源:TestHelixCustomCodeRunner.java

示例11: onControllerChange

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
/**
 * may be accessed by multiple threads: zk-client thread and
 * ZkHelixManager.disconnect()->reset() TODO: Refactor accessing
 * HelixMangerMain class statically
 */
@Override
public synchronized void onControllerChange(NotificationContext changeContext) {
  HelixManager manager = changeContext.getManager();
  if (manager == null) {
    LOG.error("missing attributes in changeContext. requires HelixManager");
    return;
  }

  InstanceType type = manager.getInstanceType();
  if (type != InstanceType.CONTROLLER && type != InstanceType.CONTROLLER_PARTICIPANT) {
    LOG.error("fail to become controller because incorrect instanceType (was " + type.toString()
        + ", requires CONTROLLER | CONTROLLER_PARTICIPANT)");
    return;
  }

  ControllerManagerHelper controllerHelper =
      new ControllerManagerHelper(_manager, _controllerTimerTasks);
  try {
    if (changeContext.getType().equals(NotificationContext.Type.INIT)
        || changeContext.getType().equals(NotificationContext.Type.CALLBACK)) {
      LOG.info(_manager.getInstanceName() + " is trying to acquire leadership for cluster: "
          + _manager.getClusterName());
      HelixDataAccessor accessor = manager.getHelixDataAccessor();
      Builder keyBuilder = accessor.keyBuilder();

      while (accessor.getProperty(keyBuilder.controllerLeader()) == null) {
        boolean success = tryUpdateController(manager);
        if (success) {
          LOG.info(_manager.getInstanceName() + " acquired leadership for cluster: "
              + _manager.getClusterName());

          updateHistory(manager);
          _manager.getHelixDataAccessor().getBaseDataAccessor().reset();
          controllerHelper.addListenersToController(_controller);
          controllerHelper.startControllerTimerTasks();
        }
      }
    } else if (changeContext.getType().equals(NotificationContext.Type.FINALIZE)) {
      LOG.info(_manager.getInstanceName() + " reqlinquish leadership for cluster: "
          + _manager.getClusterName());
      controllerHelper.stopControllerTimerTasks();
      controllerHelper.removeListenersFromController(_controller);
      _controller.shutdownClusterStatusMonitor(_manager.getClusterName());

      /**
       * clear write-through cache
       */
      _manager.getHelixDataAccessor().getBaseDataAccessor().reset();
    }

  } catch (Exception e) {
    LOG.error("Exception when trying to become leader", e);
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:60,代码来源:DistributedLeaderElection.java

示例12: scheduleTask

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
@Override
public boolean scheduleTask(MessageTask task) {
  String taskId = task.getTaskId();
  Message message = task.getMessage();
  NotificationContext notificationContext = task.getNotificationContext();
  HelixManager manager = notificationContext.getManager();

  try {
    // Check to see if dedicate thread pool for handling state transition messages is configured or provided.
    updateStateTransitionMessageThreadPool(message, manager);

    LOG.info("Scheduling message: " + taskId);
    // System.out.println("sched msg: " + message.getPartitionName() + "-"
    // + message.getTgtName() + "-" + message.getFromState() + "-"
    // + message.getToState());

    _statusUpdateUtil.logInfo(message, HelixTaskExecutor.class,
        "Message handling task scheduled", manager);

    // this sync guarantees that ExecutorService.submit() task and put taskInfo into map are
    // sync'ed
    synchronized (_lock) {
      if (!_taskMap.containsKey(taskId)) {
        ExecutorService exeSvc = findExecutorServiceForMsg(message);

        if (exeSvc == null) {
          LOG.warn(String
              .format("Threadpool is null for type %s of message %s", message.getMsgType(),
                  message.getMsgId()));
          return false;
        }

        LOG.info("Submit task: " + taskId + " to pool: " + exeSvc);
        Future<HelixTaskResult> future = exeSvc.submit(task);

        _messageTaskMap
            .putIfAbsent(getMessageTarget(message.getResourceName(), message.getPartitionName()),
                taskId);

        TimerTask timerTask = null;
        if (message.getExecutionTimeout() > 0) {
          timerTask = new MessageTimeoutTask(this, task);
          _timer.schedule(timerTask, message.getExecutionTimeout());
          LOG.info("Message starts with timeout " + message.getExecutionTimeout() + " MsgId: "
              + task.getTaskId());
        } else {
          LOG.debug("Message does not have timeout. MsgId: " + task.getTaskId());
        }
        _taskMap.put(taskId, new MessageTaskInfo(task, future, timerTask));

        LOG.info("Message: " + taskId + " handling task scheduled");
        return true;
      } else {
        _statusUpdateUtil.logWarning(message, HelixTaskExecutor.class,
            "Message handling task already sheduled for " + taskId, manager);
      }
    }
  } catch (Exception e) {
    LOG.error("Error while executing task. " + message, e);
    _statusUpdateUtil.logError(message, HelixTaskExecutor.class, e, "Error while executing task "
        + e, manager);
  }
  return false;
}
 
开发者ID:apache,项目名称:helix,代码行数:65,代码来源:HelixTaskExecutor.java

示例13: onBecomeOfflineFromOnline

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
public void onBecomeOfflineFromOnline(Message message, NotificationContext context) {
  HelixManager manager = context.getManager();
  LOG.info("onBecomeOfflineFromOnline for " + message.getPartitionName() + " on "
      + manager.getInstanceName());
}
 
开发者ID:apache,项目名称:helix,代码行数:6,代码来源:TestPreferenceListAsQueue.java

示例14: onBecomeDroppedFromOffline

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
public void onBecomeDroppedFromOffline(Message message, NotificationContext context) {
  HelixManager manager = context.getManager();
  LOG.info("onBecomeDroppedFromOffline for " + message.getPartitionName() + " on "
      + manager.getInstanceName());
  _offlineLatch.countDown();
}
 
开发者ID:apache,项目名称:helix,代码行数:7,代码来源:TestPreferenceListAsQueue.java

示例15: onBecomeOfflineFromError

import org.apache.helix.NotificationContext; //导入方法依赖的package包/类
public void onBecomeOfflineFromError(Message message, NotificationContext context) {
  HelixManager manager = context.getManager();
  LOG.info("onBecomeOfflineFromError for " + message.getPartitionName() + " on "
      + manager.getInstanceName());
}
 
开发者ID:apache,项目名称:helix,代码行数:6,代码来源:TestPreferenceListAsQueue.java


注:本文中的org.apache.helix.NotificationContext.getManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。