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);
}
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");
}
}
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");
}
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);
}
}
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");
}
}
Aggregations