Search in sources :

Example 1 with NamedCache

use of com.tangosol.net.NamedCache 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 2 with NamedCache

use of com.tangosol.net.NamedCache in project teiid by teiid.

the class CoherenceConnectionImpl method update.

public void update(Object key, Object object) throws ResourceException {
    NamedCache sourceCache = getCache();
    if (!sourceCache.containsKey(key)) {
        throw new ResourceException("Unable to update object for key: " + key + " to cache " + this.cacheName + ", because it already exist");
    }
    TransactionMap tmap = CacheFactory.getLocalTransaction(sourceCache);
    tmap.setTransactionIsolation(TransactionMap.TRANSACTION_REPEATABLE_GET);
    tmap.setConcurrency(TransactionMap.CONCUR_PESSIMISTIC);
    tmap.begin();
    try {
        tmap.put(key, object);
        tmap.prepare();
        tmap.commit();
    } catch (Exception e) {
        throw new ResourceException(e);
    }
    sourceCache = getCache();
    if (!sourceCache.containsKey(key)) {
        throw new ResourceException("Problem updating object for key: " + key + " to the cache " + this.cacheName + ", object not found after add");
    }
}
Also used : ResourceException(javax.resource.ResourceException) TransactionMap(com.tangosol.util.TransactionMap) ResourceException(javax.resource.ResourceException) NamedCache(com.tangosol.net.NamedCache)

Example 3 with NamedCache

use of com.tangosol.net.NamedCache in project teiid by teiid.

the class TestCoherenceConnection method loadCoherence.

/**
 * Load the cache with 3 trades and 10 legs for each trade.
 *
 * @throws Exception
 */
private static void loadCoherence() throws Exception {
    NamedCache tradesCache = CacheFactory.getCache(CACHE_NAME);
    // populate the cache
    Map legsMap = new HashMap();
    Trade trade = new Trade();
    for (int i = 1; i <= NUMTRADES; i++) {
        for (int j = 1; j <= NUMLEGS; j++) {
            Leg leg = new Leg();
            leg.setId(j);
            leg.setNotional(i + j);
            legsMap.put(j, leg);
        }
        trade.setId(i);
        trade.setName("NameIs " + i);
        trade.setLegs(legsMap);
        tradesCache.put(i, trade);
    }
    System.out.println("Loaded Coherence");
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) NamedCache(com.tangosol.net.NamedCache)

Example 4 with NamedCache

use of com.tangosol.net.NamedCache in project teiid by teiid.

the class TradesCacheSource method loadCoherence.

/**
 * Load the cache with 3 trades and 10 legs for each trade.
 *
 * @throws Exception
 */
private static void loadCoherence() throws Exception {
    NamedCache tradesCache = CacheFactory.getCache(CACHE_NAME);
    TradesCacheSource translator = new TradesCacheSource();
    for (int i = 1; i <= NUMTRADES; i++) {
        Trade trade = (Trade) translator.createObjectFromMetadata("org.teiid.translator.coherence.Trade");
        // execFactory.getCacheTranslator().createObject("org.teiid.translator.coherence.Trade");
        Map legsMap = new HashMap();
        for (int j = 1; j <= NUMLEGS; j++) {
            Object leg = translator.createObjectFromMetadata("org.teiid.translator.coherence.Leg");
            // new Leg();
            if (leg == null) {
                throw new Exception("Unable to create leg");
            }
            translator.setValue("Trade", "LegId", leg, j, long.class);
            translator.setValue("Trade", "Notational", leg, j, double.class);
            translator.setValue("Trade", "Name", leg, "LegName " + j, String.class);
            legsMap.put(j, leg);
        }
        translator.setValue("Trade", "TradeId", trade, i, long.class);
        translator.setValue("Trade", "Name", trade, "TradeName " + i, String.class);
        translator.setValue("Trade", "Legs", trade, legsMap, Map.class);
        tradesCache.put(i, trade);
    }
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) TranslatorException(org.teiid.translator.TranslatorException) NamedCache(com.tangosol.net.NamedCache)

Example 5 with NamedCache

use of com.tangosol.net.NamedCache in project teiid by teiid.

the class CoherenceConnectionImpl method add.

public void add(Object key, Object value) throws ResourceException {
    NamedCache sourceCache = getCache();
    if (sourceCache.containsKey(key)) {
        throw new ResourceException("Unable to add object for key: " + key + " to cache " + this.cacheName + ", because it already exist");
    }
    TransactionMap tmap = CacheFactory.getLocalTransaction(sourceCache);
    tmap.setTransactionIsolation(TransactionMap.TRANSACTION_REPEATABLE_GET);
    tmap.setConcurrency(TransactionMap.CONCUR_PESSIMISTIC);
    tmap.begin();
    try {
        tmap.put(key, value);
        tmap.prepare();
        tmap.commit();
    } catch (Exception e) {
        throw new ResourceException(e);
    }
    sourceCache = getCache();
    if (!sourceCache.containsKey(key)) {
        throw new ResourceException("Problem adding object for key: " + key + " to the cache " + this.cacheName + ", object not found after add");
    }
}
Also used : ResourceException(javax.resource.ResourceException) TransactionMap(com.tangosol.util.TransactionMap) ResourceException(javax.resource.ResourceException) NamedCache(com.tangosol.net.NamedCache)

Aggregations

NamedCache (com.tangosol.net.NamedCache)7 TransactionMap (com.tangosol.util.TransactionMap)3 Map (java.util.Map)3 ResourceException (javax.resource.ResourceException)3 HashMap (java.util.HashMap)2 BackingMapManager (com.tangosol.net.BackingMapManager)1 DefaultConfigurableCacheFactory (com.tangosol.net.DefaultConfigurableCacheFactory)1 NearCache (com.tangosol.net.cache.NearCache)1 ReadWriteBackingMap (com.tangosol.net.cache.ReadWriteBackingMap)1 Cache (org.jivesoftware.util.cache.Cache)1 TranslatorException (org.teiid.translator.TranslatorException)1