Search in sources :

Example 1 with GridSpinReadWriteLock

use of org.apache.ignite.internal.util.GridSpinReadWriteLock in project ignite by apache.

the class GridSpinReadWriteLockSelfTest method testWriteLockReentry.

/**
     * @throws Exception If any error occurs.
     */
public void testWriteLockReentry() throws Exception {
    GridSpinReadWriteLock lock = new GridSpinReadWriteLock();
    lock.writeLock();
    lock.writeLock();
    boolean b = lock.tryWriteLock();
    assert b;
}
Also used : GridSpinReadWriteLock(org.apache.ignite.internal.util.GridSpinReadWriteLock)

Example 2 with GridSpinReadWriteLock

use of org.apache.ignite.internal.util.GridSpinReadWriteLock in project ignite by apache.

the class GridSpinReadWriteLockSelfTest method testReadLockReentry.

/**
     * @throws Exception If any error occurs.
     */
public void testReadLockReentry() throws Exception {
    final GridSpinReadWriteLock lock = new GridSpinReadWriteLock();
    lock.readLock();
    final CountDownLatch latch = new CountDownLatch(1);
    IgniteInternalFuture<?> f = multithreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            assert !lock.tryWriteLock();
            info("Before write lock.");
            latch.countDown();
            lock.writeLock();
            info("After write lock.");
            return null;
        }
    }, 1);
    latch.await();
    U.sleep(100);
    lock.readLock();
    assert lock.tryReadLock();
    lock.readUnlock();
    lock.readUnlock();
    lock.readUnlock();
    f.get();
}
Also used : GridSpinReadWriteLock(org.apache.ignite.internal.util.GridSpinReadWriteLock) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 3 with GridSpinReadWriteLock

use of org.apache.ignite.internal.util.GridSpinReadWriteLock in project ignite by apache.

the class HadoopJobTracker method start.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public void start(final HadoopContext ctx) throws IgniteCheckedException {
    super.start(ctx);
    busyLock = new GridSpinReadWriteLock();
    evtProcSvc = Executors.newFixedThreadPool(1);
    assert jobCls == null;
    HadoopClassLoader ldr = ctx.kernalContext().hadoopHelper().commonClassLoader();
    try {
        jobCls = (Class<HadoopJobEx>) ldr.loadClass(HadoopCommonUtils.JOB_CLS_NAME);
    } catch (Exception ioe) {
        throw new IgniteCheckedException("Failed to load job class [class=" + HadoopCommonUtils.JOB_CLS_NAME + ']', ioe);
    }
}
Also used : HadoopClassLoader(org.apache.ignite.internal.processors.hadoop.HadoopClassLoader) GridSpinReadWriteLock(org.apache.ignite.internal.util.GridSpinReadWriteLock) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) HadoopJobEx(org.apache.ignite.internal.processors.hadoop.HadoopJobEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) HadoopTaskCancelledException(org.apache.ignite.internal.processors.hadoop.HadoopTaskCancelledException)

Example 4 with GridSpinReadWriteLock

use of org.apache.ignite.internal.util.GridSpinReadWriteLock in project ignite by apache.

the class GridSpinReadWriteLockSelfTest method testLockDowngrade.

/**
     * @throws Exception If any error occurs.
     */
public void testLockDowngrade() throws Exception {
    GridSpinReadWriteLock lock = new GridSpinReadWriteLock();
    // Read lock while holding write lock.
    lock.writeLock();
    lock.readLock();
    lock.readUnlock();
    lock.writeUnlock();
    // Downgrade from write to read lock.
    lock.writeLock();
    lock.readLock();
    lock.writeUnlock();
    assert !lock.tryWriteLock();
    lock.readUnlock();
    // Test that we can operate with write locks now.
    lock.writeLock();
    lock.writeUnlock();
}
Also used : GridSpinReadWriteLock(org.apache.ignite.internal.util.GridSpinReadWriteLock)

Aggregations

GridSpinReadWriteLock (org.apache.ignite.internal.util.GridSpinReadWriteLock)4 CountDownLatch (java.util.concurrent.CountDownLatch)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 HadoopClassLoader (org.apache.ignite.internal.processors.hadoop.HadoopClassLoader)1 HadoopJobEx (org.apache.ignite.internal.processors.hadoop.HadoopJobEx)1 HadoopTaskCancelledException (org.apache.ignite.internal.processors.hadoop.HadoopTaskCancelledException)1