Search in sources :

Example 1 with ResourceLockState

use of org.gradle.internal.resources.ResourceLockState in project gradle by gradle.

the class DefaultTaskExecutionPlan method executeWithTask.

@Override
public boolean executeWithTask(final WorkerLease workerLease, final Action<TaskInternal> taskExecution) {
    final AtomicReference<TaskInfo> selected = new AtomicReference<TaskInfo>();
    final AtomicBoolean workRemaining = new AtomicBoolean();
    coordinationService.withStateLock(new Transformer<ResourceLockState.Disposition, ResourceLockState>() {

        @Override
        public ResourceLockState.Disposition transform(ResourceLockState resourceLockState) {
            if (cancellationToken.isCancellationRequested()) {
                if (abortExecution()) {
                    tasksCancelled = true;
                }
            }
            workRemaining.set(workRemaining());
            if (!workRemaining.get()) {
                return FINISHED;
            }
            if (allProjectsLocked()) {
                return RETRY;
            }
            try {
                selected.set(selectNextTask(workerLease));
            } catch (Throwable t) {
                abortAllAndFail(t);
                workRemaining.set(false);
            }
            if (selected.get() == null && workRemaining.get()) {
                return RETRY;
            } else {
                return FINISHED;
            }
        }
    });
    TaskInfo selectedTask = selected.get();
    execute(selectedTask, workerLease, taskExecution);
    return workRemaining.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Disposition(org.gradle.internal.resources.ResourceLockState.Disposition) AtomicReference(java.util.concurrent.atomic.AtomicReference) ResourceLockState(org.gradle.internal.resources.ResourceLockState)

Example 2 with ResourceLockState

use of org.gradle.internal.resources.ResourceLockState in project gradle by gradle.

the class DefaultWorkerLeaseService method allLockedByCurrentThread.

private boolean allLockedByCurrentThread(final Iterable<? extends ResourceLock> locks) {
    final MutableBoolean allLocked = new MutableBoolean();
    coordinationService.withStateLock(new Transformer<ResourceLockState.Disposition, ResourceLockState>() {

        @Override
        public ResourceLockState.Disposition transform(ResourceLockState resourceLockState) {
            allLocked.set(CollectionUtils.every(locks, new Spec<ResourceLock>() {

                @Override
                public boolean isSatisfiedBy(ResourceLock lock) {
                    return lock.isLockedByCurrentThread();
                }
            }));
            return FINISHED;
        }
    });
    return allLocked.get();
}
Also used : MutableBoolean(org.gradle.internal.MutableBoolean) ResourceLock(org.gradle.internal.resources.ResourceLock) ResourceLockState(org.gradle.internal.resources.ResourceLockState)

Aggregations

ResourceLockState (org.gradle.internal.resources.ResourceLockState)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 MutableBoolean (org.gradle.internal.MutableBoolean)1 ResourceLock (org.gradle.internal.resources.ResourceLock)1 Disposition (org.gradle.internal.resources.ResourceLockState.Disposition)1