0840568efb23f2d88d3b6aa015e42d9b2783adea
[openflowplugin.git] / openflowplugin-api / src / main / java / org / opendaylight / openflowplugin / api / openflow / OFPContext.java
1 /*
2  * Copyright (c) 2015 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.openflowplugin.api.openflow;
9
10 import com.google.common.util.concurrent.Futures;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.concurrent.ExecutionException;
13 import java.util.concurrent.RejectedExecutionException;
14 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
15 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
16
17 /**
18  * General API for all OFP Context
19  */
20 public interface OFPContext {
21
22     void setState(CONTEXT_STATE contextState);
23
24     /**
25      * Context state
26      */
27     enum CONTEXT_STATE {
28         /* Initialization phase, context not yet fully initialized */
29         INITIALIZATION,
30         /* Standard working phase everything is fine */
31         WORKING,
32         /* Termination phase context is being shutting down */
33         TERMINATION
34     }
35
36     /**
37      * @return actual context state
38      */
39     CONTEXT_STATE getState();
40
41     /**
42      * Starting cluster services for context becoming master
43      */
44     default void startupClusterServices() throws ExecutionException, InterruptedException {
45         throw new InterruptedException("Cannot start abstract service, check implementation of cluster services");
46     }
47
48     /**
49      * About to stop services in cluster not master anymore or going down
50      * @return Future most of services need time to be closed
51      */
52     default ListenableFuture<Void> stopClusterServices(){
53         return Futures.immediateFailedFuture(new RejectedExecutionException("Cannot stop abstract services, check implementation of cluster services"));
54     }
55
56     /**
57      * @return cluster singleton service identifier
58      */
59     ServiceGroupIdentifier getServiceIdentifier();
60
61     /**
62      * @return device info
63      */
64     DeviceInfo getDeviceInfo();
65
66 }