<artifactId>org.osgi.core</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<scm>
<connection>scm:git:http://git.opendaylight.org/gerrit/controller.git</connection>
--- /dev/null
+/*
+ * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.api.clustering;
+
+import com.google.common.annotations.Beta;
+import javax.annotation.Nonnull;
+import org.opendaylight.mdsal.common.api.clustering.GenericEntity;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Binding version of {@link GenericEntity}.
+ *
+ * @author Thomas Pantelis
+ */
+@Beta
+public class Entity extends GenericEntity<InstanceIdentifier<?>> {
+ private static final long serialVersionUID = 1L;
+
+ /** Constructs an instance.
+ *
+ * @param type the entity type
+ * @param id the entity id.
+ */
+ public Entity(@Nonnull final String type, @Nonnull final InstanceIdentifier<?> id) {
+ super(type, id);
+ }
+
+ /**
+ * Construct an Entity with an with a name. The general-entity schema is used to construct the
+ * InstanceIdentifier.
+ *
+ * @param type the type of the entity
+ * @param entityName the name of the entity used to construct a general-entity InstanceIdentifier
+ */
+ // FIXME: needs to be enabled in a follow-up
+// public Entity(@Nonnull String type, @Nonnull String entityName) {
+// super(type, InstanceIdentifier.builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.
+// ns.yang.controller.md.sal.core.general.entity.rev150820.Entity.class,
+// new EntityKey(Preconditions.checkNotNull(entityName, "entityName should not be null"))).build());
+// }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.api.clustering;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.mdsal.common.api.clustering.GenericEntityOwnershipCandidateRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Binding version of {@link GenericEntityOwnershipCandidateRegistration}.
+ *
+ * @author Thomas Pantelis
+ */
+@Beta
+public interface EntityOwnershipCandidateRegistration extends
+ GenericEntityOwnershipCandidateRegistration<InstanceIdentifier<?>, Entity> {
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.api.clustering;
+
+import com.google.common.annotations.Beta;
+import javax.annotation.Nonnull;
+import org.opendaylight.mdsal.common.api.clustering.EntityOwnershipChangeState;
+import org.opendaylight.mdsal.common.api.clustering.GenericEntityOwnershipChange;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Binding version of {@link GenericEntityOwnershipChange}.
+ *
+ * @author Thomas Pantelis
+ */
+@Beta
+public class EntityOwnershipChange extends GenericEntityOwnershipChange<InstanceIdentifier<?>, Entity> {
+
+ /**
+ * {@inheritDoc}
+ */
+ public EntityOwnershipChange(@Nonnull final Entity entity, @Nonnull final EntityOwnershipChangeState state) {
+ super(entity, state);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.api.clustering;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.mdsal.common.api.clustering.GenericEntityOwnershipListener;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Binding interface for GenericEntityOwnershipListener.
+ *
+ * @author Thomas Pantelis
+ */
+@Beta
+public interface EntityOwnershipListener extends
+ GenericEntityOwnershipListener<InstanceIdentifier<?>, EntityOwnershipChange> {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ void ownershipChanged(EntityOwnershipChange ownershipChange);
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.api.clustering;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.mdsal.common.api.clustering.GenericEntityOwnershipListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Binding interface for GenericEntityOwnershipCandidateRegistration.
+ *
+ * @author Thomas Pantelis
+ */
+@Beta
+public interface EntityOwnershipListenerRegistration extends
+ GenericEntityOwnershipListenerRegistration<InstanceIdentifier<?>, EntityOwnershipListener> {
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.api.clustering;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Optional;
+import javax.annotation.Nonnull;
+import org.opendaylight.mdsal.common.api.clustering.CandidateAlreadyRegisteredException;
+import org.opendaylight.mdsal.common.api.clustering.EntityOwnershipState;
+import org.opendaylight.mdsal.common.api.clustering.GenericEntityOwnershipService;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Binding version of {@link GenericEntityOwnershipService}.
+ *
+ * @author Thomas Pantelis
+ */
+@Beta
+public interface EntityOwnershipService extends
+ GenericEntityOwnershipService<InstanceIdentifier<?>, Entity, EntityOwnershipListener> {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ EntityOwnershipCandidateRegistration registerCandidate(@Nonnull Entity entity)
+ throws CandidateAlreadyRegisteredException;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ EntityOwnershipListenerRegistration registerListener(@Nonnull String entityType,
+ @Nonnull EntityOwnershipListener listener);
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ Optional<EntityOwnershipState> getOwnershipState(@Nonnull Entity forEntity);
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.api.clustering;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import org.apache.commons.lang3.SerializationUtils;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Unit tests for Entity.
+ *
+ * @author Thomas Pantelis
+ */
+public class EntityTest {
+ static String ENTITY_TYPE1 = "type1";
+ static String ENTITY_TYPE2 = "type2";
+ static final InstanceIdentifier<TestDataObject1> ID1 = InstanceIdentifier.create(TestDataObject1.class);
+ static final InstanceIdentifier<TestDataObject2> ID2 = InstanceIdentifier.create(TestDataObject2.class);
+
+ @Test
+ public void testHashCode() {
+ Entity entity1 = new Entity(ENTITY_TYPE1, ID1);
+
+ assertEquals("hashCode", entity1.hashCode(), new Entity(ENTITY_TYPE1, ID1).hashCode());
+ assertNotEquals("hashCode", entity1.hashCode(), new Entity(ENTITY_TYPE2, ID2).hashCode());
+ }
+
+ static class TestDataObject1 implements DataObject {
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return null;
+ }
+ }
+
+ @Test
+ public void testEquals() {
+ Entity entity1 = new Entity(ENTITY_TYPE1, ID1);
+
+ assertEquals("Same", true, entity1.equals(entity1));
+ assertEquals("Same", true, entity1.equals(new Entity(ENTITY_TYPE1, ID1)));
+ assertEquals("Different entity type", false, entity1.equals(new Entity(ENTITY_TYPE2, ID1)));
+ assertEquals("Different yang ID", false, entity1.equals(new Entity(ENTITY_TYPE1, ID2)));
+ assertEquals("Different Object", false, entity1.equals(new Object()));
+ assertEquals("Equals null", false, entity1.equals(null));
+ }
+
+ @Test
+ public void testSerialization() {
+ Entity entity = new Entity(ENTITY_TYPE1, ID1);
+
+ Entity clone = SerializationUtils.clone(entity);
+
+ assertEquals("getType", entity.getType(), clone.getType());
+ assertEquals("getId", entity.getIdentifier(), clone.getIdentifier());
+ }
+
+ static class TestDataObject2 implements DataObject {
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return null;
+ }
+ }
+}