2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.applications.frsync;
11 import java.util.concurrent.Semaphore;
12 import javax.annotation.Nonnull;
13 import javax.annotation.Nullable;
16 * Key based semaphore provider.
17 * For the same key there is always only one semaphore available. Unused semaphores are garbage-collect.
21 public interface SemaphoreKeeper<K> {
23 * Create or load semaphore for key from cache.
24 * @param key semaphore identifier
25 * @return new or existing semaphore for given key, for one key there is always only one semaphore available
27 Semaphore summonGuard(@Nonnull final K key);
30 * Get guard and lock for key.
31 * @param key for which guard should be created and acquired
32 * @return semaphore guard
34 Semaphore summonGuardAndAcquire(@Nonnull final K key);
37 * Unlock and release guard.
38 * @param guard semaphore guard which should be released
40 void releaseGuard(@Nullable final Semaphore guard);