/** * 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); }
/** * 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)); }
/** * 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); }
/** * 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(); }
/** * 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(); }
/** * 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(); }
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; }
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); } }
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); } }
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; } }
private <T> void copy(Map<?, ?> map, Option<T> option) { set(option, option.cast(map.get(option))); }
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; } }
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; } }
/** {@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); } }
/** {@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); } }
/** {@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); } }
/** {@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); } }
/** {@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); } }
/** {@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); } }