Search in sources :

Example 6 with ICacheService

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

the class CacheCreateConfigOperation method run.

@Override
public void run() throws Exception {
    ICacheService service = getService();
    if (!ignoreLocal) {
        response = service.putCacheConfigIfAbsent(config);
    }
    if (createAlsoOnOthers) {
        NodeEngine nodeEngine = getNodeEngine();
        Collection<Member> members = nodeEngine.getClusterService().getMembers();
        int remoteNodeCount = members.size() - 1;
        if (remoteNodeCount > 0) {
            postponeReturnResponse();
            ExecutionCallback<Object> callback = new CacheConfigCreateCallback(this, remoteNodeCount);
            OperationService operationService = nodeEngine.getOperationService();
            for (Member member : members) {
                if (!member.localMember()) {
                    CacheCreateConfigOperation op = new CacheCreateConfigOperation(config, false);
                    operationService.createInvocationBuilder(ICacheService.SERVICE_NAME, op, member.getAddress()).setExecutionCallback(callback).invoke();
                }
            }
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) ICacheService(com.hazelcast.cache.impl.ICacheService) OperationService(com.hazelcast.spi.OperationService) Member(com.hazelcast.core.Member)

Example 7 with ICacheService

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

the class CacheGetConfigOperation method run.

@Override
public void run() throws Exception {
    final ICacheService service = getService();
    CacheConfig cacheConfig = service.getCacheConfig(name);
    if (cacheConfig == null) {
        cacheConfig = service.findCacheConfig(simpleName);
        if (cacheConfig != null) {
            cacheConfig.setManagerPrefix(name.substring(0, name.lastIndexOf(simpleName)));
            CacheConfig existingCacheConfig = service.putCacheConfigIfAbsent(cacheConfig);
            if (existingCacheConfig != null) {
                cacheConfig = existingCacheConfig;
            }
        }
    }
    response = cacheConfig;
}
Also used : ICacheService(com.hazelcast.cache.impl.ICacheService) CacheConfig(com.hazelcast.config.CacheConfig)

Example 8 with ICacheService

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

the class AbstractCacheAllPartitionsTask method getOperationProvider.

protected CacheOperationProvider getOperationProvider(String name) {
    ICacheService service = getService(CacheService.SERVICE_NAME);
    CacheConfig cacheConfig = service.getCacheConfig(name);
    if (cacheConfig == null) {
        throw new CacheNotExistsException("Cache config for cache " + name + " has not been created yet!");
    }
    return service.getCacheOperationProvider(name, cacheConfig.getInMemoryFormat());
}
Also used : ICacheService(com.hazelcast.cache.impl.ICacheService) CacheConfig(com.hazelcast.config.CacheConfig) CacheNotExistsException(com.hazelcast.cache.CacheNotExistsException)

Example 9 with ICacheService

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

the class AbstractCacheMessageTask method getOperationProvider.

protected CacheOperationProvider getOperationProvider(String name) {
    ICacheService service = getService(CacheService.SERVICE_NAME);
    final CacheConfig cacheConfig = service.getCacheConfig(name);
    if (cacheConfig == null) {
        throw new CacheNotExistsException("Cache " + name + " is already destroyed or not created yet, on " + nodeEngine.getLocalMember());
    }
    final InMemoryFormat inMemoryFormat = cacheConfig.getInMemoryFormat();
    return service.getCacheOperationProvider(name, inMemoryFormat);
}
Also used : ICacheService(com.hazelcast.cache.impl.ICacheService) LegacyCacheConfig(com.hazelcast.config.LegacyCacheConfig) CacheConfig(com.hazelcast.config.CacheConfig) CacheNotExistsException(com.hazelcast.cache.CacheNotExistsException) InMemoryFormat(com.hazelcast.config.InMemoryFormat)

Example 10 with ICacheService

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

the class CacheLoadAllTest method testLoadAll.

@Test
public void testLoadAll() throws InterruptedException {
    ICache<String, String> cache = createCache();
    String cacheName = cache.getName();
    Map<String, String> entries = createAndFillEntries();
    final CountDownLatch latch = new CountDownLatch(1);
    cache.loadAll(entries.keySet(), true, new CompletionListener() {

        @Override
        public void onCompletion() {
            latch.countDown();
        }

        @Override
        public void onException(Exception e) {
            latch.countDown();
        }
    });
    latch.await(60, TimeUnit.SECONDS);
    // Verify that load-all works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String expectedValue = entries.get(key);
        String actualValue = cache.get(key);
        assertEquals(expectedValue, actualValue);
    }
    Node node = getNode(hazelcastInstance);
    InternalPartitionService partitionService = node.getPartitionService();
    SerializationService serializationService = node.getSerializationService();
    // Verify that backup of load-all works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String expectedValue = entries.get(key);
        Data keyData = serializationService.toData(key);
        int keyPartitionId = partitionService.getPartitionId(keyData);
        for (int i = 0; i < INSTANCE_COUNT; i++) {
            Node n = getNode(hazelcastInstances[i]);
            ICacheService cacheService = n.getNodeEngine().getService(ICacheService.SERVICE_NAME);
            ICacheRecordStore recordStore = cacheService.getRecordStore("/hz/" + cacheName, keyPartitionId);
            assertNotNull(recordStore);
            String actualValue = serializationService.toObject(recordStore.get(keyData, null));
            assertEquals(expectedValue, actualValue);
        }
    }
}
Also used : CompletionListener(javax.cache.integration.CompletionListener) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.Node) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) ICacheRecordStore(com.hazelcast.cache.impl.ICacheRecordStore) CountDownLatch(java.util.concurrent.CountDownLatch) CacheLoaderException(javax.cache.integration.CacheLoaderException) ICacheService(com.hazelcast.cache.impl.ICacheService) HashMap(java.util.HashMap) Map(java.util.Map) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ICacheService (com.hazelcast.cache.impl.ICacheService)24 ICacheRecordStore (com.hazelcast.cache.impl.ICacheRecordStore)9 CacheConfig (com.hazelcast.config.CacheConfig)8 Data (com.hazelcast.nio.serialization.Data)8 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 Node (com.hazelcast.instance.Node)5 SerializationService (com.hazelcast.spi.serialization.SerializationService)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 CacheRecord (com.hazelcast.cache.impl.record.CacheRecord)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 AssertTask (com.hazelcast.test.AssertTask)3 CacheNotExistsException (com.hazelcast.cache.CacheNotExistsException)2 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)2 Config (com.hazelcast.config.Config)2 NodeEngine (com.hazelcast.spi.NodeEngine)2 HashSet (java.util.HashSet)2