72c54969e7bcc64c50cc59565f52cf362f5ddf25
[policy/drools-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * feature-test-transaction
4  * ================================================================================
5  * Copyright (C) 2017 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  * TestTransactionFeature implements the PolicyControllerFeatureAPI.
29  * TestTransactionFeature is the interface to the TestTransaction feature logic.
30  * 
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() &&
43             !controller.isLocked() && 
44             controller.getDrools().isBrained())
45                 TestTransaction.manager.register(controller);
46         
47         return false;
48     }
49     
50     @Override
51     public boolean afterLock(PolicyController controller) {
52         logger.info("CONTROLLER " + controller.getName() + " LOCKED");
53         
54         TestTransaction.manager.unregister(controller);
55         return false;
56     }
57     
58     @Override
59     public boolean afterUnlock(PolicyController controller) {
60         logger.info("CONTROLLER " + controller.getName() + " UNLOCKED");
61         
62         if (controller.isAlive() &&
63                 !controller.isLocked() && 
64             controller.getDrools().isBrained())
65                 TestTransaction.manager.register(controller);
66         
67         return false;
68     }
69
70     @Override
71     public boolean beforeStop(PolicyController controller) {
72         logger.info("CONTROLLER " + controller.getName() + " ABOUT TO STOP");
73         
74         TestTransaction.manager.unregister(controller);
75         
76         return false;
77     }
78
79     @Override
80     public int getSequenceNumber() {
81         return 1000;
82     }
83 }