001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.eclipse.aether.named.providers;
020
021import javax.inject.Named;
022import javax.inject.Singleton;
023
024import java.util.concurrent.TimeUnit;
025
026import org.eclipse.aether.named.support.NamedLockFactorySupport;
027import org.eclipse.aether.named.support.NamedLockSupport;
028
029/**
030 * A no-op lock factory, that creates no-op locks.
031 */
032@Singleton
033@Named(NoopNamedLockFactory.NAME)
034public class NoopNamedLockFactory extends NamedLockFactorySupport {
035    public static final String NAME = "noop";
036
037    @Override
038    protected NoopNamedLock createLock(final String name) {
039        return new NoopNamedLock(name, this);
040    }
041
042    private static final class NoopNamedLock extends NamedLockSupport {
043        private NoopNamedLock(final String name, final NamedLockFactorySupport factory) {
044            super(name, factory);
045        }
046
047        @Override
048        protected boolean doLockShared(final long time, final TimeUnit unit) {
049            return true;
050        }
051
052        @Override
053        protected boolean doLockExclusively(final long time, final TimeUnit unit) {
054            return true;
055        }
056
057        @Override
058        protected void doUnlock() {
059            // no-op
060        }
061    }
062}