Bug 4105: Add hasOwner param to EntityOwnershipListener#ownershipChanged
[controller.git] / opendaylight / md-sal / sal-common-api / src / main / java / org / opendaylight / controller / md / sal / common / api / clustering / EntityOwnershipChange.java
1 /*
2  * Copyright (c) 2015 Brocade Communications 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 package org.opendaylight.controller.md.sal.common.api.clustering;
9
10 import com.google.common.base.Preconditions;
11 import javax.annotation.Nonnull;
12
13 /**
14  * A DTO that encapsulates an ownership change for an entity.
15  *
16  * @author Thomas Pantelis
17  */
18 public class EntityOwnershipChange {
19     private final Entity entity;
20     private final boolean wasOwner;
21     private final boolean isOwner;
22     private final boolean hasOwner;
23
24     public EntityOwnershipChange(@Nonnull Entity entity, boolean wasOwner, boolean isOwner, boolean hasOwner) {
25         this.entity = Preconditions.checkNotNull(entity, "entity can't be null");
26         this.wasOwner = wasOwner;
27         this.isOwner = isOwner;
28         this.hasOwner = hasOwner;
29     }
30
31     /**
32      * Returns the entity whose ownership status changed.
33      * @return the entity
34      */
35     @Nonnull public Entity getEntity() {
36         return entity;
37     }
38
39     /**
40      * Returns the previous ownership status of the entity for this process instance.
41      * @return true if this process was the owner of the entity at the time this notification was generated
42      */
43     public boolean wasOwner() {
44         return wasOwner;
45     }
46
47     /**
48      * Returns the current ownership status of the entity for this process instance.
49      * @return true if this process is now the owner of the entity
50      */
51     public boolean isOwner() {
52         return isOwner;
53     }
54
55     /**
56      * Returns the current ownership status of the entity across all process instances.
57      * @return true if the entity has an owner which may or may not be this process. If false, then
58      *         the entity has no candidates and thus no owner.
59      */
60     public boolean hasOwner() {
61         return hasOwner;
62     }
63
64     @Override
65     public String toString() {
66         return "EntityOwnershipChanged [entity=" + entity + ", wasOwner=" + wasOwner + ", isOwner=" + isOwner
67                 + ", hasOwner=" + hasOwner + "]";
68     }
69 }