use of com.hazelcast.cache.impl.ICacheService in project hazelcast by hazelcast.
the class ClientCacheConfigTest method createCacheConfigOnAllNodes.
@Test
public void createCacheConfigOnAllNodes() {
final String CACHE_NAME = "myCache";
HazelcastInstance client = null;
HazelcastInstance server1 = null;
HazelcastInstance server2 = null;
try {
Config config = new Config();
CacheSimpleConfig cacheSimpleConfig = new CacheSimpleConfig().setName(CACHE_NAME).setBackupCount(// Be sure that cache put operation is mirrored to backup node
1);
config.addCacheConfig(cacheSimpleConfig);
// Create servers with configured caches
server1 = Hazelcast.newHazelcastInstance(config);
server2 = Hazelcast.newHazelcastInstance(config);
ICacheService cacheService1 = getCacheService(server1);
ICacheService cacheService2 = getCacheService(server2);
// Create the hazelcast client instance
client = HazelcastClient.newHazelcastClient();
// Create the client cache manager
CachingProvider cachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
CacheManager cacheManager = cachingProvider.getCacheManager();
Cache<String, String> cache = cacheManager.getCache(CACHE_NAME);
assertNotNull(cache);
CacheConfig cacheConfig = cache.getConfiguration(CacheConfig.class);
assertNotNull(cacheService1.getCacheConfig(cacheConfig.getNameWithPrefix()));
assertNotNull(cacheService2.getCacheConfig(cacheConfig.getNameWithPrefix()));
// First attempt to use the cache will trigger to create its record store.
// So, we are testing also this case. There should not be any exception.
// In here, we are testing both of nodes since there is a backup,
// put is also applied to other (backup node).
cache.put("key", "value");
} finally {
if (client != null) {
client.shutdown();
}
if (server1 != null) {
server1.shutdown();
}
if (server2 != null) {
server2.shutdown();
}
}
}
use of com.hazelcast.cache.impl.ICacheService in project hazelcast by hazelcast.
the class CacheSizeOperation method run.
@Override
public void run() throws Exception {
ICacheService service = getService();
ICacheRecordStore cache = service.getRecordStore(name, getPartitionId());
response = cache != null ? cache.size() : 0;
}
use of com.hazelcast.cache.impl.ICacheService in project hazelcast by hazelcast.
the class CacheNearCacheStateHolder method prepare.
void prepare(CachePartitionSegment segment) {
ICacheService cacheService = segment.getCacheService();
MetaDataGenerator metaData = getPartitionMetaDataGenerator(cacheService);
int partitionId = segment.getPartitionId();
partitionUuid = metaData.getUuidOrNull(partitionId);
cacheNameSequencePairs = new ArrayList(segment.getCacheConfigs().size());
Iterator<ICacheRecordStore> iter = segment.recordStoreIterator();
while (iter.hasNext()) {
ICacheRecordStore cacheRecordStore = iter.next();
String cacheName = cacheRecordStore.getName();
cacheNameSequencePairs.add(cacheName);
cacheNameSequencePairs.add(metaData.currentSequence(cacheName, partitionId));
}
}
use of com.hazelcast.cache.impl.ICacheService in project hazelcast by hazelcast.
the class CachePutAllOperation method run.
@Override
public void run() throws Exception {
int partitionId = getPartitionId();
String callerUuid = getCallerUuid();
ICacheService service = getService();
cache = service.getOrCreateRecordStore(name, partitionId);
backupRecords = new HashMap<Data, CacheRecord>(entries.size());
for (Map.Entry<Data, Data> entry : entries) {
Data key = entry.getKey();
Data value = entry.getValue();
CacheRecord backupRecord = cache.put(key, value, expiryPolicy, callerUuid, completionId);
backupRecords.put(key, backupRecord);
}
}
use of com.hazelcast.cache.impl.ICacheService in project hazelcast by hazelcast.
the class CachePutBackupOperation method runInternal.
@Override
public void runInternal() throws Exception {
ICacheService service = getService();
ICacheRecordStore cache = service.getOrCreateRecordStore(name, getPartitionId());
cache.putRecord(key, cacheRecord);
response = Boolean.TRUE;
}
Aggregations