Disconnection improvements.
[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.RejectedExecutionException;
13 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
14 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
15 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
16 import org.opendaylight.openflowplugin.api.openflow.device.handlers.ClusterInitializationPhaseHandler;
17 import org.opendaylight.openflowplugin.api.openflow.device.handlers.ClusterLifecycleSupervisor;
18
19 /**
20  * General API for all OFP Context.
21  */
22 public interface OFPContext extends AutoCloseable, ClusterLifecycleSupervisor, ClusterInitializationPhaseHandler {
23
24
25     String MESSAGE = "Cannot stop abstract services, check implementation of cluster services";
26
27     /**
28      * Replace actual connection.
29      * @param connectionContext new connection
30      */
31     default void replaceConnection(final ConnectionContext connectionContext) {
32         //Nothing to do
33     }
34
35     /**
36      * Context state.
37      */
38     enum CONTEXT_STATE {
39         /* Initialization phase, context not yet fully initialized */
40         INITIALIZATION,
41         /* Standard working phase everything is fine */
42         WORKING,
43         /* Termination phase context is being shutting down */
44         TERMINATION
45     }
46
47     /**
48      * Get actual context state.
49      * @return actual context state
50      */
51     CONTEXT_STATE getState();
52
53     /**
54      * About to stop services in cluster not master anymore or going down.
55      * @return Future most of services need time to be closed.
56      * @param connectionInterrupted true if clustering services stopping by device disconnect.
57      */
58     default ListenableFuture<Void> stopClusterServices(boolean connectionInterrupted) {
59         return Futures.immediateFailedFuture(
60                 new RejectedExecutionException(MESSAGE));
61     }
62
63     /**
64      * About to stop services in cluster not master anymore or going down.
65      * @return Future most of services need time to be closed.
66      */
67     default ListenableFuture<Void> stopClusterServices() {
68         return stopClusterServices(false);
69     }
70
71     /**
72      * Get cluster singleton service identifier.
73      * @return cluster singleton service identifier.
74      */
75     ServiceGroupIdentifier getServiceIdentifier();
76
77     /**
78      * Get device info.
79      * @return device info
80      */
81     DeviceInfo getDeviceInfo();
82
83     @Override
84     void close();
85 }