Search in sources :

Example 1 with ExpirationManager

use of org.infinispan.expiration.ExpirationManager in project hibernate-orm by hibernate.

the class BaseTransactionalDataRegion method replaceExpirationManager.

private void replaceExpirationManager() {
    // ClusteredExpirationManager sends RemoteExpirationCommands to remote nodes which causes
    // undesired overhead. When get() triggers a RemoteExpirationCommand executed in async executor
    // this locks the entry for the duration of RPC, and putFromLoad with ZERO_LOCK_ACQUISITION_TIMEOUT
    // fails as it finds the entry being blocked.
    ExpirationManager expirationManager = cache.getComponentRegistry().getComponent(ExpirationManager.class);
    if ((expirationManager instanceof ClusterExpirationManager)) {
        // re-registering component does not stop the old one
        ((ClusterExpirationManager) expirationManager).stop();
        cache.getComponentRegistry().registerComponent(new ExpirationManagerImpl<>(), ExpirationManager.class);
        cache.getComponentRegistry().rewire();
    } else if (expirationManager instanceof ExpirationManagerImpl) {
    // do nothing
    } else {
        throw new IllegalStateException("Expected clustered expiration manager, found " + expirationManager);
    }
}
Also used : ClusterExpirationManager(org.infinispan.expiration.impl.ClusterExpirationManager) ExpirationManager(org.infinispan.expiration.ExpirationManager) ClusterExpirationManager(org.infinispan.expiration.impl.ClusterExpirationManager) ExpirationManagerImpl(org.infinispan.expiration.impl.ExpirationManagerImpl)

Example 2 with ExpirationManager

use of org.infinispan.expiration.ExpirationManager in project infinispan by infinispan.

the class AutoCommitExpiryTest method testNoAutCommitAndExpiryListener.

@Test
public void testNoAutCommitAndExpiryListener() throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException {
    ExpiryListener expiryListener = new ExpiryListener();
    Cache<String, String> applicationCache = cacheManager.getCache();
    applicationCache.addListener(expiryListener);
    TransactionManager tm = applicationCache.getAdvancedCache().getTransactionManager();
    tm.begin();
    applicationCache.put("test1", "value1", 1, TimeUnit.SECONDS);
    tm.commit();
    tm.begin();
    applicationCache.put("test2", "value2", 1, TimeUnit.SECONDS);
    tm.commit();
    timeService.advance(TimeUnit.SECONDS.toMillis(10));
    ExpirationManager manager = applicationCache.getAdvancedCache().getExpirationManager();
    manager.processExpiration();
    assertEquals(2, expiryListener.getCount());
}
Also used : TransactionManager(javax.transaction.TransactionManager) ExpirationManager(org.infinispan.expiration.ExpirationManager) SingleCacheManagerTest(org.infinispan.test.SingleCacheManagerTest) Test(org.testng.annotations.Test)

Aggregations

ExpirationManager (org.infinispan.expiration.ExpirationManager)2 TransactionManager (javax.transaction.TransactionManager)1 ClusterExpirationManager (org.infinispan.expiration.impl.ClusterExpirationManager)1 ExpirationManagerImpl (org.infinispan.expiration.impl.ExpirationManagerImpl)1 SingleCacheManagerTest (org.infinispan.test.SingleCacheManagerTest)1 Test (org.testng.annotations.Test)1