com.alachisoft.ncache.client.CacheCollection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ncache-professional-client Show documentation
Show all versions of ncache-professional-client Show documentation
NCache Professional client for java.
package com.alachisoft.ncache.client;
import com.alachisoft.ncache.client.Cache;
import com.alachisoft.ncache.client.internal.caching.CacheImpl;
import com.alachisoft.ncache.client.internal.util.ConfigReader;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import static tangible.DotNetToJavaStringHelper.isNullOrEmpty;
public class CacheCollection implements Iterable {
private HashMap caches = null;
public CacheCollection() {
caches = new HashMap(8);
}
public void addCache(String cacheId, CacheImpl c) {
caches.put(cacheId.toLowerCase(), c);
}
public boolean contains(String cacheId) {
return caches.containsKey(cacheId.toLowerCase());
}
public CacheImpl removeCache(String cacheId) {
return (CacheImpl) caches.remove(cacheId.toLowerCase());
}
public int size() {
return caches.size();
}
public Collection values() {
return caches.values();
}
//~--- get methods --------------------------------------------------------
/**
* @param cacheId Name of cache
* @return Cache instance
*/
public CacheImpl getCache(String cacheId) {
return (CacheImpl) caches.get(cacheId.toLowerCase());
}
public CacheImpl getCache(String cacheId, boolean useClientCache) throws Exception {
String clientCache = "";
boolean isPessimistic = false;
tangible.RefObject tempRef_clientCache = new tangible.RefObject(clientCache);
tangible.RefObject tempRef_isPessimistic = new tangible.RefObject(isPessimistic);
boolean tempVar = useClientCache && hasClientCache(cacheId, tempRef_clientCache, tempRef_isPessimistic);
clientCache = tempRef_clientCache.argvalue;
isPessimistic = tempRef_isPessimistic.argvalue;
if (tempVar) {
}
return (caches.get(cacheId.toLowerCase()) instanceof Cache) ? (CacheImpl) caches.get(cacheId.toLowerCase()) : null;
}
public Iterator iterator() {
return new CacheIterator();
}
public boolean hasClientCache(String cacheId, tangible.RefObject clientCacheID, tangible.RefObject isPessimistic) throws Exception {
if (cacheId == null) {
throw new IllegalArgumentException("Value cannot be null."+System.lineSeparator()+"Parameter name: cacheId");
}
try {
clientCacheID.argvalue = ConfigReader.ClientCacheID("client.ncconf", cacheId, isPessimistic).trim().toString();
if (clientCacheID.argvalue.length() > 0) {
return true;
} else {
return false;
}
} catch (Exception e) {
throw e;
}
}
private class CacheIterator implements Iterator {
private HashMap _caches = (HashMap) caches.clone();
Iterator keys = _caches.keySet().iterator();//int i=0;
public boolean hasNext() {
return keys.hasNext();
}
public CacheImpl next() {
return (CacheImpl) _caches.get((String) keys.next());
}
public void remove() {
throw new UnsupportedOperationException();
}
}
}