use of org.xnio.Option in project camel by apache.
the class UndertowEndpoint method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
if (sslContextParameters != null) {
sslContext = sslContextParameters.createSSLContext(getCamelContext());
}
// create options map
if (options != null && !options.isEmpty()) {
// favor to use the classloader that loaded the user application
ClassLoader cl = getComponent().getCamelContext().getApplicationContextClassLoader();
if (cl == null) {
cl = Options.class.getClassLoader();
}
OptionMap.Builder builder = OptionMap.builder();
for (Map.Entry<String, Object> entry : options.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (key != null && value != null) {
// upper case and dash as underscore
key = key.toUpperCase(Locale.ENGLISH).replace('-', '_');
// must be field name
key = Options.class.getName() + "." + key;
Option option = Option.fromString(key, cl);
value = option.parseValue(value.toString(), cl);
LOG.trace("Parsed option {}={}", option.getName(), value);
builder.set(option, value);
}
}
optionMap = builder.getMap();
} else {
// use an empty map
optionMap = OptionMap.EMPTY;
}
// and then configure these default options if they have not been explicit configured
if (keepAlive != null && !optionMap.contains(Options.KEEP_ALIVE)) {
// rebuild map
OptionMap.Builder builder = OptionMap.builder();
builder.addAll(optionMap).set(Options.KEEP_ALIVE, keepAlive);
optionMap = builder.getMap();
}
if (tcpNoDelay != null && !optionMap.contains(Options.TCP_NODELAY)) {
// rebuild map
OptionMap.Builder builder = OptionMap.builder();
builder.addAll(optionMap).set(Options.TCP_NODELAY, tcpNoDelay);
optionMap = builder.getMap();
}
if (reuseAddresses != null && !optionMap.contains(Options.REUSE_ADDRESSES)) {
// rebuild map
OptionMap.Builder builder = OptionMap.builder();
builder.addAll(optionMap).set(Options.REUSE_ADDRESSES, tcpNoDelay);
optionMap = builder.getMap();
}
}
use of org.xnio.Option in project undertow by undertow-io.
the class UndertowXnioSsl method createSslTcpServer.
@SuppressWarnings("deprecation")
public AcceptingChannel<ConnectedSslStreamChannel> createSslTcpServer(final XnioWorker worker, final InetSocketAddress bindAddress, final ChannelListener<? super AcceptingChannel<ConnectedSslStreamChannel>> acceptListener, final OptionMap optionMap) throws IOException {
final AcceptingChannel<SslConnection> server = createSslConnectionServer(worker, bindAddress, null, optionMap);
final AcceptingChannel<ConnectedSslStreamChannel> acceptingChannel = new AcceptingChannel<ConnectedSslStreamChannel>() {
public ConnectedSslStreamChannel accept() throws IOException {
final SslConnection connection = server.accept();
return connection == null ? null : new AssembledConnectedSslStreamChannel(connection, connection.getSourceChannel(), connection.getSinkChannel());
}
public ChannelListener.Setter<? extends AcceptingChannel<ConnectedSslStreamChannel>> getAcceptSetter() {
return ChannelListeners.getDelegatingSetter(server.getAcceptSetter(), this);
}
public ChannelListener.Setter<? extends AcceptingChannel<ConnectedSslStreamChannel>> getCloseSetter() {
return ChannelListeners.getDelegatingSetter(server.getCloseSetter(), this);
}
public SocketAddress getLocalAddress() {
return server.getLocalAddress();
}
public <A extends SocketAddress> A getLocalAddress(final Class<A> type) {
return server.getLocalAddress(type);
}
public void suspendAccepts() {
server.suspendAccepts();
}
public void resumeAccepts() {
server.resumeAccepts();
}
public boolean isAcceptResumed() {
return server.isAcceptResumed();
}
public void wakeupAccepts() {
server.wakeupAccepts();
}
public void awaitAcceptable() throws IOException {
server.awaitAcceptable();
}
public void awaitAcceptable(final long time, final TimeUnit timeUnit) throws IOException {
server.awaitAcceptable(time, timeUnit);
}
public XnioWorker getWorker() {
return server.getWorker();
}
@Deprecated
public XnioExecutor getAcceptThread() {
return server.getAcceptThread();
}
public XnioIoThread getIoThread() {
return server.getIoThread();
}
public void close() throws IOException {
server.close();
}
public boolean isOpen() {
return server.isOpen();
}
public boolean supportsOption(final Option<?> option) {
return server.supportsOption(option);
}
public <T> T getOption(final Option<T> option) throws IOException {
return server.getOption(option);
}
public <T> T setOption(final Option<T> option, final T value) throws IllegalArgumentException, IOException {
return server.setOption(option, value);
}
};
acceptingChannel.getAcceptSetter().set(acceptListener);
return acceptingChannel;
}
use of org.xnio.Option in project wildfly by wildfly.
the class RemotingProfileAdd method createChannelOptionMap.
private OptionMap createChannelOptionMap(final OperationContext context, final ModelNode channelCreationOptionsNode) throws OperationFailedException {
final OptionMap optionMap;
if (channelCreationOptionsNode.isDefined()) {
final OptionMap.Builder optionMapBuilder = OptionMap.builder();
final ClassLoader loader = this.getClass().getClassLoader();
for (final Property optionProperty : channelCreationOptionsNode.asPropertyList()) {
final String name = optionProperty.getName();
final ModelNode propValueModel = optionProperty.getValue();
final String type = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_TYPE.resolveModelAttribute(context, propValueModel).asString();
final String optionClassName = this.getClassNameForChannelOptionType(type);
final String fullyQualifiedOptionName = optionClassName + "." + name;
final Option option = Option.fromString(fullyQualifiedOptionName, loader);
final String value = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_VALUE.resolveModelAttribute(context, propValueModel).asString();
optionMapBuilder.set(option, option.parseValue(value, loader));
}
optionMap = optionMapBuilder.getMap();
} else {
optionMap = OptionMap.EMPTY;
}
return optionMap;
}
use of org.xnio.Option in project wildfly by wildfly.
the class EJB3RemoteServiceAdd method getChannelCreationOptions.
private OptionMap getChannelCreationOptions(final OperationContext context) throws OperationFailedException {
// read the full model of the current resource
final ModelNode fullModel = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
final ModelNode channelCreationOptions = fullModel.get(EJB3SubsystemModel.CHANNEL_CREATION_OPTIONS);
if (channelCreationOptions.isDefined() && channelCreationOptions.asInt() > 0) {
final ClassLoader loader = this.getClass().getClassLoader();
final OptionMap.Builder builder = OptionMap.builder();
for (final Property optionProperty : channelCreationOptions.asPropertyList()) {
final String name = optionProperty.getName();
final ModelNode propValueModel = optionProperty.getValue();
final String type = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_TYPE.resolveModelAttribute(context, propValueModel).asString();
final String optionClassName = getClassNameForChannelOptionType(type);
final String fullyQualifiedOptionName = optionClassName + "." + name;
final Option option = Option.fromString(fullyQualifiedOptionName, loader);
final String value = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_VALUE.resolveModelAttribute(context, propValueModel).asString();
builder.set(option, option.parseValue(value, loader));
}
return builder.getMap();
}
return OptionMap.EMPTY;
}
Aggregations