Examples of Cancellable


Examples of org.apache.twill.common.Cancellable

  private Cancellable watchLiveApps() {
    final Map<String, Cancellable> watched = Maps.newConcurrentMap();

    final AtomicBoolean cancelled = new AtomicBoolean(false);
    // Watch child changes in the root, which gives all application names.
    final Cancellable cancellable = ZKOperations.watchChildren(zkClientService, "/",
                                                               new ZKOperations.ChildrenCallback() {
      @Override
      public void updated(NodeChildren nodeChildren) {
        if (cancelled.get()) {
          return;
        }

        Set<String> apps = ImmutableSet.copyOf(nodeChildren.getChildren());

        // For each for the application name, watch for ephemeral nodes under /instances.
        for (final String appName : apps) {
          if (watched.containsKey(appName)) {
            continue;
          }

          final String instancePath = String.format("/%s/instances", appName);
          watched.put(appName,
                      ZKOperations.watchChildren(zkClientService, instancePath, new ZKOperations.ChildrenCallback() {
            @Override
            public void updated(NodeChildren nodeChildren) {
              if (cancelled.get()) {
                return;
              }
              if (nodeChildren.getChildren().isEmpty()) {     // No more child, means no live instances
                Cancellable removed = watched.remove(appName);
                if (removed != null) {
                  removed.cancel();
                }
                return;
              }
              synchronized (YarnTwillRunnerService.this) {
                // For each of the children, which the node name is the runId,
                // fetch the application Id and construct TwillController.
                for (final RunId runId : Iterables.transform(nodeChildren.getChildren(), STRING_TO_RUN_ID)) {
                  if (controllers.contains(appName, runId)) {
                    continue;
                  }
                  updateController(appName, runId, cancelled);
                }
              }
            }
          }));
        }

        // Remove app watches for apps that are gone. Removal of controller from controllers table is done
        // in the state listener attached to the twill controller.
        for (String removeApp : Sets.difference(watched.keySet(), apps)) {
          watched.remove(removeApp).cancel();
        }
      }
    });
    return new Cancellable() {
      @Override
      public void cancel() {
        cancelled.set(true);
        cancellable.cancel();
        for (Cancellable c : watched.values()) {
View Full Code Here

Examples of org.apache.twill.common.Cancellable

      }
    });

    // Return a Cancellable that remove the handler from the registry map and notify it become follower.
    // It also select the new leader and notify it.
    return new Cancellable() {
      @Override
      public void cancel() {
        Futures.getUnchecked(executor.submit(new Runnable() {
          @Override
          public void run() {
View Full Code Here

Examples of org.apache.twill.common.Cancellable

  @Override
  public final Cancellable addListener(Listener listener, Executor executor) {
    Preconditions.checkNotNull(listener, "Listener shouldn't be null.");
    Preconditions.checkNotNull(executor, "Executor shouldn't be null.");
    final ListenerCaller caller = new ListenerCaller(listener, executor);
    Cancellable cancellable = new Cancellable() {
      @Override
      public void cancel() {
        listeners.remove(caller);
      }
    };

    Cancellable result = listeners.putIfAbsent(caller, cancellable);
    if (result != null) {
      return result;
    }

    caller.init(state.get());
View Full Code Here

Examples of org.apache.twill.common.Cancellable

    }

    @Override
    protected void doStart() {
      final List<Cancellable> cancellables = Lists.newArrayList();
      this.cancellable = new Cancellable() {
        @Override
        public void cancel() {
          for (Cancellable c : cancellables) {
            c.cancel();
          }
View Full Code Here

Examples of org.apache.twill.common.Cancellable

  @Override
  public Cancellable electLeader(String name, ElectionHandler participantHandler) {
    // Namespace it under the application runId
    String electionName = String.format("%s.%s", applicationRunId.getId(), name);

    final Cancellable delegate = electionRegistry.join(electionName, participantHandler);
    Cancellable cancel = new Cancellable() {
      @Override
      public void cancel() {
        try {
          delegate.cancel();
        } finally {
View Full Code Here

Examples of org.apache.twill.common.Cancellable

            return address;
          }
        }));
      }

      return new WebappProgramController(program.getName(), runId, httpService, new Cancellable() {
        @Override
        public void cancel() {
          for (Cancellable cancellable : cancellables) {
            cancellable.cancel();
          }
View Full Code Here

Examples of org.apache.twill.common.Cancellable

    LOG.info("In run method in HTTP Service");
    Future<Service.State> completion = Services.getCompletionFuture(service);
    service.startAndWait();
    // announce the twill runnable
    int port = service.getBindAddress().getPort();
    Cancellable contextCancellable = getContext().announce(serviceName, port);
    LOG.info("Announced HTTP Service");

    // Create a Timer thread to periodically collect handler that are no longer in used and call destroy on it
    Timer timer = new Timer("http-handler-gc", true);
    timer.scheduleAtFixedRate(createHandlerDestroyTask(), HANDLER_CLEANUP_PERIOD_MS, HANDLER_CLEANUP_PERIOD_MS);

    try {
      completion.get();
    } catch (InterruptedException e) {
      LOG.error("Caught exception in HTTP Service run", e);
    } catch (ExecutionException e) {
      LOG.error("Caught exception in HTTP Service run", e);
    } finally {
      // once the service has been stopped, don't announce it anymore.
      contextCancellable.cancel();
      timer.cancel();

      // Go through all non-cleanup'ed handler and call destroy() upon them
      // At this point, there should be no call to any handler method, hence it's safe to call from this thread
      for (HandlerContextPair handlerContextPair : handlerReferences.values()) {
View Full Code Here

Examples of org.bukkit.event.Cancellable

    if (!clazz.isAssignableFrom(event.getClass())){
      // Strange but true.
      return;
    }
    // TODO: profiling option !
    final Cancellable cancellable = isCancellable ? (Cancellable) event : null;

    final MethodEntry[] entries = this.entries;
    for (int i = 0; i < entries.length ; i++){
      final MethodEntry entry = entries[i];
      try {
        if (!isCancellable || !entry.ignoreCancelled || !cancellable.isCancelled()) entry.method.invoke(entry.listener, event);
      } catch (Throwable t) {
        // IllegalArgumentException IllegalAccessException InvocationTargetException
        onError(entry, event, t);
      }
    }
View Full Code Here

Examples of org.jboss.as.controller.Cancellable

        protected final void readRequest(final InputStream inputStream) throws IOException {

            expectHeader(inputStream, ModelControllerClientProtocol.PARAM_REQUEST_ID);
            int operationId = StreamUtils.readInt(inputStream);

            Cancellable operation = getAsynchronousOperation(operationId);
            cancelled = operation!= null && operation.cancel();
        }
View Full Code Here

Examples of org.openide.util.Cancellable

        public RunningLongTask(LongTask task, Runnable runnable, String taskName) {
            this.task = task;
            this.runnable = runnable;
            ProgressTicketProvider progressProvider = Lookup.getDefault().lookup(ProgressTicketProvider.class);
            if (progressProvider != null) {
                this.progress = progressProvider.createTicket(taskName, new Cancellable() {

                    public boolean cancel() {
                        LongTaskExecutor.this.cancel();
                        return true;
                    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.