Search in sources :

Example 1 with TypedProperties

use of org.infinispan.commons.util.TypedProperties 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)

Example 2 with TypedProperties

use of org.infinispan.commons.util.TypedProperties in project infinispan by infinispan.

the class AuthenticationConfigurationBuilder method withProperties.

@Override
public ConfigurationBuilder withProperties(Properties properties) {
    TypedProperties typed = TypedProperties.toTypedProperties(properties);
    if (typed.containsKey(ConfigurationProperties.SASL_MECHANISM))
        saslMechanism(typed.getProperty(ConfigurationProperties.SASL_MECHANISM, saslMechanism, true));
    Object prop = typed.get(ConfigurationProperties.AUTH_CALLBACK_HANDLER);
    if (prop instanceof String) {
        String cbhClassName = StringPropertyReplacer.replaceProperties((String) prop);
        CallbackHandler handler = Util.getInstance(cbhClassName, builder.getBuilder().classLoader());
        this.callbackHandler(handler);
    } else if (prop instanceof CallbackHandler) {
        this.callbackHandler((CallbackHandler) prop);
    }
    if (typed.containsKey(ConfigurationProperties.AUTH_USERNAME))
        username(typed.getProperty(ConfigurationProperties.AUTH_USERNAME, username, true));
    if (typed.containsKey(ConfigurationProperties.AUTH_PASSWORD))
        password(typed.getProperty(ConfigurationProperties.AUTH_PASSWORD, null, true));
    if (typed.containsKey(ConfigurationProperties.AUTH_TOKEN))
        token(typed.getProperty(ConfigurationProperties.AUTH_TOKEN, token, true));
    if (typed.containsKey(ConfigurationProperties.AUTH_REALM))
        realm(typed.getProperty(ConfigurationProperties.AUTH_REALM, realm, true));
    if (typed.containsKey(ConfigurationProperties.AUTH_SERVER_NAME))
        serverName(typed.getProperty(ConfigurationProperties.AUTH_SERVER_NAME, serverName, true));
    if (typed.containsKey(ConfigurationProperties.AUTH_CLIENT_SUBJECT))
        this.clientSubject((Subject) typed.get(ConfigurationProperties.AUTH_CLIENT_SUBJECT));
    Map<String, String> saslProperties = typed.entrySet().stream().filter(e -> ((String) e.getKey()).startsWith(ConfigurationProperties.SASL_PROPERTIES_PREFIX)).collect(Collectors.toMap(e -> ConfigurationProperties.SASL_PROPERTIES_PREFIX_REGEX.matcher((String) e.getKey()).replaceFirst(""), e -> StringPropertyReplacer.replaceProperties((String) e.getValue())));
    if (!saslProperties.isEmpty())
        this.saslProperties(saslProperties);
    if (typed.containsKey(ConfigurationProperties.USE_AUTH))
        this.enabled(typed.getBooleanProperty(ConfigurationProperties.USE_AUTH, enabled, true));
    return builder.getBuilder();
}
Also used : StringPropertyReplacer(org.infinispan.commons.util.StringPropertyReplacer) Properties(java.util.Properties) ConfigurationProperties(org.infinispan.client.hotrod.impl.ConfigurationProperties) Util(org.infinispan.commons.util.Util) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) Subject(javax.security.auth.Subject) CallbackHandler(javax.security.auth.callback.CallbackHandler) Map(java.util.Map) BasicCallbackHandler(org.infinispan.client.hotrod.security.BasicCallbackHandler) TokenCallbackHandler(org.infinispan.client.hotrod.security.TokenCallbackHandler) TypedProperties(org.infinispan.commons.util.TypedProperties) Sasl(javax.security.sasl.Sasl) VoidCallbackHandler(org.infinispan.client.hotrod.security.VoidCallbackHandler) HOTROD(org.infinispan.client.hotrod.logging.Log.HOTROD) Callback(javax.security.auth.callback.Callback) Builder(org.infinispan.commons.configuration.Builder) CallbackHandler(javax.security.auth.callback.CallbackHandler) BasicCallbackHandler(org.infinispan.client.hotrod.security.BasicCallbackHandler) TokenCallbackHandler(org.infinispan.client.hotrod.security.TokenCallbackHandler) VoidCallbackHandler(org.infinispan.client.hotrod.security.VoidCallbackHandler) TypedProperties(org.infinispan.commons.util.TypedProperties) Subject(javax.security.auth.Subject)

Example 3 with TypedProperties

use of org.infinispan.commons.util.TypedProperties in project infinispan by infinispan.

the class TransactionConfigurationBuilder method withTransactionProperties.

void withTransactionProperties(Properties properties) {
    TypedProperties typed = TypedProperties.toTypedProperties(properties);
    transactionMode(typed.getEnumProperty(TRANSACTION_MODE, TransactionMode.class, transactionMode, true));
    transactionManagerLookup(tlmFromString(typed.getProperty(TRANSACTION_MANAGER_LOOKUP, tlmClass(), true)));
    setTimeoutMillis(typed.getLongProperty(TRANSACTION_TIMEOUT, timeout, true));
}
Also used : TypedProperties(org.infinispan.commons.util.TypedProperties)

Example 4 with TypedProperties

use of org.infinispan.commons.util.TypedProperties in project infinispan by infinispan.

the class RestClientConfiguration method properties.

public Properties properties() {
    TypedProperties properties = new TypedProperties();
    properties.setProperty(RestClientConfigurationProperties.PROTOCOL, protocol().name());
    properties.setProperty(RestClientConfigurationProperties.CONNECT_TIMEOUT, Long.toString(connectionTimeout()));
    properties.setProperty(RestClientConfigurationProperties.SO_TIMEOUT, socketTimeout());
    properties.setProperty(RestClientConfigurationProperties.TCP_NO_DELAY, tcpNoDelay());
    properties.setProperty(RestClientConfigurationProperties.TCP_KEEP_ALIVE, tcpKeepAlive());
    properties.setProperty(RestClientConfigurationProperties.CONTEXT_PATH, tcpKeepAlive());
    StringBuilder servers = new StringBuilder();
    for (ServerConfiguration server : servers()) {
        if (servers.length() > 0) {
            servers.append(";");
        }
        servers.append(server.host()).append(":").append(server.port());
    }
    properties.setProperty(RestClientConfigurationProperties.SERVER_LIST, servers.toString());
    properties.setProperty(RestClientConfigurationProperties.USE_SSL, Boolean.toString(security.ssl().enabled()));
    if (security.ssl().keyStoreFileName() != null)
        properties.setProperty(RestClientConfigurationProperties.KEY_STORE_FILE_NAME, security.ssl().keyStoreFileName());
    if (security.ssl().keyStorePassword() != null)
        properties.setProperty(RestClientConfigurationProperties.KEY_STORE_PASSWORD, new String(security.ssl().keyStorePassword()));
    if (security.ssl().keyStoreCertificatePassword() != null)
        properties.setProperty(RestClientConfigurationProperties.KEY_STORE_CERTIFICATE_PASSWORD, new String(security.ssl().keyStoreCertificatePassword()));
    if (security.ssl().trustStoreFileName() != null)
        properties.setProperty(RestClientConfigurationProperties.TRUST_STORE_FILE_NAME, security.ssl().trustStoreFileName());
    if (security.ssl().trustStorePassword() != null)
        properties.setProperty(RestClientConfigurationProperties.TRUST_STORE_PASSWORD, new String(security.ssl().trustStorePassword()));
    if (security.ssl().sniHostName() != null)
        properties.setProperty(RestClientConfigurationProperties.SNI_HOST_NAME, security.ssl().sniHostName());
    if (security.ssl().protocol() != null)
        properties.setProperty(RestClientConfigurationProperties.SSL_PROTOCOL, security.ssl().protocol());
    if (security.ssl().sslContext() != null)
        properties.put(RestClientConfigurationProperties.SSL_CONTEXT, security.ssl().sslContext());
    if (security.ssl().trustManagers() != null)
        properties.put(RestClientConfigurationProperties.TRUST_MANAGERS, security.ssl().trustManagers());
    properties.setProperty(RestClientConfigurationProperties.USE_AUTH, Boolean.toString(security.authentication().enabled()));
    if (security.authentication().mechanism() != null)
        properties.setProperty(RestClientConfigurationProperties.AUTH_MECHANISM, security.authentication().mechanism());
    return properties;
}
Also used : TypedProperties(org.infinispan.commons.util.TypedProperties)

Example 5 with TypedProperties

use of org.infinispan.commons.util.TypedProperties in project infinispan by infinispan.

the class IndexingConfigurationBuilder method ensureSingleIndexingConfig.

private void ensureSingleIndexingConfig() {
    TypedProperties typedProperties = attributes.attribute(PROPERTIES).get();
    boolean hasMultiIndexConfig = typedProperties.keySet().stream().map(Object::toString).filter(k -> k.contains(".")).map(k -> k.substring(k.lastIndexOf('.'))).anyMatch(s -> typedProperties.keySet().stream().filter(k -> k.toString().endsWith(s)).count() > 1);
    if (hasMultiIndexConfig) {
        throw CONFIG.foundDifferentIndexConfigPerType();
    }
}
Also used : Arrays(java.util.Arrays) Properties(java.util.Properties) KEY_TRANSFORMERS(org.infinispan.configuration.cache.IndexingConfiguration.KEY_TRANSFORMERS) CacheConfigurationException(org.infinispan.commons.CacheConfigurationException) Util(org.infinispan.commons.util.Util) Set(java.util.Set) PROPERTIES(org.infinispan.commons.configuration.AbstractTypedPropertiesConfiguration.PROPERTIES) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) CONFIG(org.infinispan.util.logging.Log.CONFIG) StringPropertyReplacer.replaceProperties(org.infinispan.commons.util.StringPropertyReplacer.replaceProperties) AUTO_CONFIG(org.infinispan.configuration.cache.IndexingConfiguration.AUTO_CONFIG) HashSet(java.util.HashSet) STORAGE(org.infinispan.configuration.cache.IndexingConfiguration.STORAGE) AttributeSet(org.infinispan.commons.configuration.attributes.AttributeSet) Paths(java.nio.file.Paths) PATH(org.infinispan.configuration.cache.IndexingConfiguration.PATH) ENABLED(org.infinispan.configuration.cache.IndexingConfiguration.ENABLED) Map(java.util.Map) INDEXED_ENTITIES(org.infinispan.configuration.cache.IndexingConfiguration.INDEXED_ENTITIES) TypedProperties(org.infinispan.commons.util.TypedProperties) INDEX(org.infinispan.configuration.cache.IndexingConfiguration.INDEX) Collections(java.util.Collections) Builder(org.infinispan.commons.configuration.Builder) TypedProperties(org.infinispan.commons.util.TypedProperties)

Aggregations

TypedProperties (org.infinispan.commons.util.TypedProperties)23 Map (java.util.Map)4 Properties (java.util.Properties)4 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 Collectors (java.util.stream.Collectors)3 Builder (org.infinispan.commons.configuration.Builder)3 Util (org.infinispan.commons.util.Util)3 WeakReference (java.lang.ref.WeakReference)2 AccessControlContext (java.security.AccessControlContext)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 ThreadFactory (java.util.concurrent.ThreadFactory)2 TimeUnit (java.util.concurrent.TimeUnit)2 Supplier (java.util.function.Supplier)2 FailoverRequestBalancingStrategy (org.infinispan.client.hotrod.FailoverRequestBalancingStrategy)2 ProtocolVersion (org.infinispan.client.hotrod.ProtocolVersion)2 TransportFactory (org.infinispan.client.hotrod.TransportFactory)2