Add ExtensibleObject interface 50/80650/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Feb 2019 15:10:14 +0000 (16:10 +0100)
committerRobert Varga <nite@hq.sk>
Thu, 28 Feb 2019 18:50:42 +0000 (18:50 +0000)
This adds the basic ExtensibleObject and ObjectExtension interfaces,
which can be reused to define extensible objects.

Unlike a full-blown implementation, these interfaces provide only
access interface, not a mechanism to perform actual state attachment.

The attachment mechanism will be defined in future, when the need
for it actually arises.

JIRA: YANGTOOLS-497
Change-Id: Ie390b6174b8909c87595dddc0d467858f36ef8bf
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 33e06bd2f202c270f70b99091029cb18afeb792a)

common/concepts/src/main/java/org/opendaylight/yangtools/concepts/ExtensibleObject.java [new file with mode: 0644]
common/concepts/src/main/java/org/opendaylight/yangtools/concepts/ObjectExtension.java [new file with mode: 0644]

diff --git a/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/ExtensibleObject.java b/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/ExtensibleObject.java
new file mode 100644 (file)
index 0000000..2b94aea
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2019 Pantheon Technologies, s.r.o. 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.yangtools.concepts;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.collect.ImmutableClassToInstanceMap;
+import org.eclipse.jdt.annotation.NonNull;
+
+/**
+ * Interface specifying access to extensions attached to a particular object. This functionality is loosely based on
+ * <a href="https://docs.microsoft.com/en-us/dotnet/framework/wcf/extending/extensible-objects">Extensible Object</a>
+ * pattern.
+ *
+ * @param <T> Type of extensible object
+ * @param <E> Extension marker interface
+ * @author Robert Varga
+ */
+@Beta
+public interface ExtensibleObject<T extends ExtensibleObject<T, E>, E extends ObjectExtension<T, E>> {
+    /**
+     * Return a map of currently-supported extensions, along with accessor objects which provide access to the specific
+     * functionality bound to this object.
+     *
+     * @return A map of supported functionality.
+     */
+    default @NonNull ClassToInstanceMap<E> getExtensions() {
+        return ImmutableClassToInstanceMap.of();
+    }
+}
diff --git a/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/ObjectExtension.java b/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/ObjectExtension.java
new file mode 100644 (file)
index 0000000..2da775e
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2019 Pantheon Technologies, s.r.o. 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.yangtools.concepts;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * An extension to a concrete {@link ExtensibleObject}. This is a marker interface to introduce type safety and unlike
+ * full Extensible Objects, does not specify how extensions are attached to an extensible object.
+ *
+ * <p>
+ * {@link ObjectExtension} instances are attached to their host object and share its state, which means they work in
+ * concert and care must be taken to ensure consistency, such as thread safety and observable effects.
+ *
+ * @param <T> Extensible object type
+ * @param <E> Extension type
+ * @author Robert Varga
+ */
+@Beta
+public interface ObjectExtension<T extends ExtensibleObject<T, E>, E extends ObjectExtension<T, E>> {
+
+}