本文整理汇总了Java中org.apache.helix.HelixManager.getHelixDataAccessor方法的典型用法代码示例。如果您正苦于以下问题:Java HelixManager.getHelixDataAccessor方法的具体用法?Java HelixManager.getHelixDataAccessor怎么用?Java HelixManager.getHelixDataAccessor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.HelixManager
的用法示例。
在下文中一共展示了HelixManager.getHelixDataAccessor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ParticipantManager
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public ParticipantManager(HelixManager manager, ZkClient zkclient, int sessionTimeout,
LiveInstanceInfoProvider liveInstanceInfoProvider, List<PreConnectCallback> preConnectCallbacks) {
_zkclient = zkclient;
_manager = manager;
_clusterName = manager.getClusterName();
_instanceName = manager.getInstanceName();
_keyBuilder = new PropertyKey.Builder(_clusterName);
_sessionId = manager.getSessionId();
_sessionTimeout = sessionTimeout;
_configAccessor = manager.getConfigAccessor();
_instanceType = manager.getInstanceType();
_helixAdmin = manager.getClusterManagmentTool();
_dataAccessor = (ZKHelixDataAccessor) manager.getHelixDataAccessor();
_messagingService = (DefaultMessagingService) manager.getMessagingService();
_stateMachineEngine = manager.getStateMachineEngine();
_liveInstanceInfoProvider = liveInstanceInfoProvider;
_preConnectCallbacks = preConnectCallbacks;
}
示例2: addSummary
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
private void addSummary(Map<String, Map<String, String>> _resultSummaryMap,
Message originalMessage, HelixManager manager, boolean timeOut) {
Map<String, String> summary = new TreeMap<String, String>();
summary.put("TotalMessages:", "" + _resultSummaryMap.size());
summary.put("Timeout", "" + timeOut);
_resultSummaryMap.put("Summary", summary);
HelixDataAccessor accessor = manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
ZNRecord statusUpdate =
accessor.getProperty(
keyBuilder.controllerTaskStatus(MessageType.SCHEDULER_MSG.name(),
originalMessage.getMsgId())).getRecord();
statusUpdate.getMapFields().putAll(_resultSummaryMap);
accessor.setProperty(
keyBuilder.controllerTaskStatus(MessageType.SCHEDULER_MSG.name(),
originalMessage.getMsgId()), new StatusUpdate(statusUpdate));
}
示例3: syncSessionToController
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
private void syncSessionToController(HelixManager manager) {
if (_lastSessionSyncTime == null ||
System.currentTimeMillis() - _lastSessionSyncTime > SESSION_SYNC_INTERVAL) { // > delay since last sync
HelixDataAccessor accessor = manager.getHelixDataAccessor();
PropertyKey key = new Builder(manager.getClusterName()).controllerMessage(SESSION_SYNC);
if (accessor.getProperty(key) == null) {
LOG.info(String.format("Participant %s syncs session with controller", manager.getInstanceName()));
Message msg = new Message(MessageType.PARTICIPANT_SESSION_CHANGE, SESSION_SYNC);
msg.setSrcName(manager.getInstanceName());
msg.setTgtSessionId("*");
msg.setMsgState(MessageState.NEW);
msg.setMsgId(SESSION_SYNC);
Criteria cr = new Criteria();
cr.setRecipientInstanceType(InstanceType.CONTROLLER);
cr.setSessionSpecific(false);
manager.getMessagingService().send(cr, msg);
_lastSessionSyncTime = System.currentTimeMillis();
}
}
}
示例4: CallbackHandler
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public CallbackHandler(HelixManager manager, ZkClient client, PropertyKey propertyKey,
Object listener, EventType[] eventTypes, ChangeType changeType,
HelixCallbackMonitor monitor) {
if (listener == null) {
throw new HelixException("listener could not be null");
}
if (monitor != null && !monitor.getChangeType().equals(changeType)) {
throw new HelixException(
"The specified callback monitor is for different change type: " + monitor.getChangeType()
.name());
}
this._manager = manager;
this._accessor = manager.getHelixDataAccessor();
this._zkClient = client;
this._propertyKey = propertyKey;
this._path = propertyKey.getPath();
this._listener = listener;
this._eventTypes = new HashSet<>(Arrays.asList(eventTypes));
this._changeType = changeType;
this._lastNotificationTimeStamp = new AtomicLong(System.nanoTime());
this._queue = new LinkedBlockingQueue<>(1000);
this._monitor = monitor;
parseListenerProperties();
logger.info("isAsyncBatchModeEnabled: " + _batchModeEnabled);
logger.info("isPreFetchEnabled: " + _preFetchEnabled);
if (_batchModeEnabled) {
new Thread(new CallbackInvoker(this)).start();
}
init();
}
示例5: tryUpdateController
import org.apache.helix.HelixManager; //导入方法依赖的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;
}
示例6: printStatus
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
private static void printStatus(final HelixManager manager) {
System.out.println("CLUSTER STATUS");
HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
Builder keyBuilder = helixDataAccessor.keyBuilder();
System.out.println("External View \n"
+ helixDataAccessor.getProperty(keyBuilder.externalView("repository")));
}
示例7: callParticipantCode
import org.apache.helix.HelixManager; //导入方法依赖的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);
}
}
示例8: postHandleMessage
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public void postHandleMessage() {
if (_message.getBatchMessageMode() == true && _batchMsgWrapper != null) {
_batchMsgWrapper.end(_message, _notificationContext);
}
// update currentState
HelixManager manager = _notificationContext.getManager();
HelixDataAccessor accessor = manager.getHelixDataAccessor();
ConcurrentHashMap<String, CurrentStateUpdate> csUpdateMap =
(ConcurrentHashMap<String, CurrentStateUpdate>) _notificationContext
.get(MapKey.CURRENT_STATE_UPDATE.toString());
if (csUpdateMap != null) {
Map<PropertyKey, CurrentState> csUpdate = mergeCurStateUpdate(csUpdateMap);
// TODO: change to use asyncSet
for (PropertyKey key : csUpdate.keySet()) {
// logger.info("updateCS: " + key);
// System.out.println("\tupdateCS: " + key.getPath() + ", " +
// curStateMap.get(key));
if(!accessor.updateProperty(key, csUpdate.get(key))) {
LOG.error(
"Fails to persist current state to ZK for key " + key);
}
}
}
}
示例9: readNewMessagesFromZK
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
private List<Message> readNewMessagesFromZK(HelixManager manager, String instanceName,
HelixConstants.ChangeType changeType) {
HelixDataAccessor accessor = manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
Set<String> messageIds = new HashSet<>();
if (changeType.equals(HelixConstants.ChangeType.MESSAGE)) {
messageIds.addAll(accessor.getChildNames(keyBuilder.messages(instanceName)));
} else if (changeType.equals(HelixConstants.ChangeType.MESSAGES_CONTROLLER)) {
messageIds.addAll(accessor.getChildNames(keyBuilder.controllerMessages()));
} else {
LOG.warn("Unexpected ChangeType for Message Change CallbackHandler: " + changeType);
return Collections.emptyList();
}
// In case the cache contains any deleted message Id, clean up
_knownMessageIds.retainAll(messageIds);
messageIds.removeAll(_knownMessageIds);
List<PropertyKey> keys = new ArrayList<>();
for (String messageId : messageIds) {
if (changeType.equals(HelixConstants.ChangeType.MESSAGE)) {
keys.add(keyBuilder.message(instanceName, messageId));
} else if (changeType.equals(HelixConstants.ChangeType.MESSAGES_CONTROLLER)) {
keys.add(keyBuilder.controllerMessage(messageId));
}
}
List<Message> newMessages = accessor.getProperty(keys);
// Message may be removed before get read, clean up null messages.
Iterator<Message> messageIterator = newMessages.iterator();
while(messageIterator.hasNext()) {
if (messageIterator.next() == null) {
messageIterator.remove();
}
}
return newMessages;
}
示例10: onBecomeOnlineFromOffline
import org.apache.helix.HelixManager; //导入方法依赖的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();
}
示例11: liveInstances
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public static List<String> liveInstances(HelixManager helixManager) {
HelixDataAccessor helixDataAccessor = helixManager.getHelixDataAccessor();
PropertyKey liveInstancesKey = helixDataAccessor.keyBuilder().liveInstances();
return ImmutableList.copyOf(helixDataAccessor.getChildNames(liveInstancesKey));
}
示例12: getTableIdealState
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public static IdealState getTableIdealState(HelixManager manager, String resourceName) {
final HelixDataAccessor accessor = manager.getHelixDataAccessor();
final Builder builder = accessor.keyBuilder();
return accessor.getProperty(builder.idealStates(resourceName));
}
示例13: GobblinHelixTaskDriver
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public GobblinHelixTaskDriver(HelixManager manager) {
this(manager.getClusterManagmentTool(), manager.getHelixDataAccessor(), manager
.getConfigAccessor(), manager.getHelixPropertyStore(), manager.getClusterName());
}
示例14: onControllerChange
import org.apache.helix.HelixManager; //导入方法依赖的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);
}
}
示例15: testDataChange
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@Test
public void testDataChange() throws Exception {
// Create an admin and add LiveInstanceChange listener to it
HelixManager adminManager =
HelixManagerFactory.getZKHelixManager(clusterName, null, InstanceType.ADMINISTRATOR,
ZK_ADDR);
adminManager.connect();
final BlockingQueue<List<LiveInstance>> changeList =
new LinkedBlockingQueue<List<LiveInstance>>();
adminManager.addLiveInstanceChangeListener(new LiveInstanceChangeListener() {
@Override
public void onLiveInstanceChange(List<LiveInstance> liveInstances,
NotificationContext changeContext) {
// The queue is basically unbounded, so shouldn't throw exception when calling
// "add".
changeList.add(deepCopy(liveInstances));
}
});
// Check the initial condition
List<LiveInstance> instances = changeList.poll(1, TimeUnit.SECONDS);
Assert.assertNotNull(instances, "Expecting a list of live instance");
Assert.assertTrue(instances.isEmpty(), "Expecting an empty list of live instance");
// Join as participant, should trigger a live instance change event
HelixManager manager =
HelixManagerFactory.getZKHelixManager(clusterName, "localhost_54321",
InstanceType.PARTICIPANT, ZK_ADDR);
manager.connect();
instances = changeList.poll(1, TimeUnit.SECONDS);
Assert.assertNotNull(instances, "Expecting a list of live instance");
Assert.assertEquals(instances.size(), 1, "Expecting one live instance");
Assert.assertEquals(instances.get(0).getInstanceName(), manager.getInstanceName());
// Update data in the live instance node, should trigger another live instance change
// event
HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
PropertyKey propertyKey =
helixDataAccessor.keyBuilder().liveInstance(manager.getInstanceName());
LiveInstance instance = helixDataAccessor.getProperty(propertyKey);
Map<String, String> map = new TreeMap<String, String>();
map.put("k1", "v1");
instance.getRecord().setMapField("test", map);
Assert.assertTrue(helixDataAccessor.updateProperty(propertyKey, instance),
"Failed to update live instance node");
instances = changeList.poll(1, TimeUnit.SECONDS);
Assert.assertNotNull(instances, "Expecting a list of live instance");
Assert.assertEquals(instances.get(0).getRecord().getMapField("test"), map, "Wrong map data.");
manager.disconnect();
Thread.sleep(1000); // wait for callback finish
instances = changeList.poll(1, TimeUnit.SECONDS);
Assert.assertNotNull(instances, "Expecting a list of live instance");
Assert.assertTrue(instances.isEmpty(), "Expecting an empty list of live instance");
adminManager.disconnect();
}