Exemplo n.º 1
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();
  }
Exemplo n.º 2
0
  /**
   * Create server IPC endpoint.
   *
   * @param endpointCfg Endpoint configuration.
   * @param mgmt Management flag.
   * @return Server endpoint.
   * @throws IgniteCheckedException If failed.
   */
  private IpcServerEndpoint createEndpoint(IgfsIpcEndpointConfiguration endpointCfg, boolean mgmt)
      throws IgniteCheckedException {
    A.notNull(endpointCfg, "endpointCfg");

    IgfsIpcEndpointType typ = endpointCfg.getType();

    if (typ == null)
      throw new IgniteCheckedException("Failed to create server endpoint (type is not specified)");

    switch (typ) {
      case SHMEM:
        {
          IpcSharedMemoryServerEndpoint endpoint =
              new IpcSharedMemoryServerEndpoint(
                  igfsCtx.kernalContext().config().getWorkDirectory());

          endpoint.setPort(endpointCfg.getPort());
          endpoint.setSize(endpointCfg.getMemorySize());
          endpoint.setTokenDirectoryPath(endpointCfg.getTokenDirectoryPath());

          return endpoint;
        }
      case TCP:
        {
          IpcServerTcpEndpoint endpoint = new IpcServerTcpEndpoint();

          endpoint.setHost(endpointCfg.getHost());
          endpoint.setPort(endpointCfg.getPort());
          endpoint.setManagement(mgmt);

          return endpoint;
        }
      default:
        throw new IgniteCheckedException(
            "Failed to create server endpoint (type is unknown): " + typ);
    }
  }