Search in sources :

Example 56 with ConcurrentModificationException

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);
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 57 with ConcurrentModificationException

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();
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) ZooKeeper(org.apache.zookeeper.ZooKeeper) Stat(org.apache.zookeeper.data.Stat)

Example 58 with ConcurrentModificationException

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();
        }
    };
}
Also used : AbstractList(java.util.AbstractList) ConcurrentModificationException(java.util.ConcurrentModificationException) Iterator(java.util.Iterator) IFormattedObject(org.freeplane.features.format.IFormattedObject) NoSuchElementException(java.util.NoSuchElementException)

Example 59 with ConcurrentModificationException

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();
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) CategoryLabelCountMap(com.revolsys.util.count.CategoryLabelCountMap) CategoryLabelCountMap(com.revolsys.util.count.CategoryLabelCountMap) LabelCountMap(com.revolsys.util.count.LabelCountMap)

Example 60 with ConcurrentModificationException

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());
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject)

Aggregations

ConcurrentModificationException (java.util.ConcurrentModificationException)206 Iterator (java.util.Iterator)34 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)24 HashSet (java.util.HashSet)23 Map (java.util.Map)19 Set (java.util.Set)19 Test (org.junit.Test)19 ResultSet (java.sql.ResultSet)16 HashMap (java.util.HashMap)13 NoSuchElementException (java.util.NoSuchElementException)13 List (java.util.List)10 Collection (java.util.Collection)9 GameLocal (org.apache.openejb.test.entity.cmr.manytomany.GameLocal)8 PlatformLocal (org.apache.openejb.test.entity.cmr.manytomany.PlatformLocal)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 AbstractList (java.util.AbstractList)6 LinkedList (java.util.LinkedList)6 ArtistLocal (org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal)6 SongLocal (org.apache.openejb.test.entity.cmr.onetomany.SongLocal)6