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.mdsal.singleton.common.api;
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;
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.
30 * @param <P> the instance identifier path type
31 * @param <E> the GenericEntity type
32 * @param <C> the GenericEntityOwnershipChange type
34 interface ClusterSingletonServiceGroup<P extends Path<P>, E extends GenericEntity<P>,
35 C extends GenericEntityOwnershipChange<P, E>> {
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.
42 void initializationClusterSingletonGroup();
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.
49 * @param service instance
50 * @return closable {@link ClusterSingletonServiceRegistration}
52 ClusterSingletonServiceRegistration registerService(ClusterSingletonService service);
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
62 * @param service instance
64 void unregisterService(ClusterSingletonService service);
67 * Method implementation has to apply ownershipChange for all registred services.
69 * @param ownershipChange change role for ClusterSingletonServiceGroup
71 void ownershipChanged(final C ownershipChange);
74 * Closes this service group. All registered service providers are also closed.
76 * @return {@link ListenableFuture} in list for all Future from closing {@link ClusterSingletonService}
78 ListenableFuture<List<Void>> closeClusterSingletonGroup();