Search in sources :

Example 61 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project Cached-Datastore by Emperorlou.

the class ShardedCounterService method incrementCounter.

/**
 * Increments the given counter (found by the entity's key and fieldName) by the given value.
 *
 * NOTE: If this is the first time the sharded counter has been used, the entity parameter will be
 * put to the database.
 *
 * @param entity
 * @param fieldName
 * @param increment
 * @return
 */
public void incrementCounter(Key entityKey, String fieldName, long increment, Integer defaultShardCount) {
    if (defaultShardCount == null)
        defaultShardCount = 5;
    // EmbeddedEntity zeroShard = (EmbeddedEntity) entity.getProperty(fieldName);
    // if (zeroShard == null)
    // zeroShard = initializeCounter(entity, fieldName, defaultShardCount);
    Integer numShards = defaultShardCount;
    while (true) {
        ds.beginTransaction();
        int rndNum = randomGenerator.nextInt(numShards) + 1;
        String shardName = getShardName(entityKey, fieldName, rndNum);
        Key shardKey = KeyFactory.createKey(SHARD_COUNTER_KIND, shardName);
        CachedEntity shard = ds.getIfExists(shardKey);
        if (shard != null) {
            long val = (Long) shard.getProperty("value");
            shard.setUnindexedPropertyManually("value", val + increment);
        } else {
            shard = new CachedEntity(shardKey);
            shard.setUnindexedPropertyManually("value", increment);
            shard.setProperty("entity", entityKey);
            shard.setProperty("fieldName", fieldName);
        }
        ds.put(shard);
        try {
            ds.commit();
        } catch (ConcurrentModificationException ignored) {
            // TRY AGAIN
            continue;
        }
        return;
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) Key(com.google.appengine.api.datastore.Key)

Example 62 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project eclipse-integration-commons by spring-projects.

the class ManagedTestSuite method dumpSystemInfo.

private void dumpSystemInfo() {
    try {
        if (Platform.isRunning() && CommonsNetPlugin.getProxyService() != null && CommonsNetPlugin.getProxyService().isSystemProxiesEnabled() && !CommonsNetPlugin.getProxyService().hasSystemProxies()) {
            // XXX e3.5/gtk.x86_64 activate manual proxy configuration which
            // defaults to Java system properties if system proxy support is
            // not available
            System.err.println("Forcing manual proxy configuration");
            CommonsNetPlugin.getProxyService().setSystemProxiesEnabled(false);
            CommonsNetPlugin.getProxyService().setProxiesEnabled(true);
        }
        Properties p = System.getProperties();
        if (Platform.isRunning()) {
            p.put("build.system", Platform.getOS() + "-" + Platform.getOSArch() + "-" + Platform.getWS());
        } else {
            p.put("build.system", "standalone");
        }
        String info = "System: ${os.name} ${os.version} (${os.arch}) / ${build.system} / ${java.vendor} ${java.vm.name} ${java.version}";
        for (Entry<Object, Object> entry : p.entrySet()) {
            info = info.replaceFirst(Pattern.quote("${" + entry.getKey() + "}"), entry.getValue().toString());
        }
        System.err.println(info);
        System.err.print("Proxy : " + WebUtil.getProxy("google.com", IProxyData.HTTP_PROXY_TYPE) + " (Platform)");
        try {
            System.err.print(" / " + ProxySelector.getDefault().select(new URI("http://google.com")) + " (Java)");
        } catch (URISyntaxException e) {
        // ignore
        }
        System.err.println();
        System.err.println();
    } catch (ConcurrentModificationException e) {
        // Not sure why but sometimes thrown by the code that is dumping out
        // system properties!
        // Catch and print it, but don't abort the test runner simply
        // because this info can't be dumped.
        e.printStackTrace();
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) URISyntaxException(java.net.URISyntaxException) Properties(java.util.Properties) URI(java.net.URI)

Example 63 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project eclipse-integration-commons by spring-projects.

the class StsTestUtil method setUpProject.

public static IProject setUpProject(final String projectName, String compliance, String sourceWorkspacePath) throws CoreException, IOException {
    // copy files in project from source workspace to target workspace
    String targetWorkspacePath = getWorkspaceRoot().getLocation().toFile().getCanonicalPath();
    File sourceProjectPath = new File(sourceWorkspacePath, projectName);
    assertTrue("Doesn't exist: " + sourceProjectPath, sourceProjectPath.exists());
    copyDirectory(sourceProjectPath, new File(targetWorkspacePath, projectName));
    // create project
    final IProject project = getWorkspaceRoot().getProject(projectName);
    IWorkspaceRunnable populate = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            project.create(null);
            try {
                project.open(null);
            } catch (ConcurrentModificationException e) {
                // ConcurrentModificationException (bug 280488)
                try {
                    Thread.sleep(500);
                    project.open(null);
                    project.refreshLocal(IResource.DEPTH_INFINITE, null);
                } catch (InterruptedException e1) {
                    Thread.currentThread().interrupt();
                }
            }
        }
    };
    getWorkspace().run(populate, null);
    return project;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConcurrentModificationException(java.util.ConcurrentModificationException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 64 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project incubator-heron by apache.

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));
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) PackingPlans(com.twitter.heron.proto.system.PackingPlans) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) Lock(com.twitter.heron.spi.statemgr.Lock)

Example 65 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project fresco by facebook.

the class StatefulProducerRunnableTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mException = new ConcurrentModificationException();
    mSuccessMap = new HashMap<>();
    mSuccessMap.put("state", "success");
    mFailureMap = new HashMap<>();
    mFailureMap.put("state", "failure");
    mCancellationMap = new HashMap<>();
    mCancellationMap.put("state", "cancelled");
    mStatefulProducerRunnable = new StatefulProducerRunnable<Closeable>(mConsumer, mProducerListener, mProducerContext, PRODUCER_NAME) {

        @Override
        protected void disposeResult(Closeable result) {
            try {
                result.close();
            } catch (IOException ioe) {
                throw new RuntimeException("unexpected IOException", ioe);
            }
        }

        @Override
        protected Closeable getResult() throws Exception {
            return mResultSupplier.get();
        }

        @Override
        protected Map<String, String> getExtraMapOnCancellation() {
            return mCancellationMap;
        }

        @Override
        protected Map<String, String> getExtraMapOnFailure(Exception exception) {
            return mFailureMap;
        }

        @Override
        protected Map<String, String> getExtraMapOnSuccess(Closeable result) {
            return mSuccessMap;
        }
    };
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) Closeable(java.io.Closeable) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) IOException(java.io.IOException) ConcurrentModificationException(java.util.ConcurrentModificationException)

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