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.eos.common.api;
10 import static java.util.Objects.requireNonNull;
12 import java.io.Serializable;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.concepts.Identifiable;
15 import org.opendaylight.yangtools.concepts.Path;
18 * A clustered Entity is something which is shared by multiple applications across a cluster. An Entity has a type
22 * The type describes the type of the Entity where examples of a type maybe "openflow" or "netconf"
23 * etc. An Entity type could be tied to how exactly an application shares and "owns" an entity. For example we may want
24 * an application which deals with the openflow entity to be assigned ownership of that entity based on a first come
25 * first served basis. On the other hand for netconf entity types we may want applications to gain ownership based on
26 * a load balancing approach. While this mechanism of assigning a ownership acquisition strategy is not finalized the
27 * intention is that the entity type will play a role in determining the strategy and thus should be put in place.
30 * The identifier is an instance identifier path. The reason for the choice of instance identifier path is because it
31 * can easily be used to represent a data node. For example an inventory node represents a shared entity and it is best
32 * referenced by its instance identifier path if the inventory node is stored in the data store.
35 * Note that an entity identifier must conform to a valid yang schema. If there is no existing yang schema to
36 * represent an entity, the general-entity yang model can be used.
40 * @author Thomas Pantelis
42 * @param <T> the entity identifier type
44 public class GenericEntity<T extends Path<T>> implements Serializable, Identifiable<T> {
45 private static final long serialVersionUID = 1L;
47 private final @NonNull String type;
48 private final @NonNull T id;
50 protected GenericEntity(@NonNull final String type, @NonNull final T id) {
51 this.type = requireNonNull(type, "type should not be null");
52 this.id = requireNonNull(id, "id should not be null");
56 * Gets the id of the entity.
60 public final @NonNull T getIdentifier() {
65 * Gets the type of the entity.
68 public final @NonNull String getType() {
73 public boolean equals(final Object obj) {
77 if (obj == null || getClass() != obj.getClass()) {
80 final GenericEntity<?> entity = (GenericEntity<?>) obj;
81 return id.equals(entity.id) && type.equals(entity.type);
85 public int hashCode() {
86 return 31 * type.hashCode() + id.hashCode();
90 public String toString() {
91 return getClass().getSimpleName() + " [type=" + type + ", id=" + id + "]";