org.xnio.Option.cast()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中org.xnio.Option.cast()方法的一些代码示例,展示了Option.cast()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.cast()方法的具体详情如下:
包路径:org.xnio.Option
类名称:Option
方法名:cast

Option.cast介绍

[英]Return the given object as the type of this option. If the cast could not be completed, an exception is thrown.
[中]将给定对象作为此选项的类型返回。如果无法完成强制转换,将引发异常。

代码示例

代码示例来源:origin: wildfly/wildfly

/**
 * Return the given object as the type of this option.  If the cast could not be completed, an exception is thrown.
 *
 * @param o the object to cast
 * @param defaultVal the value to return if {@code o} is {@code null}
 *
 * @return the cast object
 *
 * @throws ClassCastException if the object is not of a compatible type
 */
public final T cast(Object o, T defaultVal) throws ClassCastException {
  return o == null ? defaultVal : cast(o);
}

代码示例来源:origin: wildfly/wildfly

/**
 * Get the value of an option from this option map.
 *
 * @param option the option to get
 * @param <T> the type of the option
 * @return the option value, or {@code null} if it is not present
 */
public <T> T get(Option<T> option) {
  return option.cast(value.get(option));
}

代码示例来源:origin: wildfly/wildfly

/**
 * Get the value of an option from this option map, with a specified default if the value is missing.
 *
 * @param option the option to get
 * @param defaultValue the value to return if the option is not set
 * @param <T> the type of the option
 * @return the option value, or {@code null} if it is not present
 */
public <T> T get(Option<T> option, T defaultValue) {
  final Object o = value.get(option);
  return o == null ? defaultValue : option.cast(o);
}

代码示例来源:origin: wildfly/wildfly

/**
 * Get a int value from this option map, with a specified default if the value is missing.
 *
 * @param option the option to get
 * @param defaultValue the default value if the option is not present
 * @return the result
 */
public int get(Option<Integer> option, int defaultValue) {
  final Object o = value.get(option);
  return o == null ? defaultValue : option.cast(o).intValue();
}

代码示例来源:origin: wildfly/wildfly

/**
 * Get a boolean value from this option map, with a specified default if the value is missing.
 *
 * @param option the option to get
 * @param defaultValue the default value if the option is not present
 * @return the result
 */
public boolean get(Option<Boolean> option, boolean defaultValue) {
  final Object o = value.get(option);
  return o == null ? defaultValue : option.cast(o).booleanValue();
}

代码示例来源:origin: wildfly/wildfly

/**
 * Get a long value from this option map, with a specified default if the value is missing.
 *
 * @param option the option to get
 * @param defaultValue the default value if the option is not present
 * @return the result
 */
public long get(Option<Long> option, long defaultValue) {
  final Object o = value.get(option);
  return o == null ? defaultValue : option.cast(o).longValue();
}

代码示例来源:origin: wildfly/wildfly

@Override
public <T> T getOption(Option<T> option) throws IOException {
  if (option.equals(Options.WORKER_IO_THREADS)) {
    return option.cast(workerThreads.length);
  } else if (option.equals(Options.STACK_SIZE)) {
    return option.cast(workerStackSize);
  } else {
    return super.getOption(option);
  }
}

代码示例来源:origin: wildfly/wildfly

public <T> T setOption(final Option<T> option, final T value) throws IllegalArgumentException, IOException {
  T result;
  if (option == Options.READ_TIMEOUT) {
    final NioPipeSourceConduit conduit = sourceConduit;
    result = conduit == null ? null : option.cast(Integer.valueOf(conduit.getAndSetReadTimeout(value == null ? 0 : Options.READ_TIMEOUT.cast(value).intValue())));
  } else if (option == Options.WRITE_TIMEOUT) {
    final NioPipeSinkConduit conduit = sinkConduit;
    result = conduit == null ? null : option.cast(Integer.valueOf(conduit.getAndSetWriteTimeout(value == null ? 0 : Options.WRITE_TIMEOUT.cast(value).intValue())));
  } else {
    return null;
  }
  return result;
}

代码示例来源:origin: wildfly/wildfly

public <T> T getOption(final Option<T> option) throws IOException {
  if (option == Options.SSL_CLIENT_AUTH_MODE) {
    return option.cast(clientAuthMode);
  } else if (option == Options.SSL_USE_CLIENT_MODE) {
    return option.cast(Boolean.valueOf(useClientMode != 0));
  } else if (option == Options.SSL_ENABLE_SESSION_CREATION) {
    return option.cast(Boolean.valueOf(enableSessionCreation != 0));
  } else if (option == Options.SSL_ENABLED_CIPHER_SUITES) {
    final String[] cipherSuites = this.cipherSuites;
    return cipherSuites == null ? null : option.cast(Sequence.of(cipherSuites));
  } else if (option == Options.SSL_ENABLED_PROTOCOLS) {
    final String[] protocols = this.protocols;
    return protocols == null ? null : option.cast(Sequence.of(protocols));
  } else {
    return tcpServer.getOption(option);
  }
}

代码示例来源:origin: wildfly/wildfly

public <T> T getOption(final Option<T> option) throws IOException {
  if (option == Options.SSL_CLIENT_AUTH_MODE) {
    return option.cast(clientAuthMode);
  } else if (option == Options.SSL_USE_CLIENT_MODE) {
    return option.cast(Boolean.valueOf(useClientMode != 0));
  } else if (option == Options.SSL_ENABLE_SESSION_CREATION) {
    return option.cast(Boolean.valueOf(enableSessionCreation != 0));
  } else if (option == Options.SSL_ENABLED_CIPHER_SUITES) {
    final String[] cipherSuites = this.cipherSuites;
    return cipherSuites == null ? null : option.cast(Sequence.of(cipherSuites));
  } else if (option == Options.SSL_ENABLED_PROTOCOLS) {
    final String[] protocols = this.protocols;
    return protocols == null ? null : option.cast(Sequence.of(protocols));
  } else {
    return tcpServer.getOption(option);
  }
}

代码示例来源:origin: wildfly/wildfly

public <T> T getOption(final Option<T> option) throws IOException {
  if (option == Options.READ_TIMEOUT) {
    final NioPipeSourceConduit conduit = sourceConduit;
    return conduit == null ? null : option.cast(Integer.valueOf(conduit.getReadTimeout()));
  } else if (option == Options.WRITE_TIMEOUT) {
    final NioPipeSinkConduit conduit = sinkConduit;
    return conduit == null ? null : option.cast(Integer.valueOf(conduit.getWriteTimeout()));
  } else {
    return null;
  }
}

代码示例来源:origin: wildfly/wildfly

private <T> void copy(Map<?, ?> map, Option<T> option) {
  set(option, option.cast(map.get(option)));
}

代码示例来源:origin: wildfly/wildfly

public <T> T getOption(final Option<T> option) throws IOException {
  if (! supportsOption(option)) {
    return null;
  } else if (option.equals(Options.WORKER_TASK_CORE_THREADS)) {
    return option.cast(Integer.valueOf(taskPool.getCorePoolSize()));
  } else if (option.equals(Options.WORKER_TASK_MAX_THREADS)) {
    return option.cast(Integer.valueOf(taskPool.getMaximumPoolSize()));
  } else if (option.equals(Options.WORKER_TASK_KEEPALIVE)) {
    return option.cast(Integer.valueOf((int) Math.min((long) Integer.MAX_VALUE, taskPool.getKeepAliveTime(TimeUnit.MILLISECONDS))));
  } else {
    return null;
  }
}

代码示例来源:origin: wildfly/wildfly

public <T> T getOption(final Option<T> option) throws UnsupportedOptionException, IOException {
  final DatagramChannel channel = datagramChannel;
  final DatagramSocket socket = channel.socket();
  if (option == Options.RECEIVE_BUFFER) {
    return option.cast(Integer.valueOf(socket.getReceiveBufferSize()));
  } else if (option == Options.SEND_BUFFER) {
    return option.cast(Integer.valueOf(socket.getSendBufferSize()));
  } else if (option == Options.BROADCAST) {
    return option.cast(Boolean.valueOf(socket.getBroadcast()));
  } else if (option == Options.IP_TRAFFIC_CLASS) {
    return option.cast(Integer.valueOf(socket.getTrafficClass()));
  } else if (option == Options.MULTICAST_TTL) {
    return option.cast(channel.getOption(StandardSocketOptions.IP_MULTICAST_TTL));
  } else {
    return null;
  }
}

代码示例来源:origin: wildfly/wildfly

/** {@inheritDoc} */
@Override
public <T> T getOption(final Option<T> option) throws IOException {
  if (option == Options.SSL_CLIENT_AUTH_MODE) {
    final SSLEngine engine = sslConduitEngine.getEngine();
    return option.cast(engine.getNeedClientAuth() ? SslClientAuthMode.REQUIRED : engine.getWantClientAuth() ? SslClientAuthMode.REQUESTED : SslClientAuthMode.NOT_REQUESTED);
  } else {
    return option == Options.SECURE ? option.cast(Boolean.valueOf(tls)) : connection.getOption(option);
  }
}

代码示例来源:origin: wildfly/wildfly

/** {@inheritDoc} */
@Override
public <T> T getOption(final Option<T> option) throws IOException {
  if (option == Options.SSL_CLIENT_AUTH_MODE) {
    final SSLEngine engine = conduit.getEngine();
    return option.cast(engine.getNeedClientAuth() ? SslClientAuthMode.REQUIRED : engine.getWantClientAuth() ? SslClientAuthMode.REQUESTED : SslClientAuthMode.NOT_REQUESTED);
  } else {
    return option == Options.SECURE ? option.cast(Boolean.valueOf(conduit.isTls())) : streamConnection.getOption(option);
  }
}

代码示例来源:origin: wildfly/wildfly

/** {@inheritDoc} */
@Override
public <T> T getOption(final Option<T> option) throws IOException {
  if (option == Options.SSL_CLIENT_AUTH_MODE) {
    return option.cast(engine.getNeedClientAuth() ? SslClientAuthMode.REQUIRED : engine.getWantClientAuth() ? SslClientAuthMode.REQUESTED : SslClientAuthMode.NOT_REQUESTED);
  } else {
    return option == Options.SECURE ? (T)Boolean.TRUE : delegate.getOption(option);
  }
}

代码示例来源:origin: wildfly/wildfly

/** {@inheritDoc} */
@Override
public <T> T setOption(final Option<T> option, final T value) throws IllegalArgumentException, IOException {
  if (option == Options.SSL_CLIENT_AUTH_MODE) {
    try {
      return option.cast(engine.getNeedClientAuth() ? SslClientAuthMode.REQUIRED : engine.getWantClientAuth() ? SslClientAuthMode.REQUESTED : SslClientAuthMode.NOT_REQUESTED);
    } finally {
      engine.setNeedClientAuth(value == SslClientAuthMode.REQUIRED);
      engine.setWantClientAuth(value == SslClientAuthMode.REQUESTED);
    }
  } else if (option == Options.SECURE) {
    throw new IllegalArgumentException();
  } else {
    return delegate.setOption(option, value);
  }
}

代码示例来源:origin: wildfly/wildfly

/** {@inheritDoc} */
@Override
public <T> T setOption(final Option<T> option, final T value) throws IllegalArgumentException, IOException {
  if (option == Options.SSL_CLIENT_AUTH_MODE) {
    final SSLEngine engine = sslConduitEngine.getEngine();
    try {
      return option.cast(engine.getNeedClientAuth() ? SslClientAuthMode.REQUIRED : engine.getWantClientAuth() ? SslClientAuthMode.REQUESTED : SslClientAuthMode.NOT_REQUESTED);
    } finally {
      engine.setNeedClientAuth(value == SslClientAuthMode.REQUIRED);
      engine.setWantClientAuth(value == SslClientAuthMode.REQUESTED);
    }
  } else if (option == Options.SECURE) {
    throw new IllegalArgumentException();
  } else {
    return connection.setOption(option, value);
  }
}

代码示例来源:origin: wildfly/wildfly

/** {@inheritDoc} */
@Override
public <T> T setOption(final Option<T> option, final T value) throws IllegalArgumentException, IOException {
  if (option == Options.SSL_CLIENT_AUTH_MODE) {
    final SSLEngine engine = conduit.getEngine();
    try {
      return option.cast(engine.getNeedClientAuth() ? SslClientAuthMode.REQUIRED : engine.getWantClientAuth() ? SslClientAuthMode.REQUESTED : SslClientAuthMode.NOT_REQUESTED);
    } finally {
      engine.setNeedClientAuth(value == SslClientAuthMode.REQUIRED);
      engine.setWantClientAuth(value == SslClientAuthMode.REQUESTED);
    }
  } else if (option == Options.SECURE) {
    throw new IllegalArgumentException();
  } else {
    return streamConnection.setOption(option, value);
  }
}

相关文章