58368c3618b52f014b407bfef3443fb80244a8ea
[mdsal.git] / singleton-service / mdsal-singleton-common-api / src / main / java / org / opendaylight / mdsal / singleton / common / api / ClusterSingletonService.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.singleton.common.api;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import org.opendaylight.yangtools.concepts.Identifiable;
12
13 /**
14  * {@link ClusterSingletonService} interface represents a single cluster service instance. It has to implement
15  * every service (RPCs or Applications) which would like to be instantiated on same Cluster Node. Grouping is
16  * realized by ServiceGroupIdentifier. Servicies with same ServiceGroupIdentifier have to run on same Cluster
17  * Node. ServiceGroupIdentifier must not change during whole {@link ClusterSingletonService} lifecycle.
18  */
19 public interface ClusterSingletonService extends Identifiable<ServiceGroupIdentifier> {
20
21     /**
22      * This method is invoked to instantiate an underlying service instance when
23      * ownership has been granted for the service entity.
24      */
25     void instantiateServiceInstance();
26
27     /**
28      * This method is invoked to close the underlying service instance when ownership has been lost
29      * for the service entity. If the act of closing the instance may perform blocking operations or
30      * take some time, it should be done asynchronously to avoid blocking the current thread.
31      *
32      * @return a ListenableFuture that is completed when the underlying instance close operation is complete.
33      */
34     ListenableFuture<? extends Object> closeServiceInstance();
35 }