Search in sources :

Example 1 with Cache

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);
                }
            }
        }
    }
}
Also used : CacheWrapper(org.jivesoftware.util.cache.CacheWrapper) MapListener(com.tangosol.util.MapListener) MapEvent(com.tangosol.util.MapEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Cache(org.jivesoftware.util.cache.Cache)

Example 2 with Cache

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);
}
Also used : BackingMapManager(com.tangosol.net.BackingMapManager) ReadWriteBackingMap(com.tangosol.net.cache.ReadWriteBackingMap) DefaultConfigurableCacheFactory(com.tangosol.net.DefaultConfigurableCacheFactory) BackingMapManager(com.tangosol.net.BackingMapManager) ReadWriteBackingMap(com.tangosol.net.cache.ReadWriteBackingMap) Map(java.util.Map) NearCache(com.tangosol.net.cache.NearCache) NamedCache(com.tangosol.net.NamedCache) Cache(org.jivesoftware.util.cache.Cache)

Example 3 with Cache

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);
    }
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Cache(org.jivesoftware.util.cache.Cache)

Example 4 with Cache

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);
                }
            }
        }
    }
}
Also used : CacheWrapper(org.jivesoftware.util.cache.CacheWrapper) HashSet(java.util.HashSet) Set(java.util.Set) EntryEvent(com.hazelcast.core.EntryEvent) EntryListener(com.hazelcast.core.EntryListener) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Cache(org.jivesoftware.util.cache.Cache)

Example 5 with Cache

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);
    }
}
Also used : HashMap(java.util.HashMap) Cache(org.jivesoftware.util.cache.Cache)

Aggregations

Cache (org.jivesoftware.util.cache.Cache)19 CacheFactory (org.jivesoftware.util.cache.CacheFactory)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 JID (org.xmpp.packet.JID)11 java.util (java.util)10 Lock (java.util.concurrent.locks.Lock)10 Collectors (java.util.stream.Collectors)10 Presence (org.xmpp.packet.Presence)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 XMPPServer (org.jivesoftware.openfire.XMPPServer)9 ClusterManager (org.jivesoftware.openfire.cluster.ClusterManager)9 NodeID (org.jivesoftware.openfire.cluster.NodeID)9 Element (org.dom4j.Element)8 RoutingTable (org.jivesoftware.openfire.RoutingTable)8 ClusterEventListener (org.jivesoftware.openfire.cluster.ClusterEventListener)8 Packet (org.xmpp.packet.Packet)8 QName (org.dom4j.QName)7 PacketException (org.jivesoftware.openfire.PacketException)7 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)7