Add common entity ownership interfaces
[mdsal.git] / common / mdsal-common-api / src / main / java / org / opendaylight / mdsal / common / api / clustering / GenericEntityOwnershipChange.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.mdsal.common.api.clustering;
9
10 import com.google.common.base.Preconditions;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.yangtools.concepts.Path;
13
14 /**
15  * A DTO that encapsulates an ownership change for an entity.
16  *
17  * @author Thomas Pantelis
18  *
19  * @param <P> the instance identifier path type
20  * @param <E> the GenericEntity type
21  */
22 public class GenericEntityOwnershipChange<P extends Path<P>, E extends GenericEntity<P>> {
23     private final E entity;
24     private final EntityOwnershipChangeState state;
25
26     public GenericEntityOwnershipChange(@Nonnull E entity, @Nonnull EntityOwnershipChangeState state) {
27         this.entity = Preconditions.checkNotNull(entity, "entity can't be null");
28         this.state = Preconditions.checkNotNull(state, "state can't be null");
29     }
30
31     /**
32      * Returns the entity whose ownership status changed.
33      * @return the entity
34      */
35     @Nonnull public E getEntity() {
36         return entity;
37     }
38
39     /**
40      * Returns the ownership change state.
41      * @return an EntityOwnershipChangeState enum
42      */
43     @Nonnull public EntityOwnershipChangeState getState() {
44         return state;
45     }
46
47     @Override
48     public String toString() {
49         return getClass().getSimpleName() + " [entity=" + entity + ", state=" + state + "]";
50     }
51 }