BUG 4615 : Add method on EOS to check if a candidate is registered locally
[controller.git] / opendaylight / md-sal / sal-common-api / src / main / java / org / opendaylight / controller / md / sal / common / api / clustering / EntityOwnershipService.java
1 /*
2  * Copyright (c) 2015 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.controller.md.sal.common.api.clustering;
10
11 import com.google.common.base.Optional;
12 import javax.annotation.Nonnull;
13
14 /**
15  * <p>
16  * The EntityOwnershipService provides the means for a component/application to request ownership for a given
17  * Entity on the current cluster member. Entity ownership is always tied to a process and two components on the same
18  * process cannot register a candidate for a given Entity.
19  * </p>
20  * <p>
21  * A component/application may also register interest in the ownership status of an Entity. The listener would be
22  * notified whenever the ownership status changes.
23  * </p>
24  */
25 public interface EntityOwnershipService {
26
27     /**
28      * Registers a candidate for ownership of the given entity. Only one such request can be made per entity
29      * per process. If multiple requests for registering a candidate for a given entity are received in the
30      * current process a CandidateAlreadyRegisteredException will be thrown.
31      * <p>
32      * The registration is performed asynchronously and any registered {@link EntityOwnershipListener} is
33      * notified of ownership status changes for the entity.
34      *
35      * @param entity the entity which the Candidate wants to own
36      * @return a registration object that can be used to unregister the Candidate
37      * @throws org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException
38      */
39     EntityOwnershipCandidateRegistration registerCandidate(@Nonnull Entity entity)
40             throws CandidateAlreadyRegisteredException;
41
42     /**
43      * Registers a listener that is interested in ownership changes for entities of the given entity type. The
44      * listener is notified whenever its process instance is granted ownership of the entity and also whenever
45      * it loses ownership. On registration the listener will be notified of all entities its process instance
46      * currently owns at the time of registration.
47      *
48      * @param entityType the type of entities whose ownership status the Listener is interested in
49      * @param listener the listener that is interested in the entities
50      * @return a registration object that can be used to unregister the Listener
51      */
52     EntityOwnershipListenerRegistration registerListener(@Nonnull String entityType, @Nonnull EntityOwnershipListener listener);
53
54     /**
55      * Gets the current ownership state information for an entity.
56      *
57      * @param forEntity the entity to query.
58      * @return an Optional EntityOwnershipState whose instance is present if the entity is found
59      */
60     Optional<EntityOwnershipState> getOwnershipState(@Nonnull Entity forEntity);
61
62     /**
63      * Check if a local candidate is registered for the given entity
64      *
65      * @param entity
66      * @return true if a candidate was registered locally, false otherwise
67      */
68     boolean isCandidateRegistered(@Nonnull Entity entity);
69 }