Line data Source code
1 : // Copyright (C) 2017 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.project; 16 : 17 : import com.google.common.util.concurrent.Striped; 18 : import com.google.gerrit.entities.Project; 19 : import com.google.gerrit.extensions.registration.DynamicItem; 20 : import com.google.inject.AbstractModule; 21 : import com.google.inject.Singleton; 22 : import java.util.concurrent.locks.Lock; 23 : 24 : /** In-memory lock for project names. */ 25 : @Singleton 26 146 : public class DefaultProjectNameLockManager implements ProjectNameLockManager { 27 : 28 152 : public static class DefaultProjectNameLockManagerModule extends AbstractModule { 29 : @Override 30 : protected void configure() { 31 152 : DynamicItem.bind(binder(), ProjectNameLockManager.class) 32 152 : .to(DefaultProjectNameLockManager.class); 33 152 : } 34 : } 35 : 36 146 : Striped<Lock> locks = Striped.lock(10); 37 : 38 : @Override 39 : public Lock getLock(Project.NameKey name) { 40 143 : return locks.get(name); 41 : } 42 : }