Search in sources :

Example 1 with CA

use of org.apache.ignite.internal.util.typedef.CA in project ignite by apache.

the class GridCacheDeploymentManager method onUndeploy.

/**
     * Undeploys given class loader.
     *
     * @param ldr Class loader to undeploy.
     * @param ctx Grid cache context.
     */
public void onUndeploy(final ClassLoader ldr, final GridCacheContext<K, V> ctx) {
    assert ldr != null;
    if (log.isDebugEnabled())
        log.debug("Received onUndeploy() request [ldr=" + ldr + ", cctx=" + cctx + ']');
    synchronized (undeploys) {
        List<CA> queue = undeploys.get(ctx.name());
        if (queue == null)
            undeploys.put(ctx.name(), queue = new ArrayList<>());
        queue.add(new CA() {

            @Override
            public void apply() {
                onUndeploy0(ldr, ctx);
            }
        });
    }
    // We go through preloader for proper synchronization.
    if (ctx.isLocal())
        ctx.preloader().unwindUndeploys();
}
Also used : CA(org.apache.ignite.internal.util.typedef.CA)

Example 2 with CA

use of org.apache.ignite.internal.util.typedef.CA in project ignite by apache.

the class GridCacheAbstractDataStructuresFailoverSelfTest method testAtomicSequenceInitialization.

/**
     * @throws Exception If failed.
     */
public void testAtomicSequenceInitialization() throws Exception {
    int threadCnt = 3;
    final AtomicInteger idx = new AtomicInteger(gridCount());
    IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new CA() {

        @Override
        public void apply() {
            int id = idx.getAndIncrement();
            try {
                log.info("Start node: " + id);
                startGrid(id);
                Thread.sleep(1000);
            } catch (Exception e) {
                throw F.wrap(e);
            } finally {
                stopGrid(id);
                info("Thread finished.");
            }
        }
    }, threadCnt, "test-thread");
    while (!fut.isDone()) {
        grid(0).compute().call(new IgniteCallable<Object>() {

            /** */
            @IgniteInstanceResource
            private Ignite g;

            @Override
            public Object call() throws Exception {
                IgniteAtomicSequence seq = g.atomicSequence(STRUCTURE_NAME, 1, true);
                assert seq != null;
                for (int i = 0; i < 1000; i++) seq.getAndIncrement();
                return null;
            }
        });
    }
    fut.get();
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) Ignite(org.apache.ignite.Ignite) CA(org.apache.ignite.internal.util.typedef.CA) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteException(org.apache.ignite.IgniteException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException)

Example 3 with CA

use of org.apache.ignite.internal.util.typedef.CA in project ignite by apache.

the class GridCacheAbstractIteratorsSelfTest method testEntrySetIteratorMultithreaded.

/**
     * @throws Exception If failed.
     */
public void testEntrySetIteratorMultithreaded() throws Exception {
    for (int i = 0; i < gridCount(); i++) jcache(i).removeAll();
    final IgniteInternalFuture<?> putFut = GridTestUtils.runMultiThreadedAsync(new CAX() {

        @Override
        public void applyx() {
            for (int i = 0; i < entryCount(); i++) jcache().put(KEY_PREFIX + i, i);
        }
    }, 1, "put-thread");
    GridTestUtils.runMultiThreaded(new CA() {

        @Override
        public void apply() {
            while (!putFut.isDone()) {
                for (Cache.Entry<String, Integer> entry : jcache()) {
                    assert entry != null;
                    assert entry.getKey() != null;
                    assert entry.getKey().contains(KEY_PREFIX);
                }
            }
        }
    }, 3, "iterator-thread");
}
Also used : CAX(org.apache.ignite.internal.util.typedef.CAX) CA(org.apache.ignite.internal.util.typedef.CA)

Example 4 with CA

use of org.apache.ignite.internal.util.typedef.CA in project ignite by apache.

the class GridCacheAbstractIteratorsSelfTest method testCacheIteratorMultithreaded.

/**
     * @throws Exception If failed.
     */
public void testCacheIteratorMultithreaded() throws Exception {
    for (int i = 0; i < gridCount(); i++) jcache(i).removeAll();
    final IgniteInternalFuture<?> putFut = GridTestUtils.runMultiThreadedAsync(new CAX() {

        @Override
        public void applyx() {
            for (int i = 0; i < entryCount(); i++) jcache().put(KEY_PREFIX + i, i);
        }
    }, 1, "put-thread");
    GridTestUtils.runMultiThreaded(new CA() {

        @Override
        public void apply() {
            while (!putFut.isDone()) {
                for (Cache.Entry<String, Integer> entry : jcache()) {
                    assert entry != null;
                    assert entry.getKey() != null;
                    assert entry.getKey().contains(KEY_PREFIX);
                }
            }
        }
    }, 3, "iterator-thread");
}
Also used : CAX(org.apache.ignite.internal.util.typedef.CAX) CA(org.apache.ignite.internal.util.typedef.CA)

Example 5 with CA

use of org.apache.ignite.internal.util.typedef.CA in project ignite by apache.

the class GridCacheReferenceCleanupSelfTest method checkReferenceCleanup.

/**
     * @param call Callable.
     * @throws Exception If failed.
     */
public void checkReferenceCleanup(Callable<Collection<WeakReference<Object>>> call) throws Exception {
    for (boolean cancel : new boolean[] { true, false }) {
        this.cancel = cancel;
        final Collection<WeakReference<Object>> refs = call.call();
        GridTestUtils.retryAssert(log, 10, 1000, new CA() {

            @Override
            public void apply() {
                System.gc();
                System.gc();
                System.gc();
                for (WeakReference<?> ref : refs) assertNull("" + ref.get(), ref.get());
            }
        });
    }
}
Also used : WeakReference(java.lang.ref.WeakReference) CA(org.apache.ignite.internal.util.typedef.CA)

Aggregations

CA (org.apache.ignite.internal.util.typedef.CA)17 Ignite (org.apache.ignite.Ignite)6 CAX (org.apache.ignite.internal.util.typedef.CAX)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 IgniteCache (org.apache.ignite.IgniteCache)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 GridJavaProcess (org.apache.ignite.internal.util.GridJavaProcess)2 WeakReference (java.lang.ref.WeakReference)1 Collection (java.util.Collection)1 UUID (java.util.UUID)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 CacheException (javax.cache.CacheException)1 IgniteAtomicSequence (org.apache.ignite.IgniteAtomicSequence)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)1 CachePartialUpdateException (org.apache.ignite.cache.CachePartialUpdateException)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1