2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.drools.controller.internal;
23 import com.fasterxml.jackson.annotation.JsonIgnore;
24 import com.fasterxml.jackson.annotation.JsonProperty;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.HashMap;
28 import java.util.List;
30 import java.util.Objects;
31 import java.util.stream.Collectors;
32 import org.apache.commons.collections4.queue.CircularFifoQueue;
33 import org.checkerframework.checker.nullness.qual.NonNull;
34 import org.drools.core.ClassObjectFilter;
35 import org.kie.api.definition.KiePackage;
36 import org.kie.api.definition.rule.Query;
37 import org.kie.api.runtime.KieSession;
38 import org.kie.api.runtime.rule.FactHandle;
39 import org.kie.api.runtime.rule.QueryResults;
40 import org.kie.api.runtime.rule.QueryResultsRow;
41 import org.onap.policy.common.endpoints.event.comm.TopicSink;
42 import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
43 import org.onap.policy.common.gson.annotation.GsonJsonProperty;
44 import org.onap.policy.drools.controller.DroolsController;
45 import org.onap.policy.drools.core.PolicyContainer;
46 import org.onap.policy.drools.core.PolicySession;
47 import org.onap.policy.drools.core.jmx.PdpJmx;
48 import org.onap.policy.drools.features.DroolsControllerFeatureApi;
49 import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
50 import org.onap.policy.drools.protocol.coders.EventProtocolParams;
51 import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
52 import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration;
53 import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder;
54 import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.PotentialCoderFilter;
55 import org.onap.policy.drools.utils.ReflectionUtil;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
60 * Maven-based Drools Controller that interacts with the
61 * policy-core PolicyContainer and PolicySession to manage
62 * Drools containers instantiated using Maven.
64 public class MavenDroolsController implements DroolsController {
69 private static Logger logger = LoggerFactory.getLogger(MavenDroolsController.class);
72 * Policy Container, the access object to the policy-core layer.
76 protected final PolicyContainer policyContainer;
79 * alive status of this drools controller,
80 * reflects invocation of start()/stop() only.
82 protected volatile boolean alive = false;
85 * locked status of this drools controller,
86 * reflects if i/o drools related operations are permitted,
87 * more specifically: offer() and deliver().
88 * It does not affect the ability to start and stop
89 * underlying drools infrastructure
91 protected volatile boolean locked = false;
94 * list of topics, each with associated decoder classes, each
95 * with a list of associated filters.
97 protected List<TopicCoderFilterConfiguration> decoderConfigurations;
100 * list of topics, each with associated encoder classes, each
101 * with a list of associated filters.
103 protected List<TopicCoderFilterConfiguration> encoderConfigurations;
106 * recent source events processed.
108 protected final CircularFifoQueue<Object> recentSourceEvents = new CircularFifoQueue<>(10);
111 * recent sink events processed.
113 protected final CircularFifoQueue<String> recentSinkEvents = new CircularFifoQueue<>(10);
116 * original Drools Model/Rules classloader hash.
118 protected int modelClassLoaderHash;
121 * Expanded version of the constructor.
123 * @param groupId maven group id
124 * @param artifactId maven artifact id
125 * @param version maven version
126 * @param decoderConfigurations list of topic -> decoders -> filters mapping
127 * @param encoderConfigurations list of topic -> encoders -> filters mapping
129 * @throws IllegalArgumentException invalid arguments passed in
131 public MavenDroolsController(String groupId,
134 List<TopicCoderFilterConfiguration> decoderConfigurations,
135 List<TopicCoderFilterConfiguration> encoderConfigurations) {
137 logger.info("drools-controller instantiation [{}:{}:{}]", groupId, artifactId, version);
139 if (groupId == null || groupId.isEmpty()) {
140 throw new IllegalArgumentException("Missing maven group-id coordinate");
143 if (artifactId == null || artifactId.isEmpty()) {
144 throw new IllegalArgumentException("Missing maven artifact-id coordinate");
147 if (version == null || version.isEmpty()) {
148 throw new IllegalArgumentException("Missing maven version coordinate");
151 this.policyContainer = new PolicyContainer(groupId, artifactId, version);
152 this.init(decoderConfigurations, encoderConfigurations);
154 logger.debug("{}: instantiation completed ", this);
158 * init encoding/decoding configuration.
160 * @param decoderConfigurations list of topic -> decoders -> filters mapping
161 * @param encoderConfigurations list of topic -> encoders -> filters mapping
163 protected void init(List<TopicCoderFilterConfiguration> decoderConfigurations,
164 List<TopicCoderFilterConfiguration> encoderConfigurations) {
166 this.decoderConfigurations = decoderConfigurations;
167 this.encoderConfigurations = encoderConfigurations;
169 this.initCoders(decoderConfigurations, true);
170 this.initCoders(encoderConfigurations, false);
172 this.modelClassLoaderHash = this.policyContainer.getClassLoader().hashCode();
176 public void updateToVersion(String newGroupId, String newArtifactId, String newVersion,
177 List<TopicCoderFilterConfiguration> decoderConfigurations,
178 List<TopicCoderFilterConfiguration> encoderConfigurations)
179 throws LinkageError {
181 logger.info("updating version -> [{}:{}:{}]", newGroupId, newArtifactId, newVersion);
183 if (newGroupId == null || newGroupId.isEmpty()) {
184 throw new IllegalArgumentException("Missing maven group-id coordinate");
187 if (newArtifactId == null || newArtifactId.isEmpty()) {
188 throw new IllegalArgumentException("Missing maven artifact-id coordinate");
191 if (newVersion == null || newVersion.isEmpty()) {
192 throw new IllegalArgumentException("Missing maven version coordinate");
195 if (newGroupId.equalsIgnoreCase(DroolsController.NO_GROUP_ID)
196 || newArtifactId.equalsIgnoreCase(DroolsController.NO_ARTIFACT_ID)
197 || newVersion.equalsIgnoreCase(DroolsController.NO_VERSION)) {
198 throw new IllegalArgumentException("BRAINLESS maven coordinates provided: "
199 + newGroupId + ":" + newArtifactId + ":"
203 if (newGroupId.equalsIgnoreCase(this.getGroupId())
204 && newArtifactId.equalsIgnoreCase(this.getArtifactId())
205 && newVersion.equalsIgnoreCase(this.getVersion())) {
206 logger.warn("Al in the right version: " + newGroupId + ":"
207 + newArtifactId + ":" + newVersion + " vs. " + this);
211 if (!newGroupId.equalsIgnoreCase(this.getGroupId())
212 || !newArtifactId.equalsIgnoreCase(this.getArtifactId())) {
213 throw new IllegalArgumentException(
214 "Group ID and Artifact ID maven coordinates must be identical for the upgrade: "
215 + newGroupId + ":" + newArtifactId + ":"
216 + newVersion + " vs. " + this);
220 String messages = this.policyContainer.updateToVersion(newVersion);
221 logger.warn("{} UPGRADE results: {}", this, messages);
224 * If all sucessful (can load new container), now we can remove all coders from previous sessions
231 this.init(decoderConfigurations, encoderConfigurations);
233 logger.info("UPDATE-TO-VERSION: completed {}", this);
237 * initialize decoders for all the topics supported by this controller
238 * Note this is critical to be done after the Policy Container is
239 * instantiated to be able to fetch the corresponding classes.
241 * @param coderConfigurations list of topic -> decoders -> filters mapping
243 protected void initCoders(List<TopicCoderFilterConfiguration> coderConfigurations,
246 logger.info("INIT-CODERS: {}", this);
248 if (coderConfigurations == null) {
253 for (TopicCoderFilterConfiguration coderConfig: coderConfigurations) {
254 String topic = coderConfig.getTopic();
256 CustomGsonCoder customGsonCoder = coderConfig.getCustomGsonCoder();
257 if (coderConfig.getCustomGsonCoder() != null
258 && coderConfig.getCustomGsonCoder().getClassContainer() != null
259 && !coderConfig.getCustomGsonCoder().getClassContainer().isEmpty()) {
261 String customGsonCoderClass = coderConfig.getCustomGsonCoder().getClassContainer();
262 if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(),
263 customGsonCoderClass)) {
264 throw makeRetrieveEx(customGsonCoderClass);
266 if (logger.isInfoEnabled()) {
267 logClassFetched(customGsonCoderClass);
272 List<PotentialCoderFilter> coderFilters = coderConfig.getCoderFilters();
273 if (coderFilters == null || coderFilters.isEmpty()) {
277 for (PotentialCoderFilter coderFilter : coderFilters) {
278 String potentialCodedClass = coderFilter.getCodedClass();
279 JsonProtocolFilter protocolFilter = coderFilter.getFilter();
281 if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(),
282 potentialCodedClass)) {
283 throw makeRetrieveEx(potentialCodedClass);
285 if (logger.isInfoEnabled()) {
286 logClassFetched(potentialCodedClass);
291 EventProtocolCoder.manager.addDecoder(EventProtocolParams.builder()
292 .groupId(this.getGroupId())
293 .artifactId(this.getArtifactId())
295 .eventClass(potentialCodedClass)
296 .protocolFilter(protocolFilter)
297 .customGsonCoder(customGsonCoder)
298 .modelClassLoaderHash(this.policyContainer.getClassLoader().hashCode()));
300 EventProtocolCoder.manager.addEncoder(
301 EventProtocolParams.builder().groupId(this.getGroupId())
302 .artifactId(this.getArtifactId()).topic(topic)
303 .eventClass(potentialCodedClass).protocolFilter(protocolFilter)
304 .customGsonCoder(customGsonCoder)
305 .modelClassLoaderHash(this.policyContainer.getClassLoader().hashCode()));
312 * Logs an error and makes an exception for an item that cannot be retrieved.
313 * @param itemName the item to retrieve
314 * @return a new exception
316 private IllegalArgumentException makeRetrieveEx(String itemName) {
317 logger.error("{} cannot be retrieved", itemName);
318 return new IllegalArgumentException(itemName + " cannot be retrieved");
322 * Logs the name of the class that was fetched.
323 * @param className class name fetched
325 private void logClassFetched(String className) {
326 logger.info("CLASS FETCHED {}", className);
333 protected void removeDecoders() {
334 logger.info("REMOVE-DECODERS: {}", this);
336 if (this.decoderConfigurations == null) {
341 for (TopicCoderFilterConfiguration coderConfig: decoderConfigurations) {
342 String topic = coderConfig.getTopic();
343 EventProtocolCoder.manager.removeDecoders(this.getGroupId(), this.getArtifactId(), topic);
350 protected void removeEncoders() {
352 logger.info("REMOVE-ENCODERS: {}", this);
354 if (this.encoderConfigurations == null) {
358 for (TopicCoderFilterConfiguration coderConfig: encoderConfigurations) {
359 String topic = coderConfig.getTopic();
360 EventProtocolCoder.manager.removeEncoders(this.getGroupId(), this.getArtifactId(), topic);
366 public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) {
367 if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(), coderClass.getName())) {
368 logger.error("{}{} cannot be retrieved. ", this, coderClass.getName());
372 if (modelHash == this.modelClassLoaderHash) {
373 logger.info("{}{} class loader matches original drools controller rules classloader {}",
374 coderClass.getName(), this, coderClass.getClassLoader());
377 logger.warn("{}{} class loaders don't match {} vs {}", this, coderClass.getName(),
378 coderClass.getClassLoader(), this.policyContainer.getClassLoader());
384 public boolean start() {
386 logger.info("START: {}", this);
388 synchronized (this) {
395 return this.policyContainer.start();
399 public boolean stop() {
401 logger.info("STOP: {}", this);
403 synchronized (this) {
410 return this.policyContainer.stop();
414 public void shutdown() {
415 logger.info("{}: SHUTDOWN", this);
420 } catch (Exception e) {
421 logger.error("{} SHUTDOWN FAILED because of {}", this, e.getMessage(), e);
423 this.policyContainer.shutdown();
430 logger.info("{}: HALT", this);
435 } catch (Exception e) {
436 logger.error("{} HALT FAILED because of {}", this, e.getMessage(), e);
438 this.policyContainer.destroy();
443 * removes this drools controllers and encoders and decoders from operation.
445 protected void removeCoders() {
446 logger.info("{}: REMOVE-CODERS", this);
449 this.removeDecoders();
450 } catch (IllegalArgumentException e) {
451 logger.error("{} REMOVE-DECODERS FAILED because of {}", this, e.getMessage(), e);
455 this.removeEncoders();
456 } catch (IllegalArgumentException e) {
457 logger.error("{} REMOVE-ENCODERS FAILED because of {}", this, e.getMessage(), e);
462 public boolean isAlive() {
467 public boolean offer(String topic, String event) {
468 logger.debug("{}: OFFER raw event from {}", this, topic);
470 if (this.locked || !this.alive || this.policyContainer.getPolicySessions().isEmpty()) {
474 // 1. Now, check if this topic has a decoder:
476 if (!EventProtocolCoder.manager.isDecodingSupported(this.getGroupId(),
477 this.getArtifactId(),
480 logger.warn("{}: DECODING-UNSUPPORTED {}:{}:{}", this,
481 topic, this.getGroupId(), this.getArtifactId());
489 anEvent = EventProtocolCoder.manager.decode(this.getGroupId(),
490 this.getArtifactId(),
493 } catch (UnsupportedOperationException uoe) {
494 logger.debug("{}: DECODE FAILED: {} <- {} because of {}", this, topic,
495 event, uoe.getMessage(), uoe);
497 } catch (Exception e) {
498 logger.warn("{}: DECODE FAILED: {} <- {} because of {}", this, topic,
499 event, e.getMessage(), e);
503 return offer(anEvent);
508 public <T> boolean offer(T event) {
509 logger.debug("{}: OFFER event", this);
511 if (this.locked || !this.alive || this.policyContainer.getPolicySessions().isEmpty()) {
515 synchronized (this.recentSourceEvents) {
516 this.recentSourceEvents.add(event);
519 PdpJmx.getInstance().updateOccured();
523 for (DroolsControllerFeatureApi feature : DroolsControllerFeatureApi.providers.getList()) {
525 if (feature.beforeInsert(this, event)) {
528 } catch (Exception e) {
529 logger.error("{}: feature {} before-insert failure because of {}",
530 this, feature.getClass().getName(), e.getMessage(), e);
534 boolean successInject = this.policyContainer.insertAll(event);
535 if (!successInject) {
536 logger.warn(this + "Failed to inject into PolicyContainer {}", this.getSessionNames());
539 for (DroolsControllerFeatureApi feature : DroolsControllerFeatureApi.providers.getList()) {
541 if (feature.afterInsert(this, event, successInject)) {
544 } catch (Exception e) {
545 logger.error("{}: feature {} after-insert failure because of {}",
546 this, feature.getClass().getName(), e.getMessage(), e);
555 public boolean deliver(TopicSink sink, Object event) {
557 logger.info("{}DELIVER: {} FROM {} TO {}", this, event, this, sink);
559 for (DroolsControllerFeatureApi feature : DroolsControllerFeatureApi.providers.getList()) {
561 if (feature.beforeDeliver(this, sink, event)) {
565 catch (Exception e) {
566 logger.error("{}: feature {} before-deliver failure because of {}", this, feature.getClass().getName(),
572 throw new IllegalArgumentException(this + " invalid sink");
576 throw new IllegalArgumentException(this + " invalid event");
580 throw new IllegalStateException(this + " is locked");
584 throw new IllegalStateException(this + " is stopped");
588 EventProtocolCoder.manager.encode(sink.getTopic(), event, this);
590 synchronized (this.recentSinkEvents) {
591 this.recentSinkEvents.add(json);
594 boolean success = sink.send(json);
596 for (DroolsControllerFeatureApi feature : DroolsControllerFeatureApi.providers.getList()) {
598 if (feature.afterDeliver(this, sink, event, json, success)) {
602 catch (Exception e) {
603 logger.error("{}: feature {} after-deliver failure because of {}", this, feature.getClass().getName(),
613 public String getVersion() {
614 return this.policyContainer.getVersion();
618 public String getArtifactId() {
619 return this.policyContainer.getArtifactId();
623 public String getGroupId() {
624 return this.policyContainer.getGroupId();
628 * Get model class loader hash.
630 * @return the modelClassLoaderHash
632 public int getModelClassLoaderHash() {
633 return modelClassLoaderHash;
637 public synchronized boolean lock() {
638 logger.info("LOCK: {}", this);
645 public synchronized boolean unlock() {
646 logger.info("UNLOCK: {}", this);
653 public boolean isLocked() {
660 public PolicyContainer getContainer() {
661 return this.policyContainer;
664 @JsonProperty("sessions")
665 @GsonJsonProperty("sessions")
667 public List<String> getSessionNames() {
668 return getSessionNames(true);
674 * @param abbreviated true for the short form, otherwise the long form
675 * @return session names
677 protected List<String> getSessionNames(boolean abbreviated) {
678 List<String> sessionNames = new ArrayList<>();
680 for (PolicySession session: this.policyContainer.getPolicySessions()) {
682 sessionNames.add(session.getName());
684 sessionNames.add(session.getFullName());
687 } catch (Exception e) {
688 logger.warn("Can't retrieve CORE sessions: " + e.getMessage(), e);
689 sessionNames.add(e.getMessage());
694 @JsonProperty("sessionCoordinates")
695 @GsonJsonProperty("sessionCoordinates")
697 public List<String> getCanonicalSessionNames() {
698 return getSessionNames(false);
702 public List<String> getBaseDomainNames() {
703 return new ArrayList<>(this.policyContainer.getKieContainer().getKieBaseNames());
707 * provides the underlying core layer container sessions.
709 * @return the attached Policy Container
711 protected List<PolicySession> getSessions() {
712 List<PolicySession> sessions = new ArrayList<>();
713 sessions.addAll(this.policyContainer.getPolicySessions());
718 * provides the underlying core layer container session with name sessionName.
720 * @param sessionName session name
721 * @return the attached Policy Container
722 * @throws IllegalArgumentException when an invalid session name is provided
723 * @throws IllegalStateException when the drools controller is in an invalid state
725 protected PolicySession getSession(String sessionName) {
726 if (sessionName == null || sessionName.isEmpty()) {
727 throw new IllegalArgumentException("A Session Name must be provided");
730 List<PolicySession> sessions = this.getSessions();
731 for (PolicySession session : sessions) {
732 if (sessionName.equals(session.getName()) || sessionName.equals(session.getFullName())) {
737 throw invalidSessNameEx(sessionName);
740 private IllegalArgumentException invalidSessNameEx(String sessionName) {
741 return new IllegalArgumentException("Invalid Session Name: " + sessionName);
745 public Map<String,Integer> factClassNames(String sessionName) {
746 if (sessionName == null || sessionName.isEmpty()) {
747 throw invalidSessNameEx(sessionName);
750 Map<String,Integer> classNames = new HashMap<>();
752 PolicySession session = getSession(sessionName);
753 KieSession kieSession = session.getKieSession();
755 Collection<FactHandle> facts = session.getKieSession().getFactHandles();
756 for (FactHandle fact : facts) {
758 String className = kieSession.getObject(fact).getClass().getName();
759 if (classNames.containsKey(className)) {
760 classNames.put(className, classNames.get(className) + 1);
762 classNames.put(className, 1);
764 } catch (Exception e) {
765 logger.warn("Object cannot be retrieved from fact {}", fact, e);
773 public long factCount(String sessionName) {
774 if (sessionName == null || sessionName.isEmpty()) {
775 throw invalidSessNameEx(sessionName);
778 PolicySession session = getSession(sessionName);
779 return session.getKieSession().getFactCount();
783 public List<Object> facts(String sessionName, String className, boolean delete) {
784 if (sessionName == null || sessionName.isEmpty()) {
785 throw invalidSessNameEx(sessionName);
788 if (className == null || className.isEmpty()) {
789 throw new IllegalArgumentException("Invalid Class Name: " + className);
793 ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className);
794 if (factClass == null) {
795 throw new IllegalArgumentException("Class cannot be fetched in model's classloader: " + className);
798 PolicySession session = getSession(sessionName);
799 KieSession kieSession = session.getKieSession();
801 List<Object> factObjects = new ArrayList<>();
803 Collection<FactHandle> factHandles = kieSession.getFactHandles(new ClassObjectFilter(factClass));
804 for (FactHandle factHandle : factHandles) {
806 factObjects.add(kieSession.getObject(factHandle));
808 kieSession.delete(factHandle);
810 } catch (Exception e) {
811 logger.warn("Object cannot be retrieved from fact {}", factHandle, e);
819 public <T> List<T> facts(@NonNull String sessionName, @NonNull Class<T> clazz) {
820 return facts(sessionName, clazz.getName(), false)
822 .filter(clazz::isInstance)
824 .collect(Collectors.toList());
828 public List<Object> factQuery(String sessionName, String queryName, String queriedEntity,
829 boolean delete, Object... queryParams) {
830 if (sessionName == null || sessionName.isEmpty()) {
831 throw invalidSessNameEx(sessionName);
834 if (queryName == null || queryName.isEmpty()) {
835 throw new IllegalArgumentException("Invalid Query Name: " + queryName);
838 if (queriedEntity == null || queriedEntity.isEmpty()) {
839 throw new IllegalArgumentException("Invalid Queried Entity: " + queriedEntity);
842 PolicySession session = getSession(sessionName);
843 KieSession kieSession = session.getKieSession();
845 boolean found = false;
846 for (KiePackage kiePackage : kieSession.getKieBase().getKiePackages()) {
847 for (Query q : kiePackage.getQueries()) {
848 if (q.getName() != null && q.getName().equals(queryName)) {
855 throw new IllegalArgumentException("Invalid Query Name: " + queryName);
858 List<Object> factObjects = new ArrayList<>();
860 QueryResults queryResults = kieSession.getQueryResults(queryName, queryParams);
861 for (QueryResultsRow row : queryResults) {
863 factObjects.add(row.get(queriedEntity));
865 kieSession.delete(row.getFactHandle(queriedEntity));
867 } catch (Exception e) {
868 logger.warn("Object cannot be retrieved from row: {}", row, e);
876 public <T> boolean delete(@NonNull String sessionName, @NonNull T fact) {
877 String factClassName = fact.getClass().getName();
879 PolicySession session = getSession(sessionName);
880 KieSession kieSession = session.getKieSession();
882 Collection<FactHandle> factHandles = kieSession.getFactHandles(new ClassObjectFilter(fact.getClass()));
883 for (FactHandle factHandle : factHandles) {
885 if (Objects.equals(fact, kieSession.getObject(factHandle))) {
886 logger.info("Deleting {} from {}", factClassName, sessionName);
887 kieSession.delete(factHandle);
890 } catch (Exception e) {
891 logger.warn("Object cannot be retrieved from fact {}", factHandle, e);
898 public <T> boolean delete(@NonNull T fact) {
899 return this.getSessionNames().stream().map((ss) -> delete(ss, fact)).reduce(false, Boolean::logicalOr);
903 public <T> boolean delete(@NonNull String sessionName, @NonNull Class<T> fact) {
904 PolicySession session = getSession(sessionName);
905 KieSession kieSession = session.getKieSession();
907 boolean success = true;
908 Collection<FactHandle> factHandles = kieSession.getFactHandles(new ClassObjectFilter(fact));
909 for (FactHandle factHandle : factHandles) {
911 kieSession.delete(factHandle);
912 } catch (Exception e) {
913 logger.warn("Object cannot be retrieved from fact {}", factHandle, e);
921 public <T> boolean delete(@NonNull Class<T> fact) {
922 return this.getSessionNames().stream().map((ss) -> delete(ss, fact)).reduce(false, Boolean::logicalOr);
927 public Class<?> fetchModelClass(String className) {
928 return ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className);
932 * Get recent source events.
934 * @return the recentSourceEvents
937 public Object[] getRecentSourceEvents() {
938 synchronized (this.recentSourceEvents) {
939 Object[] events = new Object[recentSourceEvents.size()];
940 return recentSourceEvents.toArray(events);
945 * Get recent sink events.
947 * @return the recentSinkEvents
950 public String[] getRecentSinkEvents() {
951 synchronized (this.recentSinkEvents) {
952 String[] events = new String[recentSinkEvents.size()];
953 return recentSinkEvents.toArray(events);
958 public boolean isBrained() {
964 public String toString() {
965 StringBuilder builder = new StringBuilder();
967 .append("MavenDroolsController [policyContainer=")
968 .append((policyContainer != null) ? policyContainer.getName() : "NULL")
973 .append(", modelClassLoaderHash=")
974 .append(modelClassLoaderHash)
976 return builder.toString();