Merge "Bug-4957: Double candidate, introduced roleCtx states"
[openflowplugin.git] / openflowplugin-api / src / main / java / org / opendaylight / openflowplugin / api / openflow / role / RoleContext.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.role;
9
10 import java.util.concurrent.Future;
11 import org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException;
12 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
13 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
15
16 /**
17  * Created by kramesha on 9/12/15.
18  */
19 public interface RoleContext extends RoleChangeListener, RequestContextStack {
20
21     void setTxLockOwned(boolean txLockOwned);
22
23     void promoteStateToWorking();
24
25     OfpRole getPropagatingRole();
26
27     void setPropagatingRole(OfpRole propagatingRole);
28
29     /** available states the {@link RoleContext} can exist in */
30     enum ROLE_CONTEXT_STATE {
31         /**
32          * before consequences of first entity ownership election are completely settled
33          * (lock acquired, data written, role propagated onto device)
34          */
35         STARTING,
36         /**
37          * state between
38          * <ul>
39          * <li>first entity ownership election settled</li>
40          * <li>and device disconnected or {@link DeviceContext#close()} invoked</li>
41          * </ul>
42          */
43         WORKING,
44         /** after {@link DeviceContext#close()} invoked */
45         TEARING_DOWN
46     }
47
48     /**
49      * Initialization method is responsible for a registration of
50      * {@link org.opendaylight.controller.md.sal.common.api.clustering.Entity}
51      * and listen for notification from service. {@link Future} returned object is used primary
52      * for new connection initialization phase where we have to wait for actual Role.
53      * The {@link Future} has to be canceled if device is in disconnected state or when
54      * {@link org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService} returns
55      * {@link org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException}
56      */
57     void initialization() throws CandidateAlreadyRegisteredException;
58
59     /**
60      * Transaction Candidate will provide safe way to correctly finish TxChainManager from
61      * last Node Master. It means only Master of TxEntity could hold TxChainFactory and
62      * active TransactionChain to write Data to Distributed DataStore.
63      */
64     void setupTxCandidate() throws CandidateAlreadyRegisteredException;
65
66     /**
67      * UnregistrationTxCandidate from OwnershipService
68      */
69     void suspendTxCandidate();
70
71     @Override
72     void close();
73
74     DeviceContext getDeviceContext();
75
76     ROLE_CONTEXT_STATE getState();
77
78     boolean isTxLockOwned();
79 }