use of org.jivesoftware.util.cache.Cache in project Openfire by igniterealtime.
the class ClusterListener method simuateCacheInserts.
private void simuateCacheInserts(Cache<Object, Object> cache) {
MapListener mapListener = mapListeners.get(cache);
if (mapListener != null) {
if (cache instanceof CacheWrapper) {
Cache wrapped = ((CacheWrapper) cache).getWrappedCache();
if (wrapped instanceof ClusteredCache) {
ClusteredCache clusteredCache = (ClusteredCache) wrapped;
for (Map.Entry entry : cache.entrySet()) {
MapEvent event = new MapEvent(clusteredCache.map, MapEvent.ENTRY_INSERTED, entry.getKey(), null, entry.getValue());
mapListener.entryInserted(event);
}
}
}
}
}
use of org.jivesoftware.util.cache.Cache in project Openfire by igniterealtime.
the class ClusteredCache method init.
private void init(String name, NamedCache cache) {
map = cache;
BackingMapManager backingManager = cache.getCacheService().getBackingMapManager();
Map mapBacking = null;
if (backingManager instanceof DefaultConfigurableCacheFactory.Manager) {
DefaultConfigurableCacheFactory.Manager actualManager = (DefaultConfigurableCacheFactory.Manager) backingManager;
int count = 0;
mapBacking = actualManager.getBackingMap(name);
//by the coherence api
while (mapBacking == null && count < 5) {
// Wait a full second
try {
Thread.sleep(1000);
} catch (Exception e) {
/*ignore*/
}
count++;
mapBacking = actualManager.getBackingMap(name);
}
if (mapBacking instanceof ReadWriteBackingMap) {
ReadWriteBackingMap readWriteMap = (ReadWriteBackingMap) mapBacking;
Map realBackingMap = readWriteMap.getInternalCache();
if (realBackingMap instanceof Cache) {
backingCache = (Cache) realBackingMap;
}
} else if (mapBacking instanceof Cache) {
backingCache = (Cache) mapBacking;
}
}
if (backingCache == null) {
throw new IllegalStateException("Unable to access backing cache for " + name + ". BackingMapManager is a " + backingManager.getClass().getName() + " and backing map is " + ((mapBacking != null) ? mapBacking.getClass().getName() : "null"));
}
backingCache.setName(name);
}
use of org.jivesoftware.util.cache.Cache in project Openfire by igniterealtime.
the class ClusteredCacheFactory method updateCacheStats.
public void updateCacheStats(Map<String, Cache> caches) {
if (caches.size() > 0 && cluster != null) {
// Create the cacheStats map if necessary.
if (cacheStats == null) {
cacheStats = (Map<String, Map<String, long[]>>) com.tangosol.net.CacheFactory.getCache("opt-$cacheStats");
}
String uid = cluster.getLocalMember().getUid().toString();
Map<String, long[]> stats = new HashMap<String, long[]>();
for (String cacheName : caches.keySet()) {
Cache cache = caches.get(cacheName);
// The following information is published:
// current size, max size, num elements, cache
// hits, cache misses.
long[] info = new long[5];
info[0] = cache.getCacheSize();
info[1] = cache.getMaxCacheSize();
info[2] = cache.size();
info[3] = cache.getCacheHits();
info[4] = cache.getCacheMisses();
stats.put(cacheName, info);
}
// Publish message
cacheStats.put(uid, stats);
}
}
use of org.jivesoftware.util.cache.Cache in project Openfire by igniterealtime.
the class ClusterListener method simulateCacheInserts.
private void simulateCacheInserts(Cache cache) {
EntryListener EntryListener = EntryListeners.get(cache);
if (EntryListener != null) {
if (cache instanceof CacheWrapper) {
Cache wrapped = ((CacheWrapper) cache).getWrappedCache();
if (wrapped instanceof ClusteredCache) {
ClusteredCache clusteredCache = (ClusteredCache) wrapped;
for (Map.Entry entry : (Set<Map.Entry>) cache.entrySet()) {
EntryEvent event = new EntryEvent(clusteredCache.map.getName(), cluster.getLocalMember(), EntryEventType.ADDED.getType(), entry.getKey(), null, entry.getValue());
EntryListener.entryAdded(event);
}
}
}
}
}
use of org.jivesoftware.util.cache.Cache in project Openfire by igniterealtime.
the class ClusteredCacheFactory method updateCacheStats.
public void updateCacheStats(Map<String, Cache> caches) {
if (caches.size() > 0 && cluster != null) {
// Create the cacheStats map if necessary.
if (cacheStats == null) {
cacheStats = hazelcast.getMap("opt-$cacheStats");
}
String uid = cluster.getLocalMember().getUuid();
Map<String, long[]> stats = new HashMap<String, long[]>();
for (String cacheName : caches.keySet()) {
Cache cache = caches.get(cacheName);
// The following information is published:
// current size, max size, num elements, cache
// hits, cache misses.
long[] info = new long[5];
info[0] = cache.getCacheSize();
info[1] = cache.getMaxCacheSize();
info[2] = cache.size();
info[3] = cache.getCacheHits();
info[4] = cache.getCacheMisses();
stats.put(cacheName, info);
}
// Publish message
cacheStats.put(uid, stats);
}
}
Aggregations