Search in sources :

Example 1 with Options

use of org.xnio.Options 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();
    }
}
Also used : Options(org.xnio.Options) OptionMap(org.xnio.OptionMap) Option(org.xnio.Option) OptionMap(org.xnio.OptionMap) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 Option (org.xnio.Option)1 OptionMap (org.xnio.OptionMap)1 Options (org.xnio.Options)1