Add common entity ownership interfaces
[mdsal.git] / common / mdsal-common-api / src / main / java / org / opendaylight / mdsal / common / api / clustering / EntityOwnershipState.java
diff --git a/common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/clustering/EntityOwnershipState.java b/common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/clustering/EntityOwnershipState.java
new file mode 100644 (file)
index 0000000..fcd7d84
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.common.api.clustering;
+
+/**
+ * Enumerates the current ownership state for an entity.
+ *
+ * @author Thomas Pantelis
+ */
+public enum EntityOwnershipState {
+    /**
+     * The local process instance is the owner of the entity.
+     */
+    IS_OWNER,
+
+    /**
+     * A remote process instance is the owner of the entity.
+     */
+    OWNED_BY_OTHER,
+
+    /**
+     * The entity has no owner and thus no candidates.
+     */
+    NO_OWNER;
+
+    public static EntityOwnershipState from(boolean isOwner, boolean hasOwner) {
+        if(isOwner) {
+            return IS_OWNER;
+        } else if(hasOwner) {
+            return OWNED_BY_OTHER;
+        } else {
+            return NO_OWNER;
+        }
+    }
+}