use of java.util.ConcurrentModificationException in project datanucleus-core by datanucleus.
the class TreeMap method forEach.
@Override
public void forEach(BiConsumer<? super K, ? super V> action) {
Objects.requireNonNull(action);
for (Map.Entry<K, V> entry : (java.util.Set<Map.Entry<K, V>>) entrySet()) {
K k;
V v;
try {
k = entry.getKey();
v = entry.getValue();
} catch (IllegalStateException ise) {
// this usually means the entry is no longer in the map.
throw new ConcurrentModificationException(ise);
}
action.accept(k, v);
}
}
use of java.util.ConcurrentModificationException in project accumulo by apache.
the class ZooCache method get.
/**
* Gets data at the given path, filling status information into the given <code>Stat</code> object. A watch is established by this call.
*
* @param zPath
* path to get
* @param status
* status object to populate
* @return path data, or null if non-existent
*/
public byte[] get(final String zPath, final ZcStat status) {
ZooRunnable<byte[]> zr = new ZooRunnable<byte[]>() {
@Override
public byte[] run() throws KeeperException, InterruptedException {
ZcStat zstat = null;
// only read volatile once so following code works with a consistent snapshot
ImmutableCacheCopies lic = immutableCache;
byte[] val = lic.cache.get(zPath);
if (val != null || lic.cache.containsKey(zPath)) {
if (status != null) {
zstat = lic.statCache.get(zPath);
copyStats(status, zstat);
}
return val;
}
/*
* The following call to exists() is important, since we are caching that a node does not exist. Once the node comes into existence, it will be added to
* the cache. But this notification of a node coming into existence will only be given if exists() was previously called. If the call to exists() is
* bypassed and only getData() is called with a special case that looks for Code.NONODE in the KeeperException, then non-existence can not be cached.
*/
cacheWriteLock.lock();
try {
final ZooKeeper zooKeeper = getZooKeeper();
Stat stat = zooKeeper.exists(zPath, watcher);
byte[] data = null;
if (stat == null) {
if (log.isTraceEnabled()) {
log.trace("zookeeper did not contain {}", zPath);
}
} else {
try {
data = zooKeeper.getData(zPath, watcher, stat);
zstat = new ZcStat(stat);
} catch (KeeperException.BadVersionException | KeeperException.NoNodeException e1) {
throw new ConcurrentModificationException();
}
if (log.isTraceEnabled()) {
log.trace("zookeeper contained {} {}", zPath, (data == null ? null : new String(data, UTF_8)));
}
}
put(zPath, data, zstat);
copyStats(status, zstat);
return data;
} finally {
cacheWriteLock.unlock();
}
}
};
return zr.retry();
}
use of java.util.ConcurrentModificationException in project freeplane by freeplane.
the class ProxyUtils method createList.
public static <T> List<T> createList(final Collection<T> collection) {
return new AbstractList<T>() {
private int lastIndex;
private Iterator<T> iterator;
@Override
public T get(int index) {
if (index >= size())
throw new NoSuchElementException();
if (index == 0)
return collection.iterator().next();
if (iterator == null || index <= lastIndex) {
lastIndex = -1;
iterator = collection.iterator();
}
try {
T object;
for (object = null; lastIndex < index; lastIndex++) object = iterator.next();
return object;
} catch (ConcurrentModificationException e) {
iterator = null;
return get(index);
}
}
@Override
public int indexOf(Object o) {
final Iterator<T> it = iterator();
int i = -1;
while (it.hasNext()) {
i++;
final T next = it.next();
if (o == next || o != null && o.equals(next))
return i;
}
return -1;
}
@Override
public int lastIndexOf(Object o) {
final Iterator<T> it = iterator();
int i = -1;
int result = -1;
while (it.hasNext()) {
i++;
final T next = it.next();
if (o == next || o != null && o.equals(next))
result = i;
}
return result;
}
@Override
public Iterator<T> iterator() {
return collection.iterator();
}
@Override
public int size() {
return collection.size();
}
};
}
use of java.util.ConcurrentModificationException in project com.revolsys.open by revolsys.
the class LabelCountMapTableModel method setStatistics.
public void setStatistics(final Map<String, LabelCountMap> statisticsMap) {
try {
this.categoryLabelCountMap = new CategoryLabelCountMap(statisticsMap);
for (final Entry<String, LabelCountMap> entry : statisticsMap.entrySet()) {
final String countName = entry.getKey();
addCountNameColumn(countName);
final LabelCountMap labelCountMap = entry.getValue();
for (final String label : labelCountMap.getLabels()) {
newStatistics(countName, label);
}
}
} catch (final ConcurrentModificationException e) {
}
refresh();
}
use of java.util.ConcurrentModificationException in project kernel by cristal-ise.
the class MemoryOnlyClusterStorage method dumpContents.
public void dumpContents(ItemPath thisItem) {
synchronized (memoryCache) {
Logger.msg(0, "Cached Objects of Entity " + thisItem);
Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(thisItem);
if (sysKeyMemCache == null) {
Logger.msg(0, "No cache found");
return;
}
try {
synchronized (sysKeyMemCache) {
for (Object name : sysKeyMemCache.keySet()) {
String path = (String) name;
try {
Logger.msg(0, " Path " + path + ": " + sysKeyMemCache.get(path).getClass().getName());
} catch (NullPointerException e) {
Logger.msg(0, " Path " + path + ": reaped");
}
}
}
} catch (ConcurrentModificationException ex) {
Logger.msg(0, "Cache modified - aborting");
}
}
Logger.msg(0, "Total number of cached entities: " + memoryCache.size());
}
Aggregations