Search in sources :

Example 1 with ProtoStreamMarshaller

use of org.infinispan.commons.marshall.ProtoStreamMarshaller in project keycloak by keycloak.

the class DefaultHotRodConnectionProviderFactory method lazyInit.

public void lazyInit() {
    if (config.getBoolean("embedded", false)) {
        HotRodUtils.createHotRodMapStoreServer(config.getInt("embeddedPort", 11444));
    }
    ConfigurationBuilder remoteBuilder = new ConfigurationBuilder();
    remoteBuilder.addServer().host(config.get("host", "localhost")).port(config.getInt("port", 11444)).clientIntelligence(ClientIntelligence.HASH_DISTRIBUTION_AWARE).marshaller(new ProtoStreamMarshaller());
    if (config.getBoolean("enableSecurity", true)) {
        remoteBuilder.security().authentication().saslMechanism("SCRAM-SHA-512").username(config.get("username", "admin")).password(config.get("password", "admin")).realm(config.get("realm", "default"));
    }
    boolean configureRemoteCaches = config.getBoolean("configureRemoteCaches", false);
    if (configureRemoteCaches) {
        configureRemoteCaches(remoteBuilder);
    }
    remoteBuilder.addContextInitializer(ProtoSchemaInitializer.INSTANCE);
    remoteCacheManager = new RemoteCacheManager(remoteBuilder.build());
    Set<String> remoteCaches = HotRodMapStorageProviderFactory.ENTITY_DESCRIPTOR_MAP.values().stream().map(HotRodEntityDescriptor::getCacheName).collect(Collectors.toSet());
    if (configureRemoteCaches) {
        // access the caches to force their creation
        remoteCaches.forEach(remoteCacheManager::getCache);
    }
    registerSchemata(ProtoSchemaInitializer.INSTANCE);
    RemoteCacheManagerAdmin administration = remoteCacheManager.administration();
    if (config.getBoolean("reindexAllCaches", false)) {
        LOG.infof("Reindexing all caches. This can take a long time to complete. While the rebuild operation is in progress, queries might return fewer results.");
        remoteCaches.forEach(administration::reindexCache);
    } else {
        String reindexCaches = config.get("reindexCaches", "");
        if (reindexCaches != null) {
            Arrays.stream(reindexCaches.split(",")).map(String::trim).filter(e -> !e.isEmpty()).filter(remoteCaches::contains).peek(cacheName -> LOG.infof("Reindexing %s cache. This can take a long time to complete. While the rebuild operation is in progress, queries might return fewer results.", cacheName)).forEach(administration::reindexCache);
        }
    }
}
Also used : RemoteCacheManagerAdmin(org.infinispan.client.hotrod.RemoteCacheManagerAdmin) Arrays(java.util.Arrays) GeneratedSchema(org.infinispan.protostream.GeneratedSchema) Logger(org.jboss.logging.Logger) URISyntaxException(java.net.URISyntaxException) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) KeycloakSession(org.keycloak.models.KeycloakSession) Set(java.util.Set) RemoteCache(org.infinispan.client.hotrod.RemoteCache) Collectors(java.util.stream.Collectors) ProtoSchemaInitializer(org.keycloak.models.map.storage.hotRod.common.ProtoSchemaInitializer) HotRodMapStorageProviderFactory(org.keycloak.models.map.storage.hotRod.HotRodMapStorageProviderFactory) RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) ProtobufMetadataManagerConstants(org.infinispan.query.remote.client.ProtobufMetadataManagerConstants) ClientIntelligence(org.infinispan.client.hotrod.configuration.ClientIntelligence) KeycloakSessionFactory(org.keycloak.models.KeycloakSessionFactory) URI(java.net.URI) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) HotRodEntityDescriptor(org.keycloak.models.map.storage.hotRod.common.HotRodEntityDescriptor) HotRodUtils(org.keycloak.models.map.storage.hotRod.common.HotRodUtils) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) RemoteCacheManagerAdmin(org.infinispan.client.hotrod.RemoteCacheManagerAdmin)

Example 2 with ProtoStreamMarshaller

use of org.infinispan.commons.marshall.ProtoStreamMarshaller in project hono by eclipse.

the class HotrodCache method from.

/**
 * Creates a new remote cache.
 *
 * @param vertx The vert.x instance to run on.
 * @param properties The remote cache configuration.
 * @param commonCacheConfig The common cache configuration.
 * @return The remote cache.
 * @throws NullPointerException if any of the parameters are {@code null}.
 */
public static HotrodCache<String, String> from(final Vertx vertx, final InfinispanRemoteConfigurationProperties properties, final CommonCacheConfig commonCacheConfig) {
    Objects.requireNonNull(vertx);
    Objects.requireNonNull(properties);
    Objects.requireNonNull(commonCacheConfig);
    final var configBuilder = properties.getConfigurationBuilder();
    configBuilder.marshaller(new ProtoStreamMarshaller());
    final var configuration = configBuilder.build();
    if (LOG.isInfoEnabled()) {
        LOG.info("creating HotrodCache using configuration: {}", configuration);
    }
    return new HotrodCache<>(vertx, new RemoteCacheManager(configuration, false), commonCacheConfig.getCacheName(), commonCacheConfig.getCheckKey(), commonCacheConfig.getCheckValue());
}
Also used : RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller)

Aggregations

RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)2 ProtoStreamMarshaller (org.infinispan.commons.marshall.ProtoStreamMarshaller)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Arrays (java.util.Arrays)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 RemoteCache (org.infinispan.client.hotrod.RemoteCache)1 RemoteCacheManagerAdmin (org.infinispan.client.hotrod.RemoteCacheManagerAdmin)1 ClientIntelligence (org.infinispan.client.hotrod.configuration.ClientIntelligence)1 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)1 GeneratedSchema (org.infinispan.protostream.GeneratedSchema)1 ProtobufMetadataManagerConstants (org.infinispan.query.remote.client.ProtobufMetadataManagerConstants)1 Logger (org.jboss.logging.Logger)1 KeycloakSession (org.keycloak.models.KeycloakSession)1 KeycloakSessionFactory (org.keycloak.models.KeycloakSessionFactory)1 HotRodMapStorageProviderFactory (org.keycloak.models.map.storage.hotRod.HotRodMapStorageProviderFactory)1 HotRodEntityDescriptor (org.keycloak.models.map.storage.hotRod.common.HotRodEntityDescriptor)1 HotRodUtils (org.keycloak.models.map.storage.hotRod.common.HotRodUtils)1 ProtoSchemaInitializer (org.keycloak.models.map.storage.hotRod.common.ProtoSchemaInitializer)1