Search in sources :

Example 1 with CacheService

use of com.hazelcast.cache.impl.CacheService in project hazelcast by hazelcast.

the class InvalidationMetadataDistortionTest method distortRandomPartitionSequence.

private void distortRandomPartitionSequence(String mapName, HazelcastInstance member) {
    NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(member);
    CacheService service = nodeEngineImpl.getService(CacheService.SERVICE_NAME);
    CacheEventHandler cacheEventHandler = service.getCacheEventHandler();
    MetaDataGenerator metaDataGenerator = cacheEventHandler.getMetaDataGenerator();
    InternalPartitionService partitionService = nodeEngineImpl.getPartitionService();
    int partitionCount = partitionService.getPartitionCount();
    int randomPartition = getInt(partitionCount);
    int randomSequence = getInt(MAX_VALUE);
    metaDataGenerator.setCurrentSequence(mapName, randomPartition, randomSequence);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) CacheEventHandler(com.hazelcast.cache.impl.CacheEventHandler) MetaDataGenerator(com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator) CacheService(com.hazelcast.cache.impl.CacheService)

Example 2 with CacheService

use of com.hazelcast.cache.impl.CacheService in project hazelcast by hazelcast.

the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_invoked_fromOtherNode.

@Test
public void test_cachePartitionLostListener_invoked_fromOtherNode() {
    final String cacheName = randomName();
    HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    final HazelcastServerCachingProvider cachingProvider = createCachingProvider(instance1);
    final CacheManager cacheManager = cachingProvider.getCacheManager();
    final CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
    config.setBackupCount(0);
    cacheManager.createCache(cacheName, config);
    final CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
    final CacheManager clientCacheManager = clientCachingProvider.getCacheManager();
    final Cache<Integer, String> cache = clientCacheManager.getCache(cacheName);
    final ICache iCache = cache.unwrap(ICache.class);
    final EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener();
    iCache.addPartitionLostListener(listener);
    assertRegistrationsSizeEventually(instance1, cacheName, 1);
    assertRegistrationsSizeEventually(instance2, cacheName, 1);
    final CacheService cacheService1 = getNode(instance1).getNodeEngine().getService(CacheService.SERVICE_NAME);
    final CacheService cacheService2 = getNode(instance2).getNodeEngine().getService(CacheService.SERVICE_NAME);
    final int partitionId = 5;
    cacheService1.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
    cacheService2.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
    assertCachePartitionLostEventEventually(listener, partitionId);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICache(com.hazelcast.cache.ICache) CacheManager(javax.cache.CacheManager) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheConfig(com.hazelcast.config.CacheConfig) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastServerCachingProvider.createCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider.createCachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) CacheService(com.hazelcast.cache.impl.CacheService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with CacheService

use of com.hazelcast.cache.impl.CacheService in project hazelcast by hazelcast.

the class ClientCacheMetaDataFetcherTest method distortRandomPartitionSequence.

private void distortRandomPartitionSequence(String cacheName, int partition, long sequence, HazelcastInstance member) {
    NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(member);
    CacheService service = nodeEngineImpl.getService(SERVICE_NAME);
    CacheEventHandler cacheEventHandler = service.getCacheEventHandler();
    MetaDataGenerator metaDataGenerator = cacheEventHandler.getMetaDataGenerator();
    metaDataGenerator.setCurrentSequence(cacheName, partition, sequence);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CacheEventHandler(com.hazelcast.cache.impl.CacheEventHandler) MetaDataGenerator(com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator) CacheService(com.hazelcast.cache.impl.CacheService)

Example 4 with CacheService

use of com.hazelcast.cache.impl.CacheService in project hazelcast by hazelcast.

the class CacheNearCacheStateHolder method applyState.

void applyState() {
    CacheService cacheService = cacheReplicationOperation.getService();
    MetaDataGenerator metaDataGenerator = getPartitionMetaDataGenerator(cacheService);
    int partitionId = cacheReplicationOperation.getPartitionId();
    if (partitionUuid != null) {
        metaDataGenerator.setUuid(partitionId, partitionUuid);
    }
    for (int i = 0; i < cacheNameSequencePairs.size(); ) {
        String cacheName = (String) cacheNameSequencePairs.get(i++);
        long sequence = (Long) cacheNameSequencePairs.get(i++);
        metaDataGenerator.setCurrentSequence(cacheName, partitionId, sequence);
    }
}
Also used : MetaDataGenerator(com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator) CacheService(com.hazelcast.cache.impl.CacheService) ICacheService(com.hazelcast.cache.impl.ICacheService) AbstractCacheService(com.hazelcast.cache.impl.AbstractCacheService)

Example 5 with CacheService

use of com.hazelcast.cache.impl.CacheService in project hazelcast by hazelcast.

the class CacheClearOperation method afterRun.

@Override
public void afterRun() throws Exception {
    super.afterRun();
    IPartitionService partitionService = getNodeEngine().getPartitionService();
    if (partitionService.getPartitionId(name) == getPartitionId()) {
        CacheService cacheService = getService();
        cacheService.sendInvalidationEvent(name, null, SOURCE_NOT_AVAILABLE);
    }
}
Also used : IPartitionService(com.hazelcast.spi.partition.IPartitionService) CacheService(com.hazelcast.cache.impl.CacheService) ICacheService(com.hazelcast.cache.impl.ICacheService)

Aggregations

CacheService (com.hazelcast.cache.impl.CacheService)21 CacheEventHandler (com.hazelcast.cache.impl.CacheEventHandler)6 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)6 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)5 MetaDataGenerator (com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator)5 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 CacheManager (javax.cache.CacheManager)5 Test (org.junit.Test)5 ClientEndpoint (com.hazelcast.client.ClientEndpoint)4 CacheConfig (com.hazelcast.config.CacheConfig)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 Data (com.hazelcast.nio.serialization.Data)4 CachingProvider (javax.cache.spi.CachingProvider)4 CacheContext (com.hazelcast.cache.impl.CacheContext)3 ICacheService (com.hazelcast.cache.impl.ICacheService)3 IPartitionLostEvent (com.hazelcast.spi.partition.IPartitionLostEvent)3 ICache (com.hazelcast.cache.ICache)2 CacheOperationProvider (com.hazelcast.cache.impl.CacheOperationProvider)2 CachePartitionSegment (com.hazelcast.cache.impl.CachePartitionSegment)2