Search in sources :

Example 1 with CacheMode

use of org.infinispan.configuration.cache.CacheMode in project hibernate-orm by hibernate.

the class CorrectnessTestCase method beforeClass.

@BeforeClassOnce
public void beforeClass() {
    TestResourceTracker.testStarted(getClass().getSimpleName());
    Arrays.asList(new File(System.getProperty("java.io.tmpdir")).listFiles((dir, name) -> name.startsWith("family_") || name.startsWith("invalidations-"))).stream().forEach(f -> f.delete());
    StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true").applySetting(Environment.USE_QUERY_CACHE, "true").applySetting(Environment.DRIVER, "org.h2.Driver").applySetting(Environment.URL, "jdbc:h2:mem:" + getDbName() + ";TRACE_LEVEL_FILE=4").applySetting(Environment.DIALECT, H2Dialect.class.getName()).applySetting(Environment.HBM2DDL_AUTO, "create-drop").applySetting(Environment.CACHE_REGION_FACTORY, FailingInfinispanRegionFactory.class.getName()).applySetting(TestInfinispanRegionFactory.CACHE_MODE, cacheMode).applySetting(Environment.USE_MINIMAL_PUTS, "false").applySetting(Environment.GENERATE_STATISTICS, "false");
    applySettings(ssrb);
    sessionFactories = new SessionFactory[NUM_NODES];
    for (int i = 0; i < NUM_NODES; ++i) {
        StandardServiceRegistry registry = ssrb.build();
        Metadata metadata = buildMetadata(registry);
        sessionFactories[i] = metadata.buildSessionFactory();
    }
}
Also used : Arrays(java.util.Arrays) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Transaction(org.hibernate.Transaction) Future(java.util.concurrent.Future) PessimisticLockException(org.hibernate.PessimisticLockException) PersistentClass(org.hibernate.mapping.PersistentClass) Map(java.util.Map) StaleStateException(org.hibernate.StaleStateException) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SessionFactory(org.hibernate.SessionFactory) Set(java.util.Set) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) InvocationTargetException(java.lang.reflect.InvocationTargetException) InterceptorConfiguration(org.infinispan.configuration.cache.InterceptorConfiguration) Stream(java.util.stream.Stream) AfterClassOnce(org.hibernate.testing.AfterClassOnce) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) TestingJtaPlatformImpl(org.hibernate.testing.jta.TestingJtaPlatformImpl) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) H2Dialect(org.hibernate.dialect.H2Dialect) LockAcquisitionException(org.hibernate.exception.LockAcquisitionException) TestResourceTracker(org.infinispan.test.fwk.TestResourceTracker) RunWith(org.junit.runner.RunWith) SimpleDateFormat(java.text.SimpleDateFormat) Session(org.hibernate.Session) Metadata(org.hibernate.boot.Metadata) ArrayList(java.util.ArrayList) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BiConsumer(java.util.function.BiConsumer) JtaTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl) Environment(org.hibernate.cfg.Environment) Family(org.hibernate.test.cache.infinispan.stress.entities.Family) Properties(java.util.Properties) Files(java.nio.file.Files) BlockingDeque(java.util.concurrent.BlockingDeque) BufferedWriter(java.io.BufferedWriter) OptimisticLockException(javax.persistence.OptimisticLockException) RollbackCommand(org.infinispan.commands.tx.RollbackCommand) IOException(java.io.IOException) Test(org.junit.Test) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) Field(java.lang.reflect.Field) File(java.io.File) TreeMap(java.util.TreeMap) JdbcResourceLocalTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl) ForkJoinPool(java.util.concurrent.ForkJoinPool) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) InfinispanMessageLogger(org.hibernate.cache.infinispan.util.InfinispanMessageLogger) Date(java.util.Date) TransactionStatus(org.hibernate.resource.transaction.spi.TransactionStatus) Person(org.hibernate.test.cache.infinispan.stress.entities.Person) JtaAwareConnectionProviderImpl(org.hibernate.testing.jta.JtaAwareConnectionProviderImpl) InvocationContext(org.infinispan.context.InvocationContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AccessType(org.hibernate.cache.spi.access.AccessType) Method(java.lang.reflect.Method) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Parameterized(org.junit.runners.Parameterized) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) StaleObjectStateException(org.hibernate.StaleObjectStateException) Collection(org.hibernate.mapping.Collection) NavigableMap(java.util.NavigableMap) Collectors(java.util.stream.Collectors) TransactionException(org.hibernate.TransactionException) MetadataSources(org.hibernate.boot.MetadataSources) List(java.util.List) PersistenceException(javax.persistence.PersistenceException) Address(org.hibernate.test.cache.infinispan.stress.entities.Address) PutFromLoadValidator(org.hibernate.cache.infinispan.access.PutFromLoadValidator) TimeoutException(org.infinispan.util.concurrent.TimeoutException) Restrictions(org.hibernate.criterion.Restrictions) RootClass(org.hibernate.mapping.RootClass) HashMap(java.util.HashMap) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ConcurrentMap(java.util.concurrent.ConcurrentMap) RegionAccessStrategy(org.hibernate.cache.spi.access.RegionAccessStrategy) HashSet(java.util.HashSet) RollbackException(javax.transaction.RollbackException) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) ForkJoinTask(java.util.concurrent.ForkJoinTask) LockMode(org.hibernate.LockMode) Iterator(java.util.Iterator) CustomParameterized(org.hibernate.testing.junit4.CustomParameterized) NoJtaPlatform(org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform) CommitCommand(org.infinispan.commands.tx.CommitCommand) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) CacheMode(org.infinispan.configuration.cache.CacheMode) BaseCustomInterceptor(org.infinispan.interceptors.base.BaseCustomInterceptor) Ignore(org.junit.Ignore) BeforeClassOnce(org.hibernate.testing.BeforeClassOnce) VisitableCommand(org.infinispan.commands.VisitableCommand) Comparator(java.util.Comparator) TransactionManager(javax.transaction.TransactionManager) InvalidationCacheAccessDelegate(org.hibernate.cache.infinispan.access.InvalidationCacheAccessDelegate) RemoteException(org.infinispan.remoting.RemoteException) Collections(java.util.Collections) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) File(java.io.File) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) BeforeClassOnce(org.hibernate.testing.BeforeClassOnce)

Example 2 with CacheMode

use of org.infinispan.configuration.cache.CacheMode in project hibernate-orm by hibernate.

the class BaseTransactionalDataRegion method createAccessDelegate.

protected synchronized AccessDelegate createAccessDelegate(AccessType accessType) {
    if (accessType == null) {
        throw new IllegalArgumentException();
    }
    if (this.accessType != null && !this.accessType.equals(accessType)) {
        throw new IllegalStateException("This region was already set up for " + this.accessType + ", cannot use using " + accessType);
    }
    this.accessType = accessType;
    CacheMode cacheMode = cache.getCacheConfiguration().clustering().cacheMode();
    if (accessType == AccessType.NONSTRICT_READ_WRITE) {
        prepareForVersionedEntries();
        return new NonStrictAccessDelegate(this);
    }
    if (cacheMode.isDistributed() || cacheMode.isReplicated()) {
        prepareForTombstones();
        return new TombstoneAccessDelegate(this);
    } else {
        prepareForValidation();
        if (cache.getCacheConfiguration().transaction().transactionMode().isTransactional()) {
            return new TxInvalidationCacheAccessDelegate(this, validator);
        } else {
            return new NonTxInvalidationCacheAccessDelegate(this, validator);
        }
    }
}
Also used : NonStrictAccessDelegate(org.hibernate.cache.infinispan.access.NonStrictAccessDelegate) NonTxInvalidationCacheAccessDelegate(org.hibernate.cache.infinispan.access.NonTxInvalidationCacheAccessDelegate) CacheMode(org.infinispan.configuration.cache.CacheMode) NonTxInvalidationCacheAccessDelegate(org.hibernate.cache.infinispan.access.NonTxInvalidationCacheAccessDelegate) TxInvalidationCacheAccessDelegate(org.hibernate.cache.infinispan.access.TxInvalidationCacheAccessDelegate) TombstoneAccessDelegate(org.hibernate.cache.infinispan.access.TombstoneAccessDelegate)

Example 3 with CacheMode

use of org.infinispan.configuration.cache.CacheMode in project hibernate-orm by hibernate.

the class BaseTransactionalDataRegion method replaceCommonInterceptors.

private void replaceCommonInterceptors() {
    CacheMode cacheMode = cache.getCacheConfiguration().clustering().cacheMode();
    if (!cacheMode.isReplicated() && !cacheMode.isDistributed()) {
        return;
    }
    LockingInterceptor lockingInterceptor = new LockingInterceptor();
    cache.getComponentRegistry().registerComponent(lockingInterceptor, LockingInterceptor.class);
    if (!cache.addInterceptorBefore(lockingInterceptor, NonTransactionalLockingInterceptor.class)) {
        throw new IllegalStateException("Misconfigured cache, interceptor chain is " + cache.getInterceptorChain());
    }
    cache.removeInterceptor(NonTransactionalLockingInterceptor.class);
    UnorderedDistributionInterceptor distributionInterceptor = new UnorderedDistributionInterceptor();
    cache.getComponentRegistry().registerComponent(distributionInterceptor, UnorderedDistributionInterceptor.class);
    if (!cache.addInterceptorBefore(distributionInterceptor, NonTxDistributionInterceptor.class)) {
        throw new IllegalStateException("Misconfigured cache, interceptor chain is " + cache.getInterceptorChain());
    }
    cache.removeInterceptor(NonTxDistributionInterceptor.class);
    EntryWrappingInterceptor ewi = cache.getComponentRegistry().getComponent(EntryWrappingInterceptor.class);
    try {
        Field isUsingLockDelegation = EntryWrappingInterceptor.class.getDeclaredField("isUsingLockDelegation");
        isUsingLockDelegation.setAccessible(true);
        isUsingLockDelegation.set(ewi, false);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw new IllegalStateException(e);
    }
}
Also used : Field(java.lang.reflect.Field) NonTransactionalLockingInterceptor(org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor) LockingInterceptor(org.hibernate.cache.infinispan.access.LockingInterceptor) NonTxDistributionInterceptor(org.infinispan.interceptors.distribution.NonTxDistributionInterceptor) UnorderedDistributionInterceptor(org.hibernate.cache.infinispan.access.UnorderedDistributionInterceptor) EntryWrappingInterceptor(org.infinispan.interceptors.EntryWrappingInterceptor) NonTransactionalLockingInterceptor(org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor) CacheMode(org.infinispan.configuration.cache.CacheMode)

Example 4 with CacheMode

use of org.infinispan.configuration.cache.CacheMode in project wildfly by wildfly.

the class ClientMappingsCacheBuilderProvider method getBuilders.

@Override
public Collection<CapabilityServiceBuilder<?>> getBuilders(ServiceNameRegistry<ClusteringCacheRequirement> registry, String containerName, String aliasCacheName) {
    List<CapabilityServiceBuilder<?>> builders = new LinkedList<>();
    if (aliasCacheName == null) {
        String cacheName = BeanManagerFactoryBuilderConfiguration.CLIENT_MAPPINGS_CACHE_NAME;
        builders.add(new TemplateConfigurationBuilder(ServiceName.parse(InfinispanCacheRequirement.CONFIGURATION.resolve(containerName, cacheName)), containerName, cacheName, aliasCacheName, builder -> {
            CacheMode mode = builder.clustering().cacheMode();
            builder.clustering().cacheMode(mode.isClustered() ? CacheMode.REPL_SYNC : CacheMode.LOCAL);
            builder.clustering().l1().disable();
            builder.persistence().clearStores();
        }));
        builders.add(new CacheBuilder<>(ServiceName.parse(InfinispanCacheRequirement.CACHE.resolve(containerName, cacheName)), containerName, cacheName));
        ServiceNameRegistry<ClusteringCacheRequirement> routingRegistry = requirement -> ServiceName.parse(requirement.resolve(containerName, cacheName));
        for (CacheBuilderProvider provider : ServiceLoader.load(this.providerClass, this.providerClass.getClassLoader())) {
            builders.addAll(provider.getBuilders(routingRegistry, containerName, cacheName));
        }
    }
    return builders;
}
Also used : TemplateConfigurationBuilder(org.wildfly.clustering.infinispan.spi.service.TemplateConfigurationBuilder) ClusteringCacheRequirement(org.wildfly.clustering.spi.ClusteringCacheRequirement) Collection(java.util.Collection) ServiceLoader(java.util.ServiceLoader) BeanManagerFactoryBuilderConfiguration(org.wildfly.clustering.ejb.BeanManagerFactoryBuilderConfiguration) ServiceNameRegistry(org.wildfly.clustering.spi.ServiceNameRegistry) List(java.util.List) CacheMode(org.infinispan.configuration.cache.CacheMode) CacheAliasBuilderProvider(org.wildfly.clustering.spi.CacheAliasBuilderProvider) CacheBuilder(org.wildfly.clustering.infinispan.spi.service.CacheBuilder) ServiceName(org.jboss.msc.service.ServiceName) InfinispanCacheRequirement(org.wildfly.clustering.infinispan.spi.InfinispanCacheRequirement) CacheBuilderProvider(org.wildfly.clustering.spi.CacheBuilderProvider) CapabilityServiceBuilder(org.jboss.as.clustering.controller.CapabilityServiceBuilder) LinkedList(java.util.LinkedList) CapabilityServiceBuilder(org.jboss.as.clustering.controller.CapabilityServiceBuilder) CacheBuilderProvider(org.wildfly.clustering.spi.CacheBuilderProvider) TemplateConfigurationBuilder(org.wildfly.clustering.infinispan.spi.service.TemplateConfigurationBuilder) CacheMode(org.infinispan.configuration.cache.CacheMode) ClusteringCacheRequirement(org.wildfly.clustering.spi.ClusteringCacheRequirement) LinkedList(java.util.LinkedList)

Example 5 with CacheMode

use of org.infinispan.configuration.cache.CacheMode in project wildfly by wildfly.

the class RouteCacheGroupBuilderProvider method getBuilders.

@Override
public Collection<CapabilityServiceBuilder<?>> getBuilders(ServiceNameRegistry<ClusteringCacheRequirement> registry, String containerName, String aliasCacheName) {
    List<CapabilityServiceBuilder<?>> builders = new LinkedList<>();
    if (aliasCacheName == null) {
        builders.add(new TemplateConfigurationBuilder(ServiceName.parse(InfinispanCacheRequirement.CONFIGURATION.resolve(containerName, CACHE_NAME)), containerName, CACHE_NAME, aliasCacheName, builder -> {
            CacheMode mode = builder.clustering().cacheMode();
            builder.clustering().cacheMode(mode.isClustered() ? CacheMode.REPL_SYNC : CacheMode.LOCAL);
            builder.clustering().l1().disable();
            builder.persistence().clearStores();
        }));
        builders.add(new CacheBuilder<>(ServiceName.parse(InfinispanCacheRequirement.CACHE.resolve(containerName, CACHE_NAME)), containerName, CACHE_NAME));
        ServiceNameRegistry<ClusteringCacheRequirement> routingRegistry = requirement -> ServiceName.parse(requirement.resolve(containerName, CACHE_NAME));
        for (CacheBuilderProvider provider : ServiceLoader.load(this.providerClass, this.providerClass.getClassLoader())) {
            builders.addAll(provider.getBuilders(routingRegistry, containerName, CACHE_NAME));
        }
    }
    return builders;
}
Also used : TemplateConfigurationBuilder(org.wildfly.clustering.infinispan.spi.service.TemplateConfigurationBuilder) ClusteringCacheRequirement(org.wildfly.clustering.spi.ClusteringCacheRequirement) Collection(java.util.Collection) ServiceLoader(java.util.ServiceLoader) ServiceNameRegistry(org.wildfly.clustering.spi.ServiceNameRegistry) List(java.util.List) CacheMode(org.infinispan.configuration.cache.CacheMode) CacheAliasBuilderProvider(org.wildfly.clustering.spi.CacheAliasBuilderProvider) CacheBuilder(org.wildfly.clustering.infinispan.spi.service.CacheBuilder) ServiceName(org.jboss.msc.service.ServiceName) InfinispanCacheRequirement(org.wildfly.clustering.infinispan.spi.InfinispanCacheRequirement) CacheBuilderProvider(org.wildfly.clustering.spi.CacheBuilderProvider) CapabilityServiceBuilder(org.jboss.as.clustering.controller.CapabilityServiceBuilder) LinkedList(java.util.LinkedList) CapabilityServiceBuilder(org.jboss.as.clustering.controller.CapabilityServiceBuilder) CacheBuilderProvider(org.wildfly.clustering.spi.CacheBuilderProvider) TemplateConfigurationBuilder(org.wildfly.clustering.infinispan.spi.service.TemplateConfigurationBuilder) CacheMode(org.infinispan.configuration.cache.CacheMode) ClusteringCacheRequirement(org.wildfly.clustering.spi.ClusteringCacheRequirement) LinkedList(java.util.LinkedList)

Aggregations

CacheMode (org.infinispan.configuration.cache.CacheMode)13 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)5 ServiceName (org.jboss.msc.service.ServiceName)4 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Configuration (org.infinispan.configuration.cache.Configuration)3 Test (org.junit.Test)3 Field (java.lang.reflect.Field)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 ServiceLoader (java.util.ServiceLoader)2 ExecutorService (java.util.concurrent.ExecutorService)2 Executors (java.util.concurrent.Executors)2 Consumer (java.util.function.Consumer)2 ClusteringConfigurationBuilder (org.infinispan.configuration.cache.ClusteringConfigurationBuilder)2 CapabilityServiceBuilder (org.jboss.as.clustering.controller.CapabilityServiceBuilder)2 PathAddress (org.jboss.as.controller.PathAddress)2 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)2 ServiceController (org.jboss.msc.service.ServiceController)2 ServiceTarget (org.jboss.msc.service.ServiceTarget)2