770e534ea414c30370e6a47890dfacc2405cd1e3
[mdsal.git] / singleton-service / mdsal-singleton-common-api / src / main / java / org / opendaylight / mdsal / singleton / common / api / ClusterSingletonServiceProvider.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.singleton.common.api;
9
10 import org.opendaylight.yangtools.concepts.Registration;
11
12 /**
13  * {@link ClusterSingletonServiceProvider} provides a functionality to register and group services
14  * {@link ClusterSingletonService} by service group identifier. Services could be Applications or RPCs.
15  * Provider provides a functionality which allows to have only one fully instantiated service instance
16  * in a cluster at one time and service group means to have all service instances for the same group
17  * situated on same Cluster Node. This is realized via a double candidate approach where a service
18  * group instance maintains a candidate registration for ownership of the service group entity in the
19  * cluster and also a registration that acts as a guard to ensure a service group instance has fully
20  * closed prior to relinquishing service group ownership. To achieve ownership of the service group,
21  * a service group candidate must hold ownership of both these entities.
22  */
23 public interface ClusterSingletonServiceProvider {
24     /**
25      * Method registers {@link ClusterSingletonService} to Provider.
26      * Method returns {@link java.lang.RuntimeException} for unexpected state, so be careful with implementation.
27      * Note: RuntimeException is implemented as a notification about some problems with registration and client
28      * has to implement some strategy for handling this issue.
29      * TODO: RuntimeException is not a transparent contract for handling unexpected state and it needs to be
30      * replaced with a specific documented Exception or it needs to add another contract definition for a client
31      * notification about the unexpected state reason in {@link ClusterSingletonService}.
32      * RuntimeException implementation is a hotfix for an unwanted API contract changes in boron release only.
33      *
34      * @param service ClusterSingletonService instance
35      * @return {@link Registration} registration
36      */
37     Registration registerClusterSingletonService(ClusterSingletonService service);
38 }