示例#1
0
  /**
   * Stops this server.
   *
   * @param cancel Cancel flag.
   */
  public void stop(boolean cancel) {
    // Skip if did not start.
    if (srvEndpoint == null) return;

    // Stop accepting new client connections.
    U.cancel(acceptWorker);

    U.join(acceptWorker, log);

    // Stop server handler, no more requests on existing connections will be processed.
    try {
      hnd.stop();
    } catch (IgniteCheckedException e) {
      U.error(log, "Failed to stop IGFS server handler (will close client connections anyway).", e);
    }

    // Stop existing client connections.
    for (ClientWorker worker : clientWorkers) U.cancel(worker);

    U.join(clientWorkers, log);

    // IpcServerEndpoint.getPort contract states return -1 if there is no port to be registered.
    if (srvEndpoint.getPort() >= 0)
      igfsCtx
          .kernalContext()
          .ports()
          .deregisterPort(srvEndpoint.getPort(), TCP, srvEndpoint.getClass());

    try {
      igfsCtx.kernalContext().resource().cleanupGeneric(srvEndpoint);
    } catch (IgniteCheckedException e) {
      U.error(log, "Failed to cleanup server endpoint.", e);
    }
  }
  /**
   * Stops the server.
   *
   * @throws IgniteCheckedException
   */
  public void stop() throws IgniteCheckedException {
    // Stop TCP server.
    if (nioSrvr != null) nioSrvr.stop();

    U.cancel(shmemAcceptWorker);
    U.join(shmemAcceptWorker, log);

    U.cancel(shmemWorkers);
    U.join(shmemWorkers, log);

    shmemWorkers.clear();

    // Force closing on stop (safety).
    for (HadoopCommunicationClient client : clients.values()) client.forceClose();

    // Clear resources.
    nioSrvr = null;

    boundTcpPort = -1;
  }
  /**
   * Waits for all workers to finish.
   *
   * @param cancel Flag to indicate whether workers should be cancelled before waiting for them to
   *     finish.
   */
  public void join(boolean cancel) {
    if (cancel) U.cancel(workers);

    // Record current interrupted status of calling thread.
    boolean interrupted = Thread.interrupted();

    try {
      U.join(workers, log);
    } finally {
      // Reset interrupted flag on calling thread.
      if (interrupted) Thread.currentThread().interrupt();
    }
  }
  /** {@inheritDoc} */
  @Override
  public void close() {
    closed = true;

    U.closeQuiet(srvSock);

    if (gcWorker != null) {
      U.cancel(gcWorker);

      // This method may be called from already interrupted thread.
      // Need to ensure cleaning on close.
      boolean interrupted = Thread.interrupted();

      try {
        U.join(gcWorker);
      } catch (IgniteInterruptedCheckedException e) {
        U.warn(log, "Interrupted when stopping GC worker.", e);
      } finally {
        if (interrupted) Thread.currentThread().interrupt();
      }
    }
  }