Search in sources :

Example 1 with ResourceLock

use of org.gradle.internal.resources.ResourceLock 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)

Example 2 with ResourceLock

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

the class AbstractTask method getSharedResources.

@Override
public List<ResourceLock> getSharedResources() {
    if (requiredServices == null) {
        return Collections.emptyList();
    }
    ImmutableList.Builder<ResourceLock> locks = ImmutableList.builder();
    BuildServiceRegistryInternal serviceRegistry = getServices().get(BuildServiceRegistryInternal.class);
    for (Provider<? extends BuildService<?>> service : requiredServices) {
        SharedResource resource = serviceRegistry.forService(service);
        if (resource.getMaxUsages() > 0) {
            locks.add(resource.getResourceLock());
        }
    }
    return locks.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) BuildServiceRegistryInternal(org.gradle.api.services.internal.BuildServiceRegistryInternal) SharedResource(org.gradle.internal.resources.SharedResource) ResourceLock(org.gradle.internal.resources.ResourceLock)

Aggregations

ResourceLock (org.gradle.internal.resources.ResourceLock)2 ImmutableList (com.google.common.collect.ImmutableList)1 BuildServiceRegistryInternal (org.gradle.api.services.internal.BuildServiceRegistryInternal)1 MutableBoolean (org.gradle.internal.MutableBoolean)1 ResourceLockState (org.gradle.internal.resources.ResourceLockState)1 SharedResource (org.gradle.internal.resources.SharedResource)1