Cancel build and wait for build session done

@return {@code true} if the build session is done and {@code false}
if time out happens
960971
public boolean cancel(int timeout, TimeUnit timeoutUnit) throws InterruptedException {
        if (isCanceled()) {
            return true;
        }

        cancelLatch.countDown();

        try {
            return doneLatch.await(timeout, timeoutUnit);
        } finally {
            new DefaultCurrentProcess().infanticide();
        }
    }
1223192
@Override
  public boolean stop()
  {
    if (! _lifecycle.toStopping())
      return false;

    log.finest(this + " stopping");

    closeConnections();

    destroy();

    return true;
  }
654201
def cancel(self):
        
        done = self.finished.is_set()
        self.finished.set()
        return not done
348967
private void stopWaitForHandshake() {
        if (waitForHandshakeTask != null) {
            boolean cancelled = waitForHandshakeTask.cancel(true);
            waitForHandshakeTask = null;
            if (cancelled && log.isDebugEnabled()) {
                log.debug("waitForHandshake was cancelled for {}", sessionId);
            }
        }
    }
1230034
private static boolean waitForServerDown(int port, long timeout) {
    long start = System.currentTimeMillis();
    while (true) {
      try {
        Socket sock = new Socket("localhost", port);
        try {
          OutputStream outstream = sock.getOutputStream();
          outstream.write("stat".getBytes());
          outstream.flush();
        } finally {
          sock.close();
        }
      } catch (IOException e) {
        return true;
      }

      if (System.currentTimeMillis() > start + timeout) {
        break;
      }
      try {
        Thread.sleep(250);
      } catch (InterruptedException e) {
        // ignore
      }
    }
    return false;
  }
700056
private boolean isReady() {
    if (this.status != Status.READY) {
      // e.g. if the node is disabled, it is not ready to run.
      return false;
    }
    for (final Node parent : this.parents) {
      if (!parent.status.isSuccessEffectively()) {
        return false;
      }
    }
    return true;
  }
954179
@Override
    public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
        return true;
    }
794383
public boolean shutdown() {
    mServer.shutdown();
    try {
      return mServer.awaitTermination(mServerShutdownTimeoutMs, TimeUnit.MILLISECONDS);
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
      return false;
    } finally {
      mServer.shutdownNow();
    }
  }
903645
public static boolean discard(Source source, int timeout, TimeUnit timeUnit) {
    try {
      return skipAll(source, timeout, timeUnit);
    } catch (IOException e) {
      return false;
    }
  }
1226200
public boolean waitForReady() throws InterruptedException {
        // wait for the framework to be set.
        if (waitForFramework() == null) {
            return false;
        }

        frameworkLaunched.await();
        if (!frameworkLaunchSuccess) {
            return false;
        }

        // Now look for the FrameworkReady service in the service registry
        Collection<ServiceReference<FrameworkReady>> readyServiceRefs;
        try {
            readyServiceRefs = systemBundleCtx.getServiceReferences(FrameworkReady.class, null);
        } catch (InvalidSyntaxException e) {
            throw new IllegalStateException(e); // unlikely.
        } catch (IllegalStateException ex) {
            // The framework might have been stopped before we finished starting
            if (framework.getState() != Bundle.ACTIVE) {
                waitForFrameworkStop();
                return false;
            } else {
                throw ex;
            }
        }

        // If we have any, we will wait for them...
        if (readyServiceRefs != null) {
            for (ServiceReference<FrameworkReady> readyServiceRef : readyServiceRefs) {
                FrameworkReady ready = systemBundleCtx.getService(readyServiceRef);
                if (ready != null) {
                    ready.waitForFrameworkReady();
                }
            }
        }
        // Check if some component declared a fatal start error by initiating
        // framework stop before we were fully started.  If so, wait for the
        // framework to finish stopping, then report an error.
        if (framework.getState() != Bundle.ACTIVE) {
            waitForFrameworkStop();
            return false;
        }

        return true;
    }
1276814
public boolean isCancelled() {
    Object r;
    return ((r = result) instanceof AltResult)
        && (((AltResult) r).ex instanceof CancellationException);
  }
151165
public CallOptions withWaitForReady() {
    CallOptions newOptions = new CallOptions(this);
    newOptions.waitForReady = Boolean.TRUE;
    return newOptions;
  }
198801
public static boolean execute(AbstractBuild build, BuildListener listener) {
        PrintStream logger = listener.getLogger();
        // Check all downstream Project of the project, not just those defined by BuildTrigger
        // TODO this may not yet be up to date if rebuildDependencyGraphAsync has been used; need a method to wait for the last call made before now to finish
        final DependencyGraph graph = Jenkins.getInstance().getDependencyGraph();
        List<Dependency> downstreamProjects = new ArrayList<>(
                graph.getDownstreamDependencies(build.getProject()));
        // Sort topologically
        downstreamProjects.sort(new Comparator<Dependency>() {
            public int compare(Dependency lhs, Dependency rhs) {
                // Swapping lhs/rhs to get reverse sort:
                return graph.compare(rhs.getDownstreamProject(), lhs.getDownstreamProject());
            }
        });

        for (Dependency dep : downstreamProjects) {
            List<Action> buildActions = new ArrayList<>();
            if (dep.shouldTriggerBuild(build, listener, buildActions)) {
                AbstractProject p = dep.getDownstreamProject();
                // Allow shouldTriggerBuild to return false first, in case it is skipping because of a lack of Item.READ/DISCOVER permission:
                if (p.isDisabled()) {
                    logger.println(Messages.BuildTrigger_Disabled(ModelHyperlinkNote.encodeTo(p)));
                    continue;
                }
                boolean scheduled = p.scheduleBuild(p.getQuietPeriod(), new UpstreamCause((Run)build), buildActions.toArray(new Action[0]));
                if (Jenkins.getInstance().getItemByFullName(p.getFullName()) == p) {
                    String name = ModelHyperlinkNote.encodeTo(p);
                    if (scheduled) {
                        logger.println(Messages.BuildTrigger_Triggering(name));
                    } else {
                        logger.println(Messages.BuildTrigger_InQueue(name));
                    }
                } // otherwise upstream users should not know that it happened
            }
        }

        return true;
    }
298565
public synchronized boolean stopServer() {

        if (!isProxyRunning) {
            return false;
        }

        isProxyRunning = false;
        HttpUtil.closeServerSocket(proxySocket);

        try {
            thread.join();   //(PORT_TIME_OUT);
            
        } catch (Exception e) {
        }

        proxySocket = null;

        return true;
    }
451188
@Override
	public boolean onActivityTimeout() throws Exception
    {
    	if (!transport.isClosed())
    	{
    		log.warn("#"+id+" Timeout waiting for client activity ("+authTimeout+"s), dropping client.");
    		stop();
    	}
    	return true;
    }
964430
@Override
    public boolean postBuild(MavenBuildProxy build, MavenProject pom, BuildListener listener)
            throws InterruptedException, IOException {
        build.executeAsync(new BuildCallable<Void, IOException>() {
            // record is transient, so needs to make a copy first
            private final Set<MavenDependency> d = dependencies;

            public Void call(MavenBuild build) throws IOException, InterruptedException {
                // add the action
                //TODO: [by yl] These actions are persisted into the build.xml of each build run - we need another
                //context to store these actions
                build.getActions().add(new MavenDependenciesRecord(build, d));
                return null;
            }
        });
        return true;
    }
1102280
boolean isReady() {
        final ContainerAddress[] ds = destinations.get();
        if (ds == null)
            return false;
        for (final ContainerAddress d : ds)
            if (d == null)
                return false;
        final boolean ret = ds.length != 0; // this method is only called in tests and this needs to be true there.

        if (ret && LOGGER.isDebugEnabled())
            LOGGER.debug("at {} to {} is Ready " + shorthand(ds), thisNodeId, clusterId);

        return ret;
    }