Package org.apache.twill.discovery

Examples of org.apache.twill.discovery.ServiceDiscovered


    TwillController controller = runner.prepare(new SleepApp())
      .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
      .start();

    try {
      ServiceDiscovered discovered = controller.discoverService("sleep");
      Assert.assertTrue(YarnTestUtils.waitForSize(discovered, 2, 60));
    } finally {
      controller.stopAndWait();
    }
  }
View Full Code Here


      final int port = Integer.parseInt(getContext().getArguments()[0]);
      getContext().announce(SERVICE_NAME, port);

      final CountDownLatch discoveredLatch = new CountDownLatch(1);

      ServiceDiscovered serviceDiscovered = getContext().discover(SERVICE_NAME);
      serviceDiscovered.watchChanges(new ServiceDiscovered.ChangeListener() {
        @Override
        public void onChange(ServiceDiscovered serviceDiscovered) {
          // Try to find a discoverable that is not this instance
          for (Discoverable discoverable : serviceDiscovered) {
            int discoveredPort = discoverable.getSocketAddress().getPort();
View Full Code Here

      final int port = Integer.parseInt(getContext().getArguments()[0]);
      getContext().announce(SERVICE_NAME, port);

      final CountDownLatch discoveredLatch = new CountDownLatch(1);

      ServiceDiscovered serviceDiscovered = getContext().discover(SERVICE_NAME);
      serviceDiscovered.watchChanges(new ServiceDiscovered.ChangeListener() {
        @Override
        public void onChange(ServiceDiscovered serviceDiscovered) {
          // Try to find a discoverable that is not this instance
          for (Discoverable discoverable : serviceDiscovered) {
            int discoveredPort = discoverable.getSocketAddress().getPort();
View Full Code Here

    return applicationManager.isRunning(serviceId);
  }

  @Override
  public URL getServiceURL() {
    ServiceDiscovered serviceDiscovered = discoveryServiceClient.discover(String.format("service.%s.%s.%s",
                                                                                        accountId,
                                                                                        applicationId,
                                                                                        serviceName));
    EndpointStrategy endpointStrategy = new RandomEndpointStrategy(serviceDiscovered);
    Discoverable discoverable = endpointStrategy.pick();
    if (discoverable != null) {
      return createURL(discoverable, applicationId, serviceName);
    }

    final SynchronousQueue<URL> discoverableQueue = new SynchronousQueue<URL>();
    Cancellable discoveryCancel = serviceDiscovered.watchChanges(new ServiceDiscovered.ChangeListener() {
      @Override
      public void onChange(ServiceDiscovered serviceDiscovered) {
        try {
          URL url = createURL(serviceDiscovered.iterator().next(), applicationId, serviceName);
          discoverableQueue.offer(url);
        } catch (NoSuchElementException e) {
          LOG.debug("serviceDiscovered is empty");
        }
      }
View Full Code Here

    typeManager.startAndWait();
    opExecutorClient.startAndWait();
    httpService.startAndWait();

    // setting watch for ops executor service that we need to be running to operate correctly
    ServiceDiscovered discover = discoveryServiceClient.discover(Constants.Service.DATASET_EXECUTOR);
    opExecutorDiscovered = SettableFuture.create();
    opExecutorServiceWatch = discover.watchChanges(
      new ServiceDiscovered.ChangeListener() {
        @Override
        public void onChange(ServiceDiscovered serviceDiscovered) {
          if (!Iterables.isEmpty(serviceDiscovered)) {
            LOG.info("Discovered {} service", Constants.Service.DATASET_EXECUTOR);
View Full Code Here

    return runId;
  }

  @Override
  public URL getServiceURL(final String applicationId, final String serviceId) {
    ServiceDiscovered serviceDiscovered = discoveryServiceClient.discover(String.format("service.%s.%s.%s",
                                                                                        getAccountId(),
                                                                                        applicationId,
                                                                                        serviceId));
    EndpointStrategy endpointStrategy = new RandomEndpointStrategy(serviceDiscovered);
    Discoverable discoverable = endpointStrategy.pick();
    if (discoverable != null) {
      return createURL(discoverable, applicationId, serviceId);
    }

    final SynchronousQueue<URL> discoverableQueue = new SynchronousQueue<URL>();
    Cancellable discoveryCancel = serviceDiscovered.watchChanges(new ServiceDiscovered.ChangeListener() {
      @Override
      public void onChange(ServiceDiscovered serviceDiscovered) {
        try {
          URL url = createURL(serviceDiscovered.iterator().next(), applicationId, serviceId);
          discoverableQueue.offer(url);
        } catch (NoSuchElementException e) {
          LOG.debug("serviceDiscovered is empty");
        }
      }
View Full Code Here

  }

  @Override
  protected void startUp() throws Exception {
    // Wait till DatasetService is discovered then start the scheduler.
    ServiceDiscovered discover = discoveryServiceClient.discover(Constants.Service.DATASET_MANAGER);
    cancellable = discover.watchChanges(
      new ServiceDiscovered.ChangeListener() {
        @Override
        public void onChange(ServiceDiscovered serviceDiscovered) {
          if (!Iterables.isEmpty(serviceDiscovered) && !schedulerStarted.get()) {
            LOG.info("Starting scheduler, Discovered {} dataset service(s)",
View Full Code Here

TOP

Related Classes of org.apache.twill.discovery.ServiceDiscovered

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.