Bug 5421 - Single cluster-wide service API
[mdsal.git] / singleton-service / mdsal-singleton-common-api / src / main / java / org / opendaylight / mdsal / singleton / common / api / ClusterSingletonServiceGroup.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
9 package org.opendaylight.mdsal.singleton.common.api;
10
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.List;
13 import org.opendaylight.mdsal.eos.common.api.GenericEntity;
14 import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipChange;
15 import org.opendaylight.yangtools.concepts.Path;
16
17 /**
18  * {@link ClusterSingletonServiceGroup} maintains a group of {@link ClusterSingletonService}
19  * instancies. All EntityOwnershipChange notifications have to applied to all registered
20  * services at the same time in the same manner.
21  * So this interface represents a single cluster service group instance." - remove this
22  * sentence. All registered services have only one instantiated service instance in a cluster
23  * at one time on same Cluster Node. This is realized via a double candidate approach where
24  * a service group instance maintains a candidate registration for ownership of the service
25  * entity in the cluster and also a registration that acts as a guard to ensure a service
26  * group instance has fully closed prior to relinquishing service ownership. To achieve
27  * ownership of the service group, a service group candidate must hold ownership
28  * of both these entities.
29  *
30  * @param <P> the instance identifier path type
31  * @param <E> the GenericEntity type
32  * @param <C> the GenericEntityOwnershipChange type
33  */
34 interface ClusterSingletonServiceGroup<P extends Path<P>, E extends GenericEntity<P>,
35                                        C extends GenericEntityOwnershipChange<P, E>> {
36
37     /**
38      * This method must be called once on startup to initialize this group and
39      * register the relevant group entity candidate. It means create relevant
40      * Group Entity Candidate Registration.
41      */
42     void initializationClusterSingletonGroup();
43
44     /**
45      * This method registers a service instance for this service group. If the local node has
46      * ownership of the service group, the {@link ClusterSingletonService#instantiateServiceInstance()}
47      * method is called. Otherwise, the method is called once the local node gains ownership.
48      *
49      * @param service instance
50      * @return closable {@link ClusterSingletonServiceRegistration}
51      */
52     ClusterSingletonServiceRegistration registerService(ClusterSingletonService service);
53
54     /**
55      * Method provides possibility to restart some service from group without change
56      * leadership for whole group. {@link ClusterSingletonServiceRegistration#close()}
57      * implementation has to call this service.
58      * Candidates are signed for group, so unregistration for group with one service
59      * has to trigger new election only otherwise we can see same behavior as on server
60      * without clustering.
61      *
62      * @param service instance
63      */
64     void unregisterService(ClusterSingletonService service);
65
66     /**
67      * Method implementation has to apply ownershipChange for all registred services.
68      *
69      * @param ownershipChange change role for ClusterSingletonServiceGroup
70      */
71     void ownershipChanged(final C ownershipChange);
72
73     /**
74      * Closes this service group. All registered service providers are also closed.
75      *
76      * @return {@link ListenableFuture} in list for all Future from closing {@link ClusterSingletonService}
77      */
78     ListenableFuture<List<Void>> closeClusterSingletonGroup();
79
80 }
81