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


Java NotificationContext类代码示例

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


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

示例1: onBecomeOnlineFromOffline

import org.apache.helix.NotificationContext; //导入依赖的package包/类
@Transition(from = "OFFLINE", to = "ONLINE")
public void onBecomeOnlineFromOffline(Message message,
                                      NotificationContext context) {
  Pair<String, String> hdfsPathAndPartition = getHdfsPathAndPartitionNum(message);
  String hdfsPath = hdfsPathAndPartition.getLeft();
  LOG.info("Opening " + hdfsPath);
  try {
    // TODO(varun): Maybe retry here.
    HColumnDescriptor family = new HColumnDescriptor(Constants.HFILE_COLUMN_FAMILY);
    family.setBlockCacheEnabled(isBlockCacheEnabled);
    Reader r = readerFactory.createHFileReader(hdfsPath, new CacheConfig(conf, family));
    resourcePartitionMap.addReader(
        message.getResourceName(), hdfsPathAndPartition.getRight(), r);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:pinterest-attic,项目名称:terrapin,代码行数:18,代码来源:OnlineOfflineStateModelFactory.java

示例2: onLiveInstanceChange

import org.apache.helix.NotificationContext; //导入依赖的package包/类
@Override
public void onLiveInstanceChange(List<LiveInstance> list, NotificationContext notificationContext) {
  List<InetSocketAddress> addresses = new ArrayList<>();
  HelixAdmin helixAdmin = helixConnection.createClusterManagementTool();
  for (LiveInstance liveInstance : list) {
    InstanceConfig instanceConfig = helixAdmin.getInstanceConfig(
        clusterName,
        liveInstance.getInstanceName());
    InetSocketAddress address = new InetSocketAddress(
        instanceConfig.getHostName(),
        Integer.valueOf(instanceConfig.getPort()));
    addresses.add(address);
  }

  services.set(addresses);
}
 
开发者ID:brandtg,项目名称:dropwizard-helix,代码行数:17,代码来源:HelixServiceDiscoverer.java

示例3: onBecomeOnlineFromOffline

import org.apache.helix.NotificationContext; //导入依赖的package包/类
@Transition(from = "OFFLINE", to = "ONLINE")
public void onBecomeOnlineFromOffline(Message message, NotificationContext context) {

  try {
    LOGGER.info("BrokerResourceOnlineOfflineStateModel.onBecomeOnlineFromOffline() : " + message);
    Builder keyBuilder = _helixManager.getHelixDataAccessor().keyBuilder();
    String resourceName = message.getPartitionName();
    HelixDataAccessor helixDataAccessor = _helixManager.getHelixDataAccessor();
    List<InstanceConfig> instanceConfigList = helixDataAccessor.getChildValues(keyBuilder.instanceConfigs());

    _helixExternalViewBasedRouting.markDataResourceOnline(
        resourceName,
        HelixHelper.getExternalViewForResouce(_helixManager.getClusterManagmentTool(),
            _helixManager.getClusterName(), resourceName), instanceConfigList);
  } catch (Exception e) {
    LOGGER.error("Caught exception during OFFLINE -> ONLINE transition", e);
    Utils.rethrowException(e);
    throw new AssertionError("Should not reach this");
  }
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:21,代码来源:BrokerResourceOnlineOfflineStateModelFactory.java

示例4: onBecomeOnlineFromOffline

import org.apache.helix.NotificationContext; //导入依赖的package包/类
@Transition(from = "OFFLINE", to = "ONLINE")
public void onBecomeOnlineFromOffline(Message message, NotificationContext context) {
  LOGGER.debug("SegmentOnlineOfflineStateModel.onBecomeOnlineFromOffline() : " + message);
  final TableType tableType = TableNameBuilder.getTableTypeFromTableName(message.getResourceName());
  try {
    switch (tableType) {
      case OFFLINE:
        onBecomeOnlineFromOfflineForOfflineSegment(message, context);
        break;
      case REALTIME:
        onBecomeOnlineFromOfflineForRealtimeSegment(message, context);
        break;

      default:
        throw new RuntimeException("Not supported table Type for onBecomeOnlineFromOffline message: " + message);
    }
  } catch (Exception e) {
    if (LOGGER.isErrorEnabled()) {
      LOGGER.error(
          "Caught exception in state transition for OFFLINE -> ONLINE for partition" + message.getPartitionName()
              + " of table " + message.getResourceName(), e);
    }
    Utils.rethrowException(e);
  }
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:26,代码来源:SegmentOnlineOfflineStateModelFactory.java

示例5: createMessageHandler

import org.apache.helix.NotificationContext; //导入依赖的package包/类
public MessageHandler createMessageHandler(Message message, NotificationContext changeContext) {
  String msgType = message.getMsgType().toString();

  MsgHandlerFactoryRegistryItem item = _hdlrFtyRegistry.get(msgType);

  // Fail to find a MessageHandlerFactory for the message
  // we will keep the message and the message will be handled when
  // the corresponding MessageHandlerFactory is registered
  if (item == null) {
    LOG.warn("Fail to find message handler factory for type: " + msgType + " msgId: "
        + message.getMsgId());
    return null;
  }
  MessageHandlerFactory handlerFactory = item.factory();

  // pass the executor to msg-handler since batch-msg-handler needs task-executor to schedule
  // sub-msgs
  changeContext.add(MapKey.TASK_EXECUTOR.toString(), this);
  return handlerFactory.createHandler(message, changeContext);
}
 
开发者ID:apache,项目名称:helix,代码行数:21,代码来源:HelixTaskExecutor.java

示例6: onBecomeTaskErrorFromRunning

import org.apache.helix.NotificationContext; //导入依赖的package包/类
@Transition(to = "TASK_ERROR", from = "RUNNING")
public String onBecomeTaskErrorFromRunning(Message msg, NotificationContext context) {
  String taskPartition = msg.getPartitionName();
  if (_taskRunner == null) {
    throw new IllegalStateException(String.format(
        "Invalid state transition. There is no running task for partition %s.", taskPartition));
  }

  TaskResult r = _taskRunner.waitTillDone();
  if (r.getStatus() != TaskResult.Status.ERROR && r.getStatus() != TaskResult.Status.FAILED) {
    throw new IllegalStateException(String.format(
        "Partition %s received a state transition to %s but the result status code is %s.",
        msg.getPartitionName(), msg.getToState(), r.getStatus()));
  }

  timeout_task.cancel(false);

  return r.getInfo();
}
 
开发者ID:apache,项目名称:helix,代码行数:20,代码来源:TaskStateModel.java

示例7: 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

示例8: onBecomeOnlineFromOffline

import org.apache.helix.NotificationContext; //导入依赖的package包/类
@Transition(from = "OFFLINE", to = "ONLINE")
public void onBecomeOnlineFromOffline(Message message, NotificationContext context) {
  try {
    LOGGER.info("BrokerResourceOnlineOfflineStateModel.onBecomeOnlineFromOffline() : " + message);
    Builder keyBuilder = _helixManager.getHelixDataAccessor().keyBuilder();
    String tableName = message.getPartitionName();
    HelixDataAccessor helixDataAccessor = _helixManager.getHelixDataAccessor();
    List<InstanceConfig> instanceConfigList = helixDataAccessor.getChildValues(keyBuilder.instanceConfigs());
    TableConfig tableConfig = ZKMetadataProvider.getTableConfig(_propertyStore, tableName);

    _helixExternalViewBasedRouting.markDataResourceOnline(
        tableConfig,
        HelixHelper.getExternalViewForResource(_helixAdmin, _helixManager.getClusterName(), tableName),
        instanceConfigList);
  } catch (Exception e) {
    LOGGER.error("Caught exception during OFFLINE -> ONLINE transition", e);
    Utils.rethrowException(e);
    throw new AssertionError("Should not reach this");
  }
}
 
开发者ID:linkedin,项目名称:pinot,代码行数:21,代码来源:BrokerResourceOnlineOfflineStateModelFactory.java

示例9: start

import org.apache.helix.NotificationContext; //导入依赖的package包/类
public void start(ControllerMetrics controllerMetrics) {
  _controllerMetrics = controllerMetrics;

  LOGGER.info("Starting realtime segments manager, adding a listener on the property store table configs path.");
  String zkUrl = _pinotHelixResourceManager.getHelixZkURL();
  _zkClient = new ZkClient(zkUrl, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT);
  _zkClient.setZkSerializer(new ZNRecordSerializer());
  _zkClient.waitUntilConnected();

  // Subscribe to any data/child changes to property
  _zkClient.subscribeChildChanges(_tableConfigPath, this);
  _zkClient.subscribeDataChanges(_tableConfigPath, this);

  // Subscribe to leadership changes
  _pinotHelixResourceManager.getHelixZkManager().addControllerListener(new ControllerChangeListener() {
    @Override
    public void onControllerChange(NotificationContext changeContext) {
      processPropertyStoreChange(CONTROLLER_LEADER_CHANGE);
    }
  });

  // Setup change listeners for already existing tables, if any.
  processPropertyStoreChange(_tableConfigPath);
}
 
开发者ID:linkedin,项目名称:pinot,代码行数:25,代码来源:PinotRealtimeSegmentManager.java

示例10: onBecomeOnlineFromOffline

import org.apache.helix.NotificationContext; //导入依赖的package包/类
@Transition(from = "OFFLINE", to = "ONLINE")
public void onBecomeOnlineFromOffline(Message message, NotificationContext context) {
  _logger.info("SegmentOnlineOfflineStateModel.onBecomeOnlineFromOffline() : " + message);
  String tableNameWithType = message.getResourceName();
  String segmentName = message.getPartitionName();
  try {
    TableType tableType = TableNameBuilder.getTableTypeFromTableName(message.getResourceName());
    Preconditions.checkNotNull(tableType);
    if (tableType == TableType.OFFLINE) {
      _fetcherAndLoader.addOrReplaceOfflineSegment(tableNameWithType, segmentName, /*retryOnFailure=*/true);
    } else {
      _instanceDataManager.addRealtimeSegment(tableNameWithType, segmentName);
    }
  } catch (Exception e) {
    _logger.error("Caught exception in state transition from OFFLINE -> ONLINE for resource: {}, partition: {}",
        tableNameWithType, segmentName, e);
    Utils.rethrowException(e);
  }
}
 
开发者ID:linkedin,项目名称:pinot,代码行数:20,代码来源:SegmentOnlineOfflineStateModelFactory.java

示例11: subscribeDataChange

import org.apache.helix.NotificationContext; //导入依赖的package包/类
private void subscribeDataChange(String path, NotificationContext context) {
  NotificationContext.Type type = context.getType();
  if (type == NotificationContext.Type.INIT || type == NotificationContext.Type.CALLBACK) {
    logger.info(
        _manager.getInstanceName() + " subscribe data-change. path: " + path + ", listener: "
            + _listener);
    _zkClient.subscribeDataChanges(path, this);

  } else if (type == NotificationContext.Type.FINALIZE) {
    logger.info(
        _manager.getInstanceName() + " unsubscribe data-change. path: " + path + ", listener: "
            + _listener);

    _zkClient.unsubscribeDataChanges(path, this);
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:17,代码来源:CallbackHandler.java

示例12: handleDataChange

import org.apache.helix.NotificationContext; //导入依赖的package包/类
@Override
public void handleDataChange(String dataPath, Object data) {
  logger.debug("Data change callback: paths changed: " + dataPath);

  try {
    updateNotificationTime(System.nanoTime());
    if (dataPath != null && dataPath.startsWith(_path)) {
      NotificationContext changeContext = new NotificationContext(_manager);
      changeContext.setType(NotificationContext.Type.CALLBACK);
      changeContext.setPathChanged(dataPath);
      changeContext.setChangeType(_changeType);
      enqueueTask(changeContext);
    }
  } catch (Exception e) {
    String msg = "exception in handling data-change. path: " + dataPath + ", listener: " + _listener;
    ZKExceptionHandler.getInstance().handle(msg, e);
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:19,代码来源:CallbackHandler.java

示例13: handleChildChange

import org.apache.helix.NotificationContext; //导入依赖的package包/类
@Override
public void handleChildChange(String parentPath, List<String> currentChilds) {
  logger.debug("Data change callback: child changed, path: " + parentPath + ", current childs: "
      + currentChilds);

  try {
    updateNotificationTime(System.nanoTime());
    if (parentPath != null && parentPath.startsWith(_path)) {
      if (currentChilds == null && parentPath.equals(_path)) {
        // _path has been removed, remove this listener
        // removeListener will call handler.reset(), which in turn call invoke() on FINALIZE type
        _manager.removeListener(_propertyKey, _listener);
      } else {
        NotificationContext changeContext = new NotificationContext(_manager);
        changeContext.setType(NotificationContext.Type.CALLBACK);
        changeContext.setPathChanged(parentPath);
        changeContext.setChangeType(_changeType);
        enqueueTask(changeContext);
      }
    }
  } catch (Exception e) {
    String msg = "exception in handling child-change. instance: " + _manager.getInstanceName()
        + ", parentPath: " + parentPath + ", listener: " + _listener;
    ZKExceptionHandler.getInstance().handle(msg, e);
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:27,代码来源:CallbackHandler.java

示例14: 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

示例15: onLiveInstanceChange

import org.apache.helix.NotificationContext; //导入依赖的package包/类
@Override
public void onLiveInstanceChange(final List<LiveInstance> liveInstances,
    NotificationContext changeContext) {
  LOGGER.info("AutoRebalanceLiveInstanceChangeListener.onLiveInstanceChange() wakes up!");
  _delayedScheuler.schedule(new Runnable() {
    @Override
    public void run() {
      try {
        rebalanceCurrentCluster(_helixMirrorMakerManager.getCurrentLiveInstances());
      } catch (Exception e) {
        LOGGER.error("Got exception during rebalance the whole cluster! ", e);
      }
    }
  }, _delayedAutoReblanceTimeInSeconds, TimeUnit.SECONDS);
}
 
开发者ID:uber,项目名称:uReplicator,代码行数:16,代码来源:AutoRebalanceLiveInstanceChangeListener.java


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