3b2c4598eb2c13f3871750b9a8b7a440c3f7a86c
[policy/drools-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * feature-test-transaction
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.drools.testtransaction;
22
23 import org.onap.policy.drools.features.PolicyControllerFeatureApi;
24 import org.onap.policy.drools.system.PolicyController;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 /**
29  * TestTransactionFeature implements the PolicyControllerFeatureAPI. TestTransactionFeature is the
30  * interface to the TestTransaction feature logic.
31  */
32 public class TestTransactionFeature implements PolicyControllerFeatureApi {
33
34     // get an instance of logger
35     private static final Logger logger = LoggerFactory.getLogger(TestTransactionFeature.class);
36
37     @Override
38     public boolean afterStart(PolicyController controller) {
39
40         logger.info("TEST_TRANSACTION FEATURE LOADED");
41
42         if (controller.isAlive() && !controller.isLocked() && controller.getDrools().isBrained()) {
43             getTestTransMgr().register(controller);
44         }
45         return false;
46     }
47
48     @Override
49     public boolean afterLock(PolicyController controller) {
50         logger.info("controller {} locked", controller.getName());
51
52         getTestTransMgr().unregister(controller);
53         return false;
54     }
55
56     @Override
57     public boolean afterUnlock(PolicyController controller) {
58         logger.info("controller {} unlocked", controller.getName());
59
60         if (controller.isAlive() && !controller.isLocked() && controller.getDrools().isBrained()) {
61             getTestTransMgr().register(controller);
62         }
63
64         return false;
65     }
66
67     @Override
68     public boolean beforeStop(PolicyController controller) {
69         logger.info("controller {} stopping", controller.getName());
70
71         getTestTransMgr().unregister(controller);
72
73         return false;
74     }
75
76     @Override
77     public int getSequenceNumber() {
78         return 1000;
79     }
80
81     /**
82      * Gets the test transaction manager.
83      * @return the test transaction manager
84      */
85     protected TestTransaction getTestTransMgr() {
86         return TestTransaction.manager;
87     }
88 }