Search in sources :

Example 1 with HazelcastInstanceCacheManager

use of com.hazelcast.instance.HazelcastInstanceCacheManager in project hazelcast by hazelcast.

the class GetCacheEntryRequest method writeResponse.

@Override
public void writeResponse(ManagementCenterService mcs, JsonObject root) throws Exception {
    InternalSerializationService serializationService = mcs.getHazelcastInstance().getSerializationService();
    HazelcastInstanceCacheManager cacheManager = mcs.getHazelcastInstance().getCacheManager();
    ICache<Object, Object> cache = cacheManager.getCache(cacheName);
    CacheEntryView cacheEntry = null;
    if ("string".equals(type)) {
        cacheEntry = cache.invoke(key, ENTRY_PROCESSOR, cacheEntry);
    } else if ("long".equals(type)) {
        cacheEntry = cache.invoke(Long.valueOf(key), ENTRY_PROCESSOR, cacheEntry);
    } else if ("integer".equals(type)) {
        cacheEntry = cache.invoke(Integer.valueOf(key), ENTRY_PROCESSOR, cacheEntry);
    }
    JsonObject result = new JsonObject();
    if (cacheEntry != null) {
        Object value = serializationService.toObject(cacheEntry.getValue());
        result.add("cacheBrowse_value", value != null ? value.toString() : "null");
        result.add("cacheBrowse_class", value != null ? value.getClass().getName() : "null");
        result.add("date_cache_creation_time", Long.toString(cacheEntry.getCreationTime()));
        result.add("date_cache_expiration_time", Long.toString(cacheEntry.getExpirationTime()));
        result.add("cacheBrowse_hits", Long.toString(cacheEntry.getAccessHit()));
        result.add("date_cache_access_time", Long.toString(cacheEntry.getLastAccessTime()));
    }
    root.add("result", result);
}
Also used : HazelcastInstanceCacheManager(com.hazelcast.instance.HazelcastInstanceCacheManager) CacheEntryView(com.hazelcast.cache.CacheEntryView) JsonObject(com.eclipsesource.json.JsonObject) JsonObject(com.eclipsesource.json.JsonObject) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService)

Example 2 with HazelcastInstanceCacheManager

use of com.hazelcast.instance.HazelcastInstanceCacheManager in project hazelcast by hazelcast.

the class CacheThroughHazelcastInstanceTest method getCache_whenOtherHazelcastExceptionIsThrown_thenFail.

@Test
public void getCache_whenOtherHazelcastExceptionIsThrown_thenFail() {
    // when one attempts to getCache but a HazelcastException other than ServiceNotFoundException is thrown
    HazelcastInstanceImpl hzInstanceImpl = mock(HazelcastInstanceImpl.class);
    when(hzInstanceImpl.getDistributedObject(anyString(), anyString())).thenThrow(new HazelcastException("mock hz exception"));
    // then the thrown HazelcastException is rethrown by getCache
    ICacheManager hzCacheManager = new HazelcastInstanceCacheManager(hzInstanceImpl);
    thrown.expect(HazelcastException.class);
    hzCacheManager.getCache("any-cache");
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) HazelcastInstanceCacheManager(com.hazelcast.instance.HazelcastInstanceCacheManager) HazelcastException(com.hazelcast.core.HazelcastException) ICacheManager(com.hazelcast.core.ICacheManager) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastInstanceCacheManager (com.hazelcast.instance.HazelcastInstanceCacheManager)2 JsonObject (com.eclipsesource.json.JsonObject)1 CacheEntryView (com.hazelcast.cache.CacheEntryView)1 HazelcastException (com.hazelcast.core.HazelcastException)1 ICacheManager (com.hazelcast.core.ICacheManager)1 HazelcastInstanceImpl (com.hazelcast.instance.HazelcastInstanceImpl)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1