public void acquire()

in maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NamedLockFactoryAdapter.java [198:262]


        public void acquire(Collection<? extends Artifact> artifacts, Collection<? extends Metadata> metadatas) {
            Collection<NamedLockKey> keys = lockNaming.nameLocks(session, artifacts, metadatas);
            if (keys.isEmpty()) {
                return;
            }

            final String timeStr = time + " " + timeUnit;
            final String lockKind = shared ? "shared" : "exclusive";
            final NamedLock namedLock = namedLockFactory.getLock(keys);
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace(
                        "Need {} lock for {} from {}",
                        lockKind,
                        namedLock.key().resources(),
                        namedLock.key().name());
            }

            final int attempts = retry + 1;
            for (int attempt = 1; attempt <= attempts; attempt++) {
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace(
                            "Attempt {}: Acquire {} lock from {}",
                            attempt,
                            lockKind,
                            namedLock.key().name());
                }
                try {
                    if (attempt > 1) {
                        Thread.sleep(retryWait);
                    }
                    boolean locked;
                    if (shared) {
                        locked = namedLock.lockShared(time, timeUnit);
                    } else {
                        locked = namedLock.lockExclusively(time, timeUnit);
                    }

                    if (locked) {
                        // we are done, get out
                        locks.push(namedLock);
                        return;
                    }

                    // we failed; retry
                    if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace(
                                "Failed to acquire {} lock for '{}' in {}",
                                lockKind,
                                namedLock.key().name(),
                                timeStr);
                    }
                } catch (InterruptedException e) {
                    // if we are here, means we were interrupted: fail
                    close();
                    Thread.currentThread().interrupt();
                    throw new RuntimeException(e);
                }
            }
            // if we are here, means all attempts were unsuccessful: fail
            close();
            IllegalStateException ex = new IllegalStateException("Could not acquire " + lockKind + " lock for "
                    + namedLock.key().resources() + " using lock "
                    + namedLock.key().name() + " in " + timeStr);
            throw namedLockFactory.onFailure(ex);
        }