2 * Copyright (c) 2015 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.controller.md.sal.common.api.clustering;
11 import com.google.common.base.Optional;
12 import javax.annotation.Nonnull;
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.
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 public interface EntityOwnershipService {
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.
32 * The registration is performed asynchronously and any registered {@link EntityOwnershipListener} is
33 * notified of ownership status changes for the entity.
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
39 EntityOwnershipCandidateRegistration registerCandidate(@Nonnull Entity entity)
40 throws CandidateAlreadyRegisteredException;
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.
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
52 EntityOwnershipListenerRegistration registerListener(@Nonnull String entityType, @Nonnull EntityOwnershipListener listener);
55 * Gets the current ownership state information for an entity.
57 * @param forEntity the entity to query.
58 * @return an Optional EntityOwnershipState whose instance is present if the entity is found
60 Optional<EntityOwnershipState> getOwnershipState(@Nonnull Entity forEntity);