Search in sources :

Example 1 with HotRodURI

use of org.infinispan.client.hotrod.impl.HotRodURI in project infinispan by infinispan.

the class ConfigurationBuilder method withProperties.

@Override
public ConfigurationBuilder withProperties(Properties properties) {
    TypedProperties typed = TypedProperties.toTypedProperties(properties);
    if (typed.containsKey(ConfigurationProperties.URI)) {
        HotRodURI uri = HotRodURI.create(typed.getProperty(ConfigurationProperties.URI));
        this.read(uri.toConfigurationBuilder().build());
    }
    if (typed.containsKey(ConfigurationProperties.ASYNC_EXECUTOR_FACTORY)) {
        this.asyncExecutorFactory().factoryClass(typed.getProperty(ConfigurationProperties.ASYNC_EXECUTOR_FACTORY, null, true));
    }
    this.asyncExecutorFactory().withExecutorProperties(typed);
    String balancingStrategyClass = typed.getProperty(ConfigurationProperties.REQUEST_BALANCING_STRATEGY, null, true);
    if (balancingStrategyClass != null) {
        this.balancingStrategy(balancingStrategyClass);
    }
    if (typed.containsKey(ConfigurationProperties.CLIENT_INTELLIGENCE)) {
        this.clientIntelligence(typed.getEnumProperty(ConfigurationProperties.CLIENT_INTELLIGENCE, ClientIntelligence.class, ClientIntelligence.getDefault(), true));
    }
    this.connectionPool.withPoolProperties(typed);
    if (typed.containsKey(ConfigurationProperties.CONNECT_TIMEOUT)) {
        this.connectionTimeout(typed.getIntProperty(ConfigurationProperties.CONNECT_TIMEOUT, connectionTimeout, true));
    }
    if (typed.containsKey(ConfigurationProperties.HASH_FUNCTION_PREFIX + ".1")) {
        log.warn("Hash function version 1 is no longer supported");
    }
    for (int i = 0; i < consistentHashImpl.length; i++) {
        if (consistentHashImpl[i] != null) {
            int version = i + 1;
            String hashClassName = typed.getProperty(ConfigurationProperties.HASH_FUNCTION_PREFIX + "." + version, null, true);
            if (hashClassName != null) {
                this.consistentHashImpl(version, hashClassName);
            }
        }
    }
    if (typed.containsKey(ConfigurationProperties.FORCE_RETURN_VALUES)) {
        this.forceReturnValues(typed.getBooleanProperty(ConfigurationProperties.FORCE_RETURN_VALUES, forceReturnValues, true));
    }
    if (typed.containsKey(ConfigurationProperties.KEY_SIZE_ESTIMATE)) {
        this.keySizeEstimate(typed.getIntProperty(ConfigurationProperties.KEY_SIZE_ESTIMATE, keySizeEstimate, true));
    }
    if (typed.containsKey(ConfigurationProperties.MARSHALLER)) {
        this.marshaller(typed.getProperty(ConfigurationProperties.MARSHALLER, null, true));
    }
    if (typed.containsKey(ConfigurationProperties.CONTEXT_INITIALIZERS)) {
        String initializers = typed.getProperty(ConfigurationProperties.CONTEXT_INITIALIZERS);
        for (String sci : initializers.split(",")) this.addContextInitializer(sci);
    }
    if (typed.containsKey(ConfigurationProperties.PROTOCOL_VERSION)) {
        this.version(ProtocolVersion.parseVersion(typed.getProperty(ConfigurationProperties.PROTOCOL_VERSION, protocolVersion.toString(), true)));
    }
    String serverList = typed.getProperty(ConfigurationProperties.SERVER_LIST, null, true);
    if (serverList != null) {
        this.servers.clear();
        this.addServers(serverList);
    }
    if (typed.containsKey(ConfigurationProperties.SO_TIMEOUT)) {
        this.socketTimeout(typed.getIntProperty(ConfigurationProperties.SO_TIMEOUT, socketTimeout, true));
    }
    if (typed.containsKey(ConfigurationProperties.TCP_NO_DELAY)) {
        this.tcpNoDelay(typed.getBooleanProperty(ConfigurationProperties.TCP_NO_DELAY, tcpNoDelay, true));
    }
    if (typed.containsKey(ConfigurationProperties.TCP_KEEP_ALIVE)) {
        this.tcpKeepAlive(typed.getBooleanProperty(ConfigurationProperties.TCP_KEEP_ALIVE, tcpKeepAlive, true));
    }
    if (typed.containsKey(ConfigurationProperties.VALUE_SIZE_ESTIMATE)) {
        this.valueSizeEstimate(typed.getIntProperty(ConfigurationProperties.VALUE_SIZE_ESTIMATE, valueSizeEstimate, true));
    }
    if (typed.containsKey(ConfigurationProperties.MAX_RETRIES)) {
        this.maxRetries(typed.getIntProperty(ConfigurationProperties.MAX_RETRIES, maxRetries, true));
    }
    this.security.ssl().withProperties(properties);
    this.security.authentication().withProperties(properties);
    String serialAllowList = typed.getProperty(ConfigurationProperties.JAVA_SERIAL_WHITELIST);
    if (serialAllowList != null && !serialAllowList.isEmpty()) {
        org.infinispan.commons.logging.Log.CONFIG.deprecatedProperty(ConfigurationProperties.JAVA_SERIAL_WHITELIST, ConfigurationProperties.JAVA_SERIAL_ALLOWLIST);
        String[] classes = serialAllowList.split(",");
        Collections.addAll(this.allowListRegExs, classes);
    }
    serialAllowList = typed.getProperty(ConfigurationProperties.JAVA_SERIAL_ALLOWLIST);
    if (serialAllowList != null && !serialAllowList.isEmpty()) {
        String[] classes = serialAllowList.split(",");
        Collections.addAll(this.allowListRegExs, classes);
    }
    if (typed.containsKey(ConfigurationProperties.BATCH_SIZE)) {
        this.batchSize(typed.getIntProperty(ConfigurationProperties.BATCH_SIZE, batchSize, true));
    }
    // TODO read TRANSACTION_TIMEOUT property after TransactionConfigurationBuilder is removed.
    transaction.withTransactionProperties(typed);
    nearCache.withProperties(properties);
    Map<String, String> xsiteProperties = typed.entrySet().stream().filter(e -> ((String) e.getKey()).startsWith(ConfigurationProperties.CLUSTER_PROPERTIES_PREFIX)).collect(Collectors.toMap(e -> ConfigurationProperties.CLUSTER_PROPERTIES_PREFIX_REGEX.matcher((String) e.getKey()).replaceFirst(""), e -> StringPropertyReplacer.replaceProperties((String) e.getValue())));
    xsiteProperties.forEach((key, value) -> {
        ClusterConfigurationBuilder cluster = this.addCluster(key);
        parseServers(value, cluster::addClusterNode);
    });
    Set<String> cachesNames = typed.keySet().stream().map(k -> (String) k).filter(k -> k.startsWith(ConfigurationProperties.CACHE_PREFIX)).map(k -> k.charAt(CACHE_PREFIX_LENGTH) == '[' ? k.substring(CACHE_PREFIX_LENGTH + 1, k.indexOf(']', CACHE_PREFIX_LENGTH)) : k.substring(CACHE_PREFIX_LENGTH, k.indexOf('.', CACHE_PREFIX_LENGTH + 1))).collect(Collectors.toSet());
    for (String cacheName : cachesNames) {
        this.remoteCache(cacheName).withProperties(typed);
    }
    statistics.withProperties(properties);
    if (typed.containsKey(ConfigurationProperties.TRANSPORT_FACTORY)) {
        this.transportFactory = Util.getInstance(typed.getProperty(ConfigurationProperties.TRANSPORT_FACTORY), classLoader.get());
    }
    return this;
}
Also used : Arrays(java.util.Arrays) StringPropertyReplacer(org.infinispan.commons.util.StringPropertyReplacer) HotRodURI(org.infinispan.client.hotrod.impl.HotRodURI) Log(org.infinispan.client.hotrod.logging.Log) ConsistentHashV2(org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV2) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) HashSet(java.util.HashSet) LogFactory(org.infinispan.client.hotrod.logging.LogFactory) Matcher(java.util.regex.Matcher) SerializationContextInitializer(org.infinispan.protostream.SerializationContextInitializer) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Features(org.infinispan.commons.util.Features) TypedProperties(org.infinispan.commons.util.TypedProperties) URI(java.net.URI) WeakReference(java.lang.ref.WeakReference) FailoverRequestBalancingStrategy(org.infinispan.client.hotrod.FailoverRequestBalancingStrategy) TransportFactory(org.infinispan.client.hotrod.TransportFactory) HOTROD(org.infinispan.client.hotrod.logging.Log.HOTROD) SegmentConsistentHash(org.infinispan.client.hotrod.impl.consistenthash.SegmentConsistentHash) Builder(org.infinispan.commons.configuration.Builder) Properties(java.util.Properties) ConfigurationProperties(org.infinispan.client.hotrod.impl.ConfigurationProperties) Util(org.infinispan.commons.util.Util) Set(java.util.Set) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ProtocolVersion(org.infinispan.client.hotrod.ProtocolVersion) ConsistentHash(org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash) Pattern(java.util.regex.Pattern) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) Collections(java.util.Collections) RoundRobinBalancingStrategy(org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy) Marshaller(org.infinispan.commons.marshall.Marshaller) TypedProperties(org.infinispan.commons.util.TypedProperties) HotRodURI(org.infinispan.client.hotrod.impl.HotRodURI)

Aggregations

WeakReference (java.lang.ref.WeakReference)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Set (java.util.Set)1 TimeUnit (java.util.concurrent.TimeUnit)1 BiConsumer (java.util.function.BiConsumer)1 Supplier (java.util.function.Supplier)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 FailoverRequestBalancingStrategy (org.infinispan.client.hotrod.FailoverRequestBalancingStrategy)1 ProtocolVersion (org.infinispan.client.hotrod.ProtocolVersion)1 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)1