本文整理汇总了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());
}
}
}
示例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());
}
}
}
示例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);
}
}
}
示例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");
}
示例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
}
}
示例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);
}
}
示例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;
}
示例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();
}
示例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++;
}
}
}
示例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());
}
示例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);
}
}
示例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;
}
示例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());
}
示例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();
}
示例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());
}