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();
}
}
}
}
}
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;
}
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());
}
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);
}
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);
}
}
}
Aggregations