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.common.api.clustering;
10 import com.google.common.base.Preconditions;
11 import java.io.Serializable;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.yangtools.concepts.Identifiable;
14 import org.opendaylight.yangtools.concepts.Path;
17 * A clustered Entity is something which is shared by multiple applications across a cluster. An Entity has a type
20 * The type describes the type of the Entity where examples of a type maybe "openflow" or "netconf"
21 * etc. An Entity type could be tied to how exactly an application shares and "owns" an entity. For example we may want
22 * an application which deals with the openflow entity to be assigned ownership of that entity based on a first come
23 * first served basis. On the other hand for netconf entity types we may want applications to gain ownership based on
24 * a load balancing approach. While this mechanism of assigning a ownership acquisition strategy is not finalized the
25 * intention is that the entity type will play a role in determining the strategy and thus should be put in place.
27 * The identifier is an instance identifier path. The reason for the choice of instance identifier path is because it
28 * can easily be used to represent a data node. For example an inventory node represents a shared entity and it is best
29 * referenced by its instance identifier path if the inventory node is stored in the data store.
31 * Note that an entity identifier must conform to a valid yang schema. If there is no existing yang schema to
32 * represent an entity, the general-entity yang model can be used.
35 * @author Thomas Pantelis
37 * @param <T> the entity identifier type
39 public class GenericEntity<T extends Path<T>> implements Serializable, Identifiable<T> {
40 private static final long serialVersionUID = 1L;
42 private final String type;
45 protected GenericEntity(@Nonnull String type, @Nonnull T id) {
46 this.type = Preconditions.checkNotNull(type, "type should not be null");
47 this.id = Preconditions.checkNotNull(id, "id should not be null");
51 * @return the id of entity.
55 public final T getIdentifier() {
60 * @return the type of entity.
63 public final String getType(){
67 @SuppressWarnings("unchecked")
69 public boolean equals(Object o) {
74 if (o == null || getClass() != o.getClass()) {
78 GenericEntity<T> entity = (GenericEntity<T>) o;
80 if (!id.equals(entity.id)) {
84 if (!type.equals(entity.type)) {
92 public int hashCode() {
93 return 31 * type.hashCode() + id.hashCode();
97 public String toString() {
98 return getClass().getSimpleName() + " [type=" + type + ", id=" + id + "]";