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