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;
15 * Proposal for how a key based semaphore provider should look like.
17 * <li>thread safe</li>
18 * <li>garbage-collect unused semaphores</li>
19 * <li>for the same key there must be always only one semaphore available</li>
25 * final Semaphore guard = semaphoreKeeper.summonGuard(key);
27 * // guard protected logic ...
34 public interface SemaphoreKeeper<K> {
36 * @param key semaphore identifier
37 * @return new or existing semaphore for given key, for one key there is always only one semaphore available
39 Semaphore summonGuard(@Nonnull K key);