2 * Copyright (c) 2015 Brocade Communications 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
8 package org.opendaylight.mdsal.eos.common.api;
10 import com.google.common.base.Optional;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.yangtools.concepts.Path;
16 * An interface that 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.
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.
25 * @author Thomas Pantelis
27 * @param <P> the instance identifier path type
28 * @param <E> the GenericEntity type
30 public interface GenericEntityOwnershipService<P extends Path<P>, E extends GenericEntity<P>,
31 L extends GenericEntityOwnershipListener<P, ? extends GenericEntityOwnershipChange<P, E>>> {
34 * Registers a candidate for ownership of the given entity. Only one such request can be made per entity
35 * per process. If multiple requests for registering a candidate for a given entity are received in the
36 * current process a CandidateAlreadyRegisteredException will be thrown.
38 * The registration is performed asynchronously and any registered entity ownership listener is
39 * notified of ownership status changes for the entity.
41 * @param entity the entity which the Candidate wants to own
42 * @return a registration object that can be used to unregister the Candidate
43 * @throws CandidateAlreadyRegisteredException if the candidate was already registered
45 GenericEntityOwnershipCandidateRegistration<P, E> registerCandidate(@Nonnull E entity)
46 throws CandidateAlreadyRegisteredException;
49 * Registers a listener that is interested in ownership changes for entities of the given entity type. The
50 * listener is notified whenever its process instance is granted ownership of the entity and also whenever
51 * it loses ownership. On registration the listener will be notified of all entities its process instance
52 * currently owns at the time of registration.
54 * @param entityType the type of entities whose ownership status the Listener is interested in
55 * @param listener the listener that is interested in the entities
56 * @return a registration object that can be used to unregister the Listener
58 GenericEntityOwnershipListenerRegistration<P, L> registerListener(@Nonnull String entityType, @Nonnull L listener);
61 * Gets the current ownership state information for an entity.
63 * @param forEntity the entity to query.
64 * @return an Optional EntityOwnershipState whose instance is present if the entity is found
66 Optional<EntityOwnershipState> getOwnershipState(@Nonnull E forEntity);
69 * Checks if a local candidate is registered for the given entity.
71 * @param forEntity the entity to query.
72 * @return true if a candidate is registered locally, false otherwise
74 boolean isCandidateRegistered(@Nonnull E forEntity);