Ejemplo n.º 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);
    }
  }
Ejemplo n.º 2
0
  /**
   * Starts this server.
   *
   * @throws IgniteCheckedException If failed.
   */
  public void start() throws IgniteCheckedException {
    srvEndpoint = createEndpoint(endpointCfg, mgmt);

    if (U.isWindows() && srvEndpoint instanceof IpcSharedMemoryServerEndpoint)
      throw new IgniteCheckedException(
          IpcSharedMemoryServerEndpoint.class.getSimpleName()
              + " should not be configured on Windows (configure "
              + IpcServerTcpEndpoint.class.getSimpleName()
              + ")");

    if (srvEndpoint instanceof IpcServerTcpEndpoint) {
      IpcServerTcpEndpoint srvEndpoint0 = (IpcServerTcpEndpoint) srvEndpoint;

      srvEndpoint0.setManagement(mgmt);

      if (srvEndpoint0.getHost() == null) {
        if (mgmt) {
          String locHostName = igfsCtx.kernalContext().config().getLocalHost();

          try {
            srvEndpoint0.setHost(U.resolveLocalHost(locHostName).getHostAddress());
          } catch (IOException e) {
            throw new IgniteCheckedException("Failed to resolve local host: " + locHostName, e);
          }
        } else
          // Bind non-management endpoint to 127.0.0.1 by default.
          srvEndpoint0.setHost("127.0.0.1");
      }
    }

    igfsCtx.kernalContext().resource().injectGeneric(srvEndpoint);

    srvEndpoint.start();

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

    hnd = new IgfsIpcHandler(igfsCtx, endpointCfg, mgmt);

    // Start client accept worker.
    acceptWorker = new AcceptWorker();
  }