Bug 4105: Add public EntityOwnershipService interface
[controller.git] / opendaylight / md-sal / sal-common-api / src / main / java / org / opendaylight / controller / md / sal / common / api / clustering / CandidateAlreadyRegisteredException.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.Preconditions;
12 import javax.annotation.Nonnull;
13
14 /**
15  * Thrown when a Candidate has already been registered for a given Entity. This could be due to a component doing a
16  * duplicate registration or two different components within the same process trying to register a Candidate.
17  */
18 public class CandidateAlreadyRegisteredException extends Exception {
19     private final Entity entity;
20     private final EntityOwnershipCandidate registeredCandidate;
21
22     public CandidateAlreadyRegisteredException(@Nonnull Entity entity,
23                                                @Nonnull EntityOwnershipCandidate registeredCandidate,
24                                                String message) {
25         super(message);
26         this.entity = Preconditions.checkNotNull(entity, "entity should not be null");
27         this.registeredCandidate = Preconditions.checkNotNull(registeredCandidate,
28                 "registeredCandidate should not be null");
29     }
30
31     public CandidateAlreadyRegisteredException(@Nonnull Entity entity,
32                                                @Nonnull EntityOwnershipCandidate registeredCandidate,
33                                                String message, Throwable throwable) {
34         super(message, throwable);
35         this.entity = Preconditions.checkNotNull(entity, "entity should not be null");
36         this.registeredCandidate = Preconditions.checkNotNull(registeredCandidate,
37                 "registeredCandidate should not be null");
38     }
39
40     /**
41      *
42      * @return the entity for which a Candidate has already been registered in the current process
43      */
44     @Nonnull
45     public Entity getEntity() {
46         return entity;
47     }
48
49     /**
50      *
51      * @return the currently registered candidate
52      */
53     @Nonnull
54     public EntityOwnershipCandidate getRegisteredCandidate() {
55         return registeredCandidate;
56     }
57 }