Bug 5421 - Single cluster-wide service API
[mdsal.git] / singleton-service / mdsal-singleton-common-api / src / main / java / org / opendaylight / mdsal / singleton / common / api / ClusterSingletonService.java
diff --git a/singleton-service/mdsal-singleton-common-api/src/main/java/org/opendaylight/mdsal/singleton/common/api/ClusterSingletonService.java b/singleton-service/mdsal-singleton-common-api/src/main/java/org/opendaylight/mdsal/singleton/common/api/ClusterSingletonService.java
new file mode 100644 (file)
index 0000000..2329f8b
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016 Cisco 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.singleton.common.api;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.yangtools.concepts.Identifiable;
+
+/**
+ * {@link ClusterSingletonService} interface represents a single cluster service instance. It has to implement
+ * every service (RPCs or Applications) which would like to be instantiated on same Cluster Node. Grouping is
+ * realized by ServiceGroupIdentifier. Servicies with same ServiceGroupIdentifier have to run on same Cluster
+ * Node. ServiceGroupIdentifier must not change during whole {@link ClusterSingletonService} lifecycle.
+ */
+public interface ClusterSingletonService extends Identifiable<ServiceGroupIdentifier> {
+
+    /**
+     * This method is invoked to instantiate an underlying service instance when
+     * ownership has been granted for the service entity.
+     */
+    void instantiateServiceInstance();
+
+    /**
+     * This method is invoked to close the underlying service instance when ownership has been lost
+     * for the service entity. If the act of closing the instance may perform blocking operations or
+     * take some time, it should be done asynchronously to avoid blocking the current thread.
+     *
+     * @return a ListenableFuture that is completed when the underlying instance close operation is complete.
+     */
+    ListenableFuture<Void> closeServiceInstance();
+
+}