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


Java ZKClient类代码示例

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


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

示例1: ZKDiscoveryService

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
/**
 * Constructs ZKDiscoveryService using the provided zookeeper client for storing service registry under namespace.
 * @param zkClient of zookeeper quorum
 * @param namespace under which the service registered would be stored in zookeeper.
 *                  If namespace is {@code null}, no namespace will be used.
 */
public ZKDiscoveryService(ZKClient zkClient, String namespace) {
  this.closed = new AtomicBoolean();
  this.discoverables = HashMultimap.create();
  this.lock = new ReentrantLock();
  this.retryExecutor = Executors.newSingleThreadScheduledExecutor(
    Threads.createDaemonThreadFactory("zk-discovery-retry"));
  this.zkClient = namespace == null ? zkClient : ZKClients.namespace(zkClient, namespace);
  this.services = CacheBuilder.newBuilder()
    .removalListener(new RemovalListener<String, ServiceDiscoveredCacheEntry>() {
      @Override
      public void onRemoval(RemovalNotification<String, ServiceDiscoveredCacheEntry> notification) {
        ServiceDiscoveredCacheEntry entry = notification.getValue();
        if (entry != null) {
          entry.cancel();
        }
      }
    })
    .build(createServiceLoader());
  this.watcherCancellable = this.zkClient.addConnectionWatcher(createConnectionWatcher());
}
 
开发者ID:apache,项目名称:twill,代码行数:27,代码来源:ZKDiscoveryService.java

示例2: ApplicationMasterService

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
public ApplicationMasterService(RunId runId, ZKClient zkClient,
                                TwillRuntimeSpecification twillRuntimeSpec, YarnAMClient amClient,
                                Configuration config, Location applicationLocation) throws Exception {
  super(zkClient, runId, config, applicationLocation);

  this.runId = runId;
  this.twillRuntimeSpec = twillRuntimeSpec;
  this.zkClient = zkClient;
  this.applicationLocation = applicationLocation;
  this.amClient = amClient;
  this.credentials = createCredentials();
  this.jvmOpts = loadJvmOptions();
  this.twillSpec = twillRuntimeSpec.getTwillSpecification();
  this.placementPolicyManager = new PlacementPolicyManager(twillSpec.getPlacementPolicies());
  this.environments = getEnvironments();

  this.amLiveNode = new ApplicationMasterLiveNodeData(Integer.parseInt(System.getenv(EnvKeys.YARN_APP_ID)),
                                                      Long.parseLong(System.getenv(EnvKeys.YARN_APP_ID_CLUSTER_TIME)),
                                                      amClient.getContainerId().toString(), getLocalizeFiles(),
                                                      twillRuntimeSpec.getKafkaZKConnect());

  this.expectedContainers = new ExpectedContainers(twillSpec);
  this.eventHandler = createEventHandler(twillSpec);
  this.runningContainers = createRunningContainers(amClient.getContainerId(), amClient.getHost());
}
 
开发者ID:apache,项目名称:twill,代码行数:26,代码来源:ApplicationMasterService.java

示例3: RunningContainers

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
RunningContainers(TwillRuntimeSpecification twillRuntimeSpec, String appId, TwillRunResources appMasterResources,
                  ZKClient zookeeperClient, Location applicationLocation,
                  Map<String, RuntimeSpecification> runnables,
                  EventHandler eventHandler) {
  containers = HashBasedTable.create();
  runnableInstances = Maps.newHashMap();
  completedContainerCount = Maps.newHashMap();
  startSequence = Lists.newLinkedList();
  containerLock = new ReentrantLock();
  containerChange = containerLock.newCondition();
  resourceReport = new DefaultResourceReport(appId, appMasterResources);
  zkClient = zookeeperClient;
  containerStats = HashMultimap.create();
  this.applicationLocation = applicationLocation;
  this.runnableNames = runnables.keySet();
  this.logLevels = new TreeMap<>();
  this.maxRetries = Maps.newHashMap(twillRuntimeSpec.getMaxRetries());
  this.numRetries = Maps.newHashMap();
  this.eventHandler = eventHandler;
}
 
开发者ID:apache,项目名称:twill,代码行数:21,代码来源:RunningContainers.java

示例4: YarnTwillController

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
/**
 * Creates an instance with an existing {@link ApplicationMasterLiveNodeData}.
 */
YarnTwillController(String appName, RunId runId, ZKClient zkClient,
                    final ApplicationMasterLiveNodeData amLiveNodeData, final YarnAppClient yarnAppClient) {
  super(appName, runId, zkClient, amLiveNodeData.getKafkaZKConnect() != null, Collections.<LogHandler>emptyList());
  this.appName = appName;
  this.amLiveNodeData = amLiveNodeData;
  this.startUp = new Callable<ProcessController<YarnApplicationReport>>() {
    @Override
    public ProcessController<YarnApplicationReport> call() throws Exception {
      return yarnAppClient.createProcessController(
        YarnUtils.createApplicationId(amLiveNodeData.getAppIdClusterTime(), amLiveNodeData.getAppId()));
    }
  };
  this.startTimeout = Constants.APPLICATION_MAX_START_SECONDS;
  this.startTimeoutUnit = TimeUnit.SECONDS;
}
 
开发者ID:apache,项目名称:twill,代码行数:19,代码来源:YarnTwillController.java

示例5: AbstractTwillController

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
public AbstractTwillController(String appName, RunId runId, ZKClient zkClient, boolean logCollectionEnabled,
                               Iterable<LogHandler> logHandlers) {
  super(runId, zkClient);
  this.appName = appName;
  this.runId = runId;
  this.logHandlers = new ConcurrentLinkedQueue<>();

  // When addressing TWILL-147, need to check if the given ZKClient is
  // actually used by the Kafka used for log collection
  if (logCollectionEnabled) {
    this.kafkaClient = new ZKKafkaClientService(ZKClients.namespace(zkClient, "/" + runId.getId() + "/kafka"));
    Iterables.addAll(this.logHandlers, logHandlers);
  } else {
    this.kafkaClient = null;
    if (!Iterables.isEmpty(logHandlers)) {
      LOG.warn("Log collection is disabled for application {} with runId {}. " +
                 "Adding log handler won't get any logs.", appName, runId);
    }
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:21,代码来源:AbstractTwillController.java

示例6: BasicTwillContext

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
public BasicTwillContext(RunId runId, RunId appRunId, InetAddress host, String[] args, String[] appArgs,
                         TwillRunnableSpecification spec, int instanceId,
                         DiscoveryService discoveryService, DiscoveryServiceClient discoveryServiceClient,
                         ZKClient zkClient,
                         int instanceCount, int allowedMemoryMB, int virtualCores) {
  this.runId = runId;
  this.appRunId = appRunId;
  this.host = host;
  this.args = args;
  this.appArgs = appArgs;
  this.spec = spec;
  this.instanceId = instanceId;
  this.discoveryService = discoveryService;
  this.discoveryServiceClient = discoveryServiceClient;
  this.zkClient = zkClient;
  this.elections = new ElectionRegistry(zkClient);
  this.instanceCount = instanceCount;
  this.allowedMemoryMB = allowedMemoryMB;
  this.virtualCores = virtualCores;
}
 
开发者ID:apache,项目名称:twill,代码行数:21,代码来源:BasicTwillContext.java

示例7: createService

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
private Service createService(ZKClient zkClient, RunId runId) {
  return new AbstractTwillService(zkClient, runId) {

    private final CountDownLatch stopLatch = new CountDownLatch(1);

    @Override
    protected void doStart() throws Exception {
      LOG.info("Start");
    }

    @Override
    protected void doRun() throws Exception {
      stopLatch.await();
    }

    @Override
    protected void doStop() throws Exception {
      LOG.info("Stop");
    }

    @Override
    protected void triggerShutdown() {
      stopLatch.countDown();
    }
  };
}
 
开发者ID:apache,项目名称:twill,代码行数:27,代码来源:ControllerTest.java

示例8: prepare

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
@Override
public TwillPreparer prepare(TwillApplication application) {
  Preconditions.checkState(isRunning(), "Service not start. Please call start() first.");
  final TwillSpecification twillSpec = application.configure();
  final String appName = twillSpec.getName();

  return new YarnTwillPreparer(yarnConfig, twillSpec, yarnAppClient, zkClientService, locationFactory, jvmOptions,
                               new YarnTwillControllerFactory() {
    @Override
    public YarnTwillController create(RunId runId, Iterable<LogHandler> logHandlers,
                                      Callable<ProcessController<YarnApplicationReport>> startUp) {
      ZKClient zkClient = ZKClients.namespace(zkClientService, "/" + appName);
      YarnTwillController controller = listenController(new YarnTwillController(appName, runId, zkClient,
                                                                                logHandlers, startUp));
      synchronized (YarnTwillRunnerService.this) {
        Preconditions.checkArgument(!controllers.contains(appName, runId),
                                    "Application %s with runId %s is already running.", appName, runId);
        controllers.put(appName, runId, controller);
      }
      return controller;
    }
  });
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:24,代码来源:YarnTwillRunnerService.java

示例9: YarnTwillPreparer

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
YarnTwillPreparer(YarnConfiguration yarnConfig, TwillSpecification twillSpec,
                  YarnAppClient yarnAppClient, ZKClient zkClient,
                  LocationFactory locationFactory, String extraOptions,
                  YarnTwillControllerFactory controllerFactory) {
  this.yarnConfig = yarnConfig;
  this.twillSpec = twillSpec;
  this.yarnAppClient = yarnAppClient;
  this.zkClient = ZKClients.namespace(zkClient, "/" + twillSpec.getName());
  this.locationFactory = locationFactory;
  this.controllerFactory = controllerFactory;
  this.runId = RunIds.generate();
  this.credentials = createCredentials();
  this.reservedMemory = yarnConfig.getInt(Configs.Keys.JAVA_RESERVED_MEMORY_MB,
                                          Configs.Defaults.JAVA_RESERVED_MEMORY_MB);
  this.user = System.getProperty("user.name");
  this.extraOptions = extraOptions;
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:18,代码来源:YarnTwillPreparer.java

示例10: RewatchOnExpireWatcher

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
RewatchOnExpireWatcher(ZKClient client, ActionType actionType, String path, Watcher delegate) {
  this.client = client;
  this.actionType = actionType;
  this.path = path;
  this.delegate = delegate;
  this.lastResult = new AtomicMarkableReference<Object>(null, false);
}
 
开发者ID:apache,项目名称:twill,代码行数:8,代码来源:RewatchOnExpireWatcher.java

示例11: ReentrantDistributedLock

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
/**
 * Creates a distributed lock instance.
 *
 * @param zkClient the {@link ZKClient} to interact with the ZooKeeper used for the lock coordination
 * @param path the path in ZooKeeper where the lock coordination happens
 */
public ReentrantDistributedLock(ZKClient zkClient, String path) {
  this.zkClient = zkClient;
  this.path = path.startsWith("/") ? path : "/" + path;
  this.localLockNode = new ThreadLocal<String>();
  this.lock = new ReentrantLock();
}
 
开发者ID:apache,项目名称:twill,代码行数:13,代码来源:ReentrantDistributedLock.java

示例12: TwillContainerService

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
TwillContainerService(BasicTwillContext context, ContainerInfo containerInfo, ZKClient zkClient,
                      RunId runId, TwillRunnableSpecification specification, ClassLoader classLoader,
                      Configuration config, Location applicationLocation,
                      Map<String, String> defaultLogLevels, Map<String, String> logLevels) {
  super(zkClient, runId, config, applicationLocation);

  this.specification = specification;
  this.classLoader = classLoader;
  this.defaultLogLevels = ImmutableMap.copyOf(defaultLogLevels);
  this.oldLogLevels = new HashMap<>(defaultLogLevels);
  this.containerLiveNodeData = createLiveNodeData(
    containerInfo, isLoggerContext() ? logLevels : Collections.<String, String>emptyMap());
  this.context = context;
}
 
开发者ID:apache,项目名称:twill,代码行数:15,代码来源:TwillContainerService.java

示例13: updateController

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
private void updateController(final String appName, final RunId runId, final AtomicBoolean cancelled) {
  String instancePath = String.format("/%s/instances/%s", appName, runId.getId());

  // Fetch the content node.
  Futures.addCallback(zkClientService.getData(instancePath), new FutureCallback<NodeData>() {
    @Override
    public void onSuccess(NodeData result) {
      if (cancelled.get()) {
        return;
      }

      ApplicationMasterLiveNodeData amLiveNodeData = ApplicationMasterLiveNodeDecoder.decode(result);
      if (amLiveNodeData == null) {
        return;
      }

      synchronized (YarnTwillRunnerService.this) {
        if (!controllers.contains(appName, runId)) {
          ZKClient zkClient = ZKClients.namespace(zkClientService, "/" + appName);
          YarnAppClient yarnAppClient = new VersionDetectYarnAppClientFactory().create(new Configuration(yarnConfig));

          YarnTwillController controller = listenController(
            new YarnTwillController(appName, runId, zkClient, amLiveNodeData, yarnAppClient));
          controllers.put(appName, runId, controller);
          controller.start();
        }
      }
    }

    @Override
    public void onFailure(Throwable t) {
      LOG.warn("Failed in fetching application instance node.", t);
    }
  }, Threads.SAME_THREAD_EXECUTOR);
}
 
开发者ID:apache,项目名称:twill,代码行数:36,代码来源:YarnTwillRunnerService.java

示例14: TwillContainerLauncher

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
public TwillContainerLauncher(RuntimeSpecification runtimeSpec, ContainerInfo containerInfo,
                              ProcessLauncher.PrepareLaunchContext launchContext,
                              ZKClient zkClient, int instanceCount, JvmOptions jvmOpts,
                              int reservedMemory, double minHeapRatio,
                              Location secureStoreLocation) {
  this.runtimeSpec = runtimeSpec;
  this.containerInfo = containerInfo;
  this.launchContext = launchContext;
  this.zkClient = zkClient;
  this.instanceCount = instanceCount;
  this.jvmOpts = jvmOpts;
  this.reservedMemory = reservedMemory;
  this.minHeapRatio = minHeapRatio;
  this.secureStoreLocation = secureStoreLocation;
}
 
开发者ID:apache,项目名称:twill,代码行数:16,代码来源:TwillContainerLauncher.java

示例15: TwillContainerControllerImpl

import org.apache.twill.zookeeper.ZKClient; //导入依赖的package包/类
protected TwillContainerControllerImpl(ZKClient zkClient, RunId runId, String runnable, int instanceId,
                                       ProcessController<Void> processController) {
  super(runId, zkClient);
  this.runnable = runnable;
  this.instanceId = instanceId;
  this.processController = processController;
  this.shutdownLatch = new CountDownLatch(1);
}
 
开发者ID:apache,项目名称:twill,代码行数:9,代码来源:TwillContainerLauncher.java


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