Encapsulate OpenFlowPlugin configuration
[openflowplugin.git] / openflowplugin-api / src / main / java / org / opendaylight / openflowplugin / api / openflow / lifecycle / ContextChain.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. 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.lifecycle;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
13 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
14 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
15
16 /**
17  * Chain of contexts, hold references to the contexts.
18  */
19 public interface ContextChain extends AutoCloseable {
20
21     /**
22      * Add context to the chain, if reference already exist ignore it.
23      * @param context child of OFPContext
24      */
25     <T extends OFPContext> void addContext(T context);
26
27     void addLifecycleService(LifecycleService lifecycleService);
28
29     /**
30      * Stop the working contexts, but not release them.
31      * @return Future
32      */
33     ListenableFuture<Void> stopChain();
34
35     @Override
36     void close();
37
38     /**
39      * Method need to be called if connection is dropped to stop the chain.
40      * @return future
41      */
42     ListenableFuture<Void> connectionDropped();
43
44     /**
45      * Slave was successfully set.
46      */
47     void makeContextChainStateSlave();
48
49     /**
50      * Registers context chain into cluster singleton service.
51      * @param clusterSingletonServiceProvider provider
52      */
53     void registerServices(ClusterSingletonServiceProvider clusterSingletonServiceProvider);
54
55     /**
56      * After connect of device make this device SLAVE.
57      */
58     void makeDeviceSlave();
59
60     /**
61      * Check all needed to be master.
62      * @param mastershipState - state master on device, initial gather, initial submit, initial registry fill
63      * @return true if everything done fine
64      */
65     boolean isMastered(@Nonnull ContextChainMastershipState mastershipState);
66
67     /**
68      * Add new auxiliary connection if primary is ok.
69      * @param connectionContext new connection to the device.
70      * @return false if primary connection is broken
71      */
72     boolean addAuxiliaryConnection(@Nonnull ConnectionContext connectionContext);
73
74     /**
75      * Check if connection is auxiliary and if yes then continue working.
76      * @param connectionContext connection to the device
77      * @return false if this is primary connection
78      */
79     boolean auxiliaryConnectionDropped(@Nonnull ConnectionContext connectionContext);
80 }