Search in sources :

Example 1 with IoEnvironment

use of com.couchbase.client.core.env.IoEnvironment in project couchbase-elasticsearch-connector by couchbase.

the class CouchbaseHelper method applyCustomEnvironmentProperties.

private static void applyCustomEnvironmentProperties(ClusterEnvironment.Builder envBuilder, CouchbaseConfig config) {
    // Begin workaround for IoEnvironment config.
    // Prior to Java client 3.1.5, IoEnvironment isn't configurable
    // via system properties. Until then, handle it manually.
    Map<String, String> envProps = new HashMap<>(config.env());
    IoEnvironment.Builder ioEnvBuilder = IoEnvironment.builder();
    String nativeIoEnabled = envProps.remove("ioEnvironment.enableNativeIo");
    if (nativeIoEnabled != null) {
        ioEnvBuilder.enableNativeIo(Boolean.parseBoolean(nativeIoEnabled));
    }
    String eventLoopThreadCount = envProps.remove("ioEnvironment.eventLoopThreadCount");
    if (eventLoopThreadCount != null) {
        ioEnvBuilder.eventLoopThreadCount(Integer.parseInt(eventLoopThreadCount));
    }
    envBuilder.ioEnvironment(ioEnvBuilder);
    try {
        envBuilder.load(new AbstractMapPropertyLoader<CoreEnvironment.Builder>() {

            @Override
            protected Map<String, String> propertyMap() {
                return envProps;
            }
        });
    } catch (Exception e) {
        throw new ConfigException("Failed to apply Couchbase environment properties; " + e.getMessage());
    }
}
Also used : IoEnvironment(com.couchbase.client.core.env.IoEnvironment) HashMap(java.util.HashMap) ConfigException(com.couchbase.connector.config.ConfigException) ConnectionString(com.couchbase.client.core.util.ConnectionString) HashMap(java.util.HashMap) Map(java.util.Map) ConfigException(com.couchbase.connector.config.ConfigException)

Aggregations

IoEnvironment (com.couchbase.client.core.env.IoEnvironment)1 ConnectionString (com.couchbase.client.core.util.ConnectionString)1 ConfigException (com.couchbase.connector.config.ConfigException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1