455686783f0200a276fd9f3efff9d11f4681a9dc
[policy/drools-pdp.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
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.controller.internal;
22
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import org.onap.policy.common.endpoints.event.comm.TopicSink;
29 import org.onap.policy.drools.controller.DroolsController;
30 import org.onap.policy.drools.core.PolicyContainer;
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 List<String> getBaseDomainNames() {
105         return Collections.emptyList();
106     }
107
108     @Override
109     public boolean offer(String topic, String event) {
110         return false;
111     }
112
113     @Override
114     public boolean deliver(TopicSink sink, Object event) {
115         throw new IllegalStateException(makeInvokeMsg());
116     }
117
118     @Override
119     public Object[] getRecentSourceEvents() {
120         return new String[0];
121     }
122
123     @Override
124     public PolicyContainer getContainer() {
125         return null;
126     }
127
128     @Override
129     public String[] getRecentSinkEvents() {
130         return new String[0];
131     }
132
133     @Override
134     public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) {
135         throw new IllegalStateException(makeInvokeMsg());
136     }
137
138     @Override
139     public Class<?> fetchModelClass(String className) {
140         throw new IllegalArgumentException(makeInvokeMsg());
141     }
142
143     @Override
144     public boolean isBrained() {
145         return false;
146     }
147
148     @Override
149     public String toString() {
150         StringBuilder builder = new StringBuilder();
151         builder.append("NullDroolsController []");
152         return builder.toString();
153     }
154
155     @Override
156     public void updateToVersion(String newGroupId, String newArtifactId, String newVersion,
157             List<TopicCoderFilterConfiguration> decoderConfigurations,
158             List<TopicCoderFilterConfiguration> encoderConfigurations)
159                     throws LinkageError {
160         throw new IllegalArgumentException(makeInvokeMsg());
161     }
162
163     @Override
164     public Map<String, Integer> factClassNames(String sessionName) {
165         return new HashMap<>();
166     }
167
168     @Override
169     public long factCount(String sessionName) {
170         return 0;
171     }
172
173     @Override
174     public List<Object> facts(String sessionName, String className, boolean delete) {
175         return new ArrayList<>();
176     }
177
178     @Override
179     public List<Object> factQuery(String sessionName, String queryName, 
180             String queriedEntity, 
181             boolean delete, Object... queryParams) {
182         return new ArrayList<>();
183     }
184
185     private String makeInvokeMsg() {
186         return this.getClass().getCanonicalName() + " invoked";
187     }
188 }