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.NamedLockKey;
027import org.eclipse.aether.named.support.NamedLockFactorySupport;
028import org.eclipse.aether.named.support.NamedLockSupport;
029
030/**
031 * A no-op lock factory, that creates no-op locks.
032 */
033@Singleton
034@Named(NoopNamedLockFactory.NAME)
035public class NoopNamedLockFactory extends NamedLockFactorySupport {
036    public static final String NAME = "noop";
037
038    @Override
039    protected NoopNamedLock createLock(final NamedLockKey key) {
040        return new NoopNamedLock(key, this);
041    }
042
043    private static final class NoopNamedLock extends NamedLockSupport {
044        private NoopNamedLock(final NamedLockKey key, final NamedLockFactorySupport factory) {
045            super(key, factory);
046        }
047
048        @Override
049        protected boolean doLockShared(final long time, final TimeUnit unit) {
050            return true;
051        }
052
053        @Override
054        protected boolean doLockExclusively(final long time, final TimeUnit unit) {
055            return true;
056        }
057
058        @Override
059        protected void doUnlock() {
060            // no-op
061        }
062    }
063}