use of java.util.ConcurrentModificationException in project heron by twitter.
the class UpdateTopologyManager method updateTopology.
/**
* Scales the topology out or in based on the proposedPackingPlan
*
* @param existingProtoPackingPlan the current plan. If this isn't what's found in the state
* manager, the update will fail
* @param proposedProtoPackingPlan packing plan to change the topology to
*/
public void updateTopology(final PackingPlans.PackingPlan existingProtoPackingPlan, final PackingPlans.PackingPlan proposedProtoPackingPlan) throws ExecutionException, InterruptedException, ConcurrentModificationException {
String topologyName = Runtime.topologyName(runtime);
SchedulerStateManagerAdaptor stateManager = Runtime.schedulerStateManagerAdaptor(runtime);
Lock lock = stateManager.getLock(topologyName, IStateManager.LockName.UPDATE_TOPOLOGY);
if (lock.tryLock(5, TimeUnit.SECONDS)) {
try {
PackingPlans.PackingPlan foundPackingPlan = getPackingPlan(stateManager, topologyName);
if (!deserializer.fromProto(existingProtoPackingPlan).equals(deserializer.fromProto(foundPackingPlan))) {
throw new ConcurrentModificationException(String.format("The packing plan in state manager is not the same as the submitted existing " + "packing plan for topology %s. Another actor has changed it and has likely" + "performed an update on it. Failing this request, try again once other " + "update is complete", topologyName));
}
updateTopology(existingProtoPackingPlan, proposedProtoPackingPlan, stateManager);
} finally {
lock.unlock();
}
} else {
throw new ConcurrentModificationException(String.format("The update lock can not be obtained for topology %s. Another actor is performing an " + "update on it. Failing this request, try again once current update is complete", topologyName));
}
}
use of java.util.ConcurrentModificationException in project j2objc by google.
the class AbstractListTest method test_iterator_next.
/*
* Regression test for HY-4398
*/
public void test_iterator_next() {
MockArrayList<String> t = new MockArrayList<String>();
t.list.add("a");
t.list.add("b");
Iterator it = t.iterator();
while (it.hasNext()) {
it.next();
}
try {
it.next();
fail("Should throw NoSuchElementException");
} catch (NoSuchElementException cme) {
// expected
}
t.add("c");
try {
it.remove();
fail("Should throw NoSuchElementException");
} catch (ConcurrentModificationException cme) {
// expected
}
it = t.iterator();
try {
it.remove();
fail("Should throw IllegalStateException");
} catch (IllegalStateException ise) {
// expected
}
Object value = it.next();
assertEquals("a", value);
}
use of java.util.ConcurrentModificationException in project j2objc by google.
the class ConcurrentModificationExceptionTest method test_messageAndCause.
@SuppressWarnings("ThrowableNotThrown")
public void test_messageAndCause() {
Throwable cause = new Throwable("cause msg");
assertMessageAndCause(null, null, new ConcurrentModificationException());
assertMessageAndCause("msg", null, new ConcurrentModificationException("msg"));
assertMessageAndCause("msg", cause, new ConcurrentModificationException("msg", cause));
assertMessageAndCause("msg", null, new ConcurrentModificationException("msg", null));
assertMessageAndCause(null, null, new ConcurrentModificationException((Throwable) null));
// cause.toString() is something like "java.lang.Throwable: cause msg"
assertMessageAndCause(cause.toString(), cause, new ConcurrentModificationException(cause));
}
use of java.util.ConcurrentModificationException in project j2objc by google.
the class HashtableTest method test_keySet_subtest0.
/**
* java.util.Hashtable#keySet()
*/
public void test_keySet_subtest0() {
Set s1 = ht10.keySet();
assertTrue("should contain key", s1.remove("Key 0"));
assertTrue("should not contain key", !s1.remove("Key 0"));
final int iterations = 10000;
final Hashtable ht = new Hashtable();
Thread t1 = new Thread() {
public void run() {
for (int i = 0; i < iterations; i++) {
ht.put(String.valueOf(i), "");
ht.remove(String.valueOf(i));
}
}
};
t1.start();
Set set = ht.keySet();
for (int i = 0; i < iterations; i++) {
Iterator it = set.iterator();
try {
it.next();
it.remove();
int size;
// Hashtable
if ((size = ht.size()) < 0) {
fail("invalid size: " + size);
}
} catch (NoSuchElementException e) {
} catch (ConcurrentModificationException e) {
}
}
}
use of java.util.ConcurrentModificationException in project tomee by apache.
the class ClassLoaderUtil method clearSunJarFileFactoryCacheImpl.
/**
* Due to several different implementation changes in various JDK releases the code here is not as
* straight forward as reflecting debug items in your current runtime. There have even been breaking changes
* between 1.6 runtime builds, let alone 1.5.
*
* If you discover a new issue here please be careful to ensure the existing functionality is 'extended' and not
* just replaced to match your runtime observations.
*
* If you want to look at the mess that leads up to this then follow the source code changes made to
* the class sun.net.www.protocol.jar.JarFileFactory over several years.
*
* @param jarLocation String
* @param attempt int
*/
@SuppressWarnings({ "unchecked" })
private static synchronized void clearSunJarFileFactoryCacheImpl(final String jarLocation, final int attempt) {
if (skipClearSunJarFile.get()) {
return;
}
logger.debug("Clearing Sun JarFileFactory cache for directory " + jarLocation);
try {
final Class jarFileFactory = Class.forName("sun.net.www.protocol.jar.JarFileFactory");
// Do not generify these maps as their contents are NOT stable across runtimes.
final Field fileCacheField = jarFileFactory.getDeclaredField("fileCache");
fileCacheField.setAccessible(true);
final Map fileCache = (Map) fileCacheField.get(null);
final Map fileCacheCopy = new HashMap(fileCache);
final Field urlCacheField = jarFileFactory.getDeclaredField("urlCache");
urlCacheField.setAccessible(true);
final Map urlCache = (Map) urlCacheField.get(null);
final Map urlCacheCopy = new HashMap(urlCache);
// The only stable item we have here is the JarFile/ZipFile in this map
Iterator iterator = urlCacheCopy.entrySet().iterator();
final List urlCacheRemoveKeys = new ArrayList();
while (iterator.hasNext()) {
final Map.Entry entry = (Map.Entry) iterator.next();
final Object key = entry.getKey();
if (key instanceof ZipFile) {
final ZipFile zf = (ZipFile) key;
// getName returns File.getPath()
final File file = new File(zf.getName());
if (isParent(jarLocation, file)) {
// Flag for removal
urlCacheRemoveKeys.add(key);
}
} else {
logger.warning("Unexpected key type: " + key);
}
}
iterator = fileCacheCopy.entrySet().iterator();
final List fileCacheRemoveKeys = new ArrayList();
while (iterator.hasNext()) {
final Map.Entry entry = (Map.Entry) iterator.next();
final Object value = entry.getValue();
if (urlCacheRemoveKeys.contains(value)) {
fileCacheRemoveKeys.add(entry.getKey());
}
}
// Use these unstable values as the keys for the fileCache values.
iterator = fileCacheRemoveKeys.iterator();
while (iterator.hasNext()) {
final Object next = iterator.next();
try {
final Object remove = fileCache.remove(next);
if (null != remove) {
logger.debug("Removed item from fileCache: " + remove);
}
} catch (final Throwable e) {
logger.warning("Failed to remove item from fileCache: " + next);
}
}
iterator = urlCacheRemoveKeys.iterator();
while (iterator.hasNext()) {
final Object next = iterator.next();
try {
final Object remove = urlCache.remove(next);
try {
((ZipFile) next).close();
} catch (final Throwable e) {
// Ignore
}
if (null != remove) {
logger.debug("Removed item from urlCache: " + remove);
}
} catch (final Throwable e) {
logger.warning("Failed to remove item from urlCache: " + next);
}
}
} catch (final ConcurrentModificationException e) {
if (attempt > 0) {
clearSunJarFileFactoryCacheImpl(jarLocation, attempt - 1);
} else {
logger.error("Unable to clear Sun JarFileFactory cache after 5 attempts", e);
}
} catch (final ClassNotFoundException | NoSuchFieldException e) {
// not a sun vm
} catch (final RuntimeException re) {
if ("java.lang.reflect.InaccessibleObjectException".equals(re.getClass().getName())) {
skipClearSunJarFile.compareAndSet(false, true);
return;
}
throw re;
} catch (final Throwable e) {
if (Boolean.getBoolean("openejb.java9.hack")) {
// reflection fails cause internals are not exported, close() is called and should be fine
return;
}
logger.error("Unable to clear Sun JarFileFactory cache", e);
}
}
Aggregations