Merge "BUG-4117: preparation for FlowCapableNode notification impl."
[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 org.opendaylight.controller.md.sal.common.api.clustering.Entity;
11 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService;
14
15 import javax.annotation.Nonnull;
16
17 /**
18  * Rewrote whole role context to prevent errors to change role on cluster
19  */
20 public interface RoleContext extends  RequestContextStack, AutoCloseable {
21
22     /**
23      * Initialization method is responsible for a registration of
24      * {@link org.opendaylight.controller.md.sal.common.api.clustering.Entity} and listener
25      * for notification from service
26      * {@link org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService}
27      * returns Role which has to be applied for responsible Device Context suite. Any Exception
28      * state has to close Device connection channel.
29      * @return true if initialization done ok
30      */
31     boolean initialization();
32
33     /**
34      * Termination method is responsible for an unregistration of
35      * {@link org.opendaylight.controller.md.sal.common.api.clustering.Entity} and listener
36      * for notification from service
37      * {@link org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService}
38      * returns notification "Someone else take Leadership" or "I'm last"
39      * and we need to clean Oper. DS.
40      */
41     void unregisterAllCandidates();
42
43     /**
44      * Setter for sal role service
45      * @param salRoleService
46      */
47     void setSalRoleService(@Nonnull final SalRoleService salRoleService);
48
49     /**
50      * Getter for sal role service
51      * @return
52      */
53     SalRoleService getSalRoleService();
54
55     /**
56      * Getter for main entity
57      * @return
58      */
59     Entity getEntity();
60
61     /**
62      * Getter for tx entity
63      * @return
64      */
65     Entity getTxEntity();
66
67     /**
68      * Actual nodeId
69      * @return
70      */
71     NodeId getNodeId();
72
73     /**
74      * Returns true if main entity is registered
75      * @return
76      */
77     boolean isMainCandidateRegistered();
78
79     /**
80      * Returns true if tx entity is registered
81      * @return
82      */
83     boolean isTxCandidateRegistered();
84
85     /**
86      * Register candidate depending on parameter
87      * @param entity
88      * @return true is registration was successful
89      */
90     boolean registerCandidate(final Entity entity);
91
92     /**
93      * Unregister candidate depending on parameter
94      * @param entity
95      * @return true is registration was successful
96      */
97     boolean unregisterCandidate(final Entity entity);
98
99     /**
100      * Returns true if we hold both registrations
101      * @return
102      */
103     boolean isMaster();
104
105     @Override
106     void close();
107 }