245b0b58251e9772e391428212185afd54bd64b5
[policy/drools-pdp.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-management
4  * ================================================================================
5  * Copyright (C) 2017-2018 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.controller.internal;
22
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27
28 import org.onap.policy.drools.controller.DroolsController;
29 import org.onap.policy.drools.core.PolicyContainer;
30 import org.onap.policy.drools.event.comm.TopicSink;
31 import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration;
32
33 /**
34  * no-op Drools Controller
35  */
36 public class NullDroolsController implements DroolsController {
37
38         @Override
39         public boolean start() {
40                 return false;
41         }
42
43         @Override
44         public boolean stop() {
45                 return false;
46         }
47
48         @Override
49         public void shutdown() {
50                 return;
51         }
52         
53         @Override
54         public void halt() {
55                 return;
56         }
57
58         @Override
59         public boolean isAlive() {
60                 return false;
61         }
62
63         @Override
64         public boolean lock() {
65                 return false;
66         }
67
68         @Override
69         public boolean unlock() {
70                 return false;
71         }
72
73         @Override
74         public boolean isLocked() {
75                 return false;
76         }
77
78         @Override
79         public String getGroupId() {
80                 return NO_GROUP_ID;
81         }
82
83         @Override
84         public String getArtifactId() {
85                 return NO_ARTIFACT_ID;
86         }
87
88         @Override
89         public String getVersion() {
90                 return NO_VERSION;
91         }       
92
93         @Override
94         public List<String> getSessionNames() {
95                 return new ArrayList<>();
96         }
97
98         @Override
99         public List<String> getCanonicalSessionNames() {
100                 return new ArrayList<>();
101         }
102
103         @Override
104         public boolean offer(String topic, String event) {
105                 return false;
106         }
107
108         @Override
109         public boolean deliver(TopicSink sink, Object event) {
110                 throw new IllegalStateException(makeInvokeMsg());
111         }
112
113         @Override
114         public Object[] getRecentSourceEvents() {
115                 return new String[0];
116         }
117         
118         @Override
119         public PolicyContainer getContainer() {
120                 return null;
121         }
122
123         @Override
124         public String[] getRecentSinkEvents() {
125                 return new String[0];
126         }
127
128         @Override
129         public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) {
130                 throw new IllegalStateException(makeInvokeMsg());
131         }
132
133         @Override
134         public Class<?> fetchModelClass(String className) {
135                 throw new IllegalArgumentException(makeInvokeMsg());
136         }
137         
138         @Override
139         public boolean isBrained() {
140                 return false;
141         }
142         
143         @Override
144         public String toString() {
145                 StringBuilder builder = new StringBuilder();
146                 builder.append("NullDroolsController []");
147                 return builder.toString();
148         }
149
150         @Override
151         public void updateToVersion(String newGroupId, String newArtifactId, String newVersion,
152                         List<TopicCoderFilterConfiguration> decoderConfigurations,
153                         List<TopicCoderFilterConfiguration> encoderConfigurations)
154                         throws LinkageError {
155                 throw new IllegalArgumentException(makeInvokeMsg());
156         }
157
158         @Override
159         public Map<String, Integer> factClassNames(String sessionName) {
160                 return new HashMap<>();
161         }
162
163         @Override
164         public long factCount(String sessionName) {
165                 return 0;
166         }
167
168         @Override
169         public List<Object> facts(String sessionName, String className, boolean delete) {
170                 return new ArrayList<>();
171         }
172
173         @Override
174         public List<Object> factQuery(String sessionName, String queryName, 
175                                               String queriedEntity, 
176                                               boolean delete, Object... queryParams) {
177                 return new ArrayList<>();
178         }
179
180         private String makeInvokeMsg() {
181                 return this.getClass().getCanonicalName() + " invoked";
182         }
183 }