本文整理汇总了Java中org.apache.helix.model.LiveInstance.getSessionId方法的典型用法代码示例。如果您正苦于以下问题:Java LiveInstance.getSessionId方法的具体用法?Java LiveInstance.getSessionId怎么用?Java LiveInstance.getSessionId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.model.LiveInstance
的用法示例。
在下文中一共展示了LiveInstance.getSessionId方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isLeader
import org.apache.helix.model.LiveInstance; //导入方法依赖的package包/类
@Override
public boolean isLeader() {
if (_instanceType != InstanceType.CONTROLLER
&& _instanceType != InstanceType.CONTROLLER_PARTICIPANT) {
return false;
}
if (!isConnected()) {
return false;
}
try {
LiveInstance leader = _dataAccessor.getProperty(_keyBuilder.controllerLeader());
if (leader != null) {
String leaderName = leader.getInstanceName();
String sessionId = leader.getSessionId();
if (leaderName != null && leaderName.equals(_instanceName) && sessionId != null
&& sessionId.equals(_sessionId)) {
return true;
}
}
} catch (Exception e) {
// log
}
return false;
}
示例2: getSchedulerTasksRepresentation
import org.apache.helix.model.LiveInstance; //导入方法依赖的package包/类
StringRepresentation getSchedulerTasksRepresentation() throws JsonGenerationException,
JsonMappingException, IOException {
String clusterName = (String) getRequest().getAttributes().get("clusterName");
String instanceName = (String) getRequest().getAttributes().get("instanceName");
ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
List<String> instances =
setupTool.getClusterManagementTool().getInstancesInCluster(clusterName);
HelixDataAccessor accessor =
ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
LiveInstance liveInstance =
accessor.getProperty(accessor.keyBuilder().liveInstance(instanceName));
String sessionId = liveInstance.getSessionId();
StringRepresentation representation = new StringRepresentation("");// (ClusterRepresentationUtil.ObjectToJson(instanceConfigs),
// MediaType.APPLICATION_JSON);
return representation;
}
示例3: tryUpdateController
import org.apache.helix.model.LiveInstance; //导入方法依赖的package包/类
private boolean tryUpdateController(HelixManager manager) {
HelixDataAccessor accessor = manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
LiveInstance leader = new LiveInstance(manager.getInstanceName());
try {
leader.setLiveInstance(ManagementFactory.getRuntimeMXBean().getName());
leader.setSessionId(manager.getSessionId());
leader.setHelixVersion(manager.getVersion());
boolean success = accessor.createControllerLeader(leader);
if (success) {
return true;
} else {
LOG.info("Unable to become leader probably because some other controller becames the leader");
}
} catch (Exception e) {
LOG.error(
"Exception when trying to updating leader record in cluster:" + manager.getClusterName()
+ ". Need to check again whether leader node has been created or not", e);
}
leader = accessor.getProperty(keyBuilder.controllerLeader());
if (leader != null) {
String leaderSessionId = leader.getSessionId();
LOG.info("Leader exists for cluster: " + manager.getClusterName() + ", currentLeader: "
+ leader.getInstanceName() + ", leaderSessionId: " + leaderSessionId);
if (leaderSessionId != null && leaderSessionId.equals(manager.getSessionId())) {
return true;
}
}
return false;
}
示例4: process
import org.apache.helix.model.LiveInstance; //导入方法依赖的package包/类
@Override
public void process(ClusterEvent event) throws Exception {
ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES.name());
if (cache == null || resourceMap == null) {
throw new StageException("Missing attributes in event:" + event
+ ". Requires DataCache|RESOURCE");
}
Map<String, LiveInstance> liveInstances = cache.getLiveInstances();
CurrentStateOutput currentStateOutput = new CurrentStateOutput();
for (LiveInstance instance : liveInstances.values()) {
String instanceName = instance.getInstanceName();
String instanceSessionId = instance.getSessionId();
// update pending messages
Map<String, Message> messages = cache.getMessages(instanceName);
updatePendingMessages(instance, messages.values(), currentStateOutput, resourceMap);
// update current states.
Map<String, CurrentState> currentStateMap = cache.getCurrentState(instanceName, instanceSessionId);
updateCurrentStates(instance, currentStateMap.values(), currentStateOutput, resourceMap);
}
if (!cache.isTaskCache()) {
ClusterStatusMonitor clusterStatusMonitor =
event.getAttribute(AttributeName.clusterStatusMonitor.name());
updateMissingTopStateStatus(cache, clusterStatusMonitor, resourceMap, currentStateOutput);
}
event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput);
}
示例5: updateCurrentStates
import org.apache.helix.model.LiveInstance; //导入方法依赖的package包/类
private void updateCurrentStates(LiveInstance instance, Collection<CurrentState> currentStates,
CurrentStateOutput currentStateOutput, Map<String, Resource> resourceMap) {
String instanceName = instance.getInstanceName();
String instanceSessionId = instance.getSessionId();
for (CurrentState currentState : currentStates) {
if (!instanceSessionId.equals(currentState.getSessionId())) {
continue;
}
String resourceName = currentState.getResourceName();
String stateModelDefName = currentState.getStateModelDefRef();
Resource resource = resourceMap.get(resourceName);
if (resource == null) {
continue;
}
if (stateModelDefName != null) {
currentStateOutput.setResourceStateModelDef(resourceName, stateModelDefName);
}
currentStateOutput.setBucketSize(resourceName, currentState.getBucketSize());
Map<String, String> partitionStateMap = currentState.getPartitionStateMap();
for (String partitionName : partitionStateMap.keySet()) {
Partition partition = resource.getPartition(partitionName);
if (partition != null) {
currentStateOutput.setCurrentState(resourceName, partition, instanceName,
currentState.getState(partitionName));
currentStateOutput.setRequestedState(resourceName, partition, instanceName,
currentState.getRequestedState(partitionName));
currentStateOutput.setInfo(resourceName, partition, instanceName, currentState.getInfo(partitionName));
}
}
}
}