Search in sources :

Example 11 with CA

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

the class IpcSharedMemoryCrashDetectionSelfTest method startSharedMemoryTestClient.

/**
 * Starts {@code IgfsSharedMemoryTestClient}. The method doesn't wait while client being started.
 *
 * @return Start result of the {@code IgfsSharedMemoryTestClient}.
 * @throws Exception In case of any exception happen.
 */
private ProcessStartResult startSharedMemoryTestClient() throws Exception {
    /**
     */
    final CountDownLatch killedLatch = new CountDownLatch(1);
    /**
     */
    final CountDownLatch readyLatch = new CountDownLatch(1);
    /**
     */
    final ProcessStartResult res = new ProcessStartResult();
    /**
     * Process.
     */
    GridJavaProcess proc = GridJavaProcess.exec(IgfsSharedMemoryTestClient.class, null, log, new CI1<String>() {

        @Override
        public void apply(String s) {
            info("Client process prints: " + s);
            if (s.startsWith(IgfsSharedMemoryTestClient.SHMEM_IDS_MSG_PREFIX)) {
                res.shmemIds(s.substring(IgfsSharedMemoryTestClient.SHMEM_IDS_MSG_PREFIX.length()));
                readyLatch.countDown();
            }
        }
    }, new CA() {

        @Override
        public void apply() {
            info("Client is killed");
            killedLatch.countDown();
        }
    }, null, System.getProperty("surefire.test.class.path"));
    res.proc(proc);
    res.isKilledLatch(killedLatch);
    res.isReadyLatch(readyLatch);
    return res;
}
Also used : GridJavaProcess(org.apache.ignite.internal.util.GridJavaProcess) CountDownLatch(java.util.concurrent.CountDownLatch) CA(org.apache.ignite.internal.util.typedef.CA)

Example 12 with CA

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

the class GridCacheAbstractFullApiMultithreadedSelfTest method runTest.

/**
 * @param c Test closure.
 * @throws Exception In case of error.
 */
private void runTest(final IgniteInClosure<IgniteCache<String, Integer>> c) throws Exception {
    final IgniteInternalFuture<?> fut1 = GridTestUtils.runMultiThreadedAsync(new CAX() {

        @Override
        public void applyx() {
            while (true) {
                int i = cnt.getAndIncrement();
                if (i >= PUT_CNT)
                    break;
                jcache().put("key" + i, i);
                set.add(i);
                if (i > 10)
                    guard.compareAndSet(false, true);
            }
        }
    }, WRITE_THREAD_CNT, WRITE_THREAD_NAME);
    IgniteInternalFuture<?> fut2 = GridTestUtils.runMultiThreadedAsync(new CA() {

        @Override
        public void apply() {
            IgniteCache<String, Integer> cache = jcache();
            while (!fut1.isDone()) if (guard.get())
                c.apply(cache);
        }
    }, READ_THREAD_CNT, READ_THREAD_NAME);
    fut1.get();
    fut2.get();
    checkConsistency();
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) CAX(org.apache.ignite.internal.util.typedef.CAX) CA(org.apache.ignite.internal.util.typedef.CA)

Example 13 with CA

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

the class CacheGetFromJobTest method testTopologyChange.

/**
 * @throws Exception If failed.
 */
public void testTopologyChange() throws Exception {
    final AtomicReference<Exception> err = new AtomicReference<>();
    final AtomicInteger id = new AtomicInteger(1);
    IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new CA() {

        @Override
        public void apply() {
            info("Run topology change.");
            try {
                for (int i = 0; i < 5; i++) {
                    info("Topology change: " + i);
                    startGrid(id.getAndIncrement());
                }
            } catch (Exception e) {
                err.set(e);
                log.error("Unexpected exception in topology-change-thread: " + e, e);
            }
        }
    }, 3, "topology-change-thread");
    int cntr = 0;
    while (!fut.isDone()) {
        grid(0).compute().broadcast(new TestJob());
        cntr++;
    }
    log.info("Job execution count: " + cntr);
    Exception err0 = err.get();
    if (err0 != null)
        throw err0;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference) CA(org.apache.ignite.internal.util.typedef.CA)

Example 14 with CA

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

the class GridCacheDeploymentManager method unwind.

/**
 * Undeploy all queued up closures.
 *
 * @param ctx Cache context.
 */
public void unwind(GridCacheContext ctx) {
    List<CA> q;
    synchronized (undeploys) {
        q = undeploys.remove(ctx.name());
    }
    if (q == null)
        return;
    int cnt = 0;
    for (CA c : q) {
        c.apply();
        cnt++;
    }
    if (log.isDebugEnabled())
        log.debug("Unwound undeploys count: " + cnt);
}
Also used : CA(org.apache.ignite.internal.util.typedef.CA)

Aggregations

CA (org.apache.ignite.internal.util.typedef.CA)14 Ignite (org.apache.ignite.Ignite)3 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 GridJavaProcess (org.apache.ignite.internal.util.GridJavaProcess)2 IOException (java.io.IOException)1 WeakReference (java.lang.ref.WeakReference)1 Collection (java.util.Collection)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 IgniteKernal (org.apache.ignite.internal.IgniteKernal)1