/**
   * Sets configuration properties from the map.
   *
   * @param endpointCfg Map of properties.
   * @throws IgniteCheckedException If invalid property name or value.
   */
  public void setupConfiguration(Map<String, String> endpointCfg) throws IgniteCheckedException {
    for (Map.Entry<String, String> e : endpointCfg.entrySet()) {
      try {
        switch (e.getKey()) {
          case "type":
          case "host":
          case "management":
            // Ignore these properties
            break;

          case "port":
            setPort(Integer.parseInt(e.getValue()));
            break;

          case "size":
            setSize(Integer.parseInt(e.getValue()));
            break;

          case "tokenDirectoryPath":
            setTokenDirectoryPath(e.getValue());
            break;

          default:
            throw new IgniteCheckedException(
                "Invalid property '" + e.getKey() + "' of " + getClass().getSimpleName());
        }
      } catch (Throwable t) {
        if (t instanceof IgniteCheckedException || t instanceof Error) throw t;

        throw new IgniteCheckedException(
            "Invalid value '"
                + e.getValue()
                + "' of the property '"
                + e.getKey()
                + "' in "
                + getClass().getSimpleName(),
            t);
      }
    }
  }
Esempio 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);
    }
  }