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.common.utils.services.OrderedServiceImpl;
45 import org.onap.policy.drools.controller.DroolsController;
46 import org.onap.policy.drools.core.PolicyContainer;
47 import org.onap.policy.drools.core.PolicySession;
48 import org.onap.policy.drools.core.jmx.PdpJmx;
49 import org.onap.policy.drools.features.DroolsControllerFeatureApi;
50 import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
51 import org.onap.policy.drools.protocol.coders.EventProtocolParams;
52 import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
53 import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration;
54 import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder;
55 import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.PotentialCoderFilter;
56 import org.onap.policy.drools.utils.ReflectionUtil;
57 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory;
61 * Maven-based Drools Controller that interacts with the
62 * policy-core PolicyContainer and PolicySession to manage
63 * Drools containers instantiated using Maven.
65 public class MavenDroolsController implements DroolsController {
70 private static Logger logger = LoggerFactory.getLogger(MavenDroolsController.class);
73 * Policy Container, the access object to the policy-core layer.
77 protected final PolicyContainer policyContainer;
80 * alive status of this drools controller,
81 * reflects invocation of start()/stop() only.
83 protected volatile boolean alive = false;
86 * locked status of this drools controller,
87 * reflects if i/o drools related operations are permitted,
88 * more specifically: offer() and deliver().
89 * It does not affect the ability to start and stop
90 * underlying drools infrastructure
92 protected volatile boolean locked = false;
95 * list of topics, each with associated decoder classes, each
96 * with a list of associated filters.
98 protected List<TopicCoderFilterConfiguration> decoderConfigurations;
101 * list of topics, each with associated encoder classes, each
102 * with a list of associated filters.
104 protected List<TopicCoderFilterConfiguration> encoderConfigurations;
107 * recent source events processed.
109 protected final CircularFifoQueue<Object> recentSourceEvents = new CircularFifoQueue<>(10);
112 * recent sink events processed.
114 protected final CircularFifoQueue<String> recentSinkEvents = new CircularFifoQueue<>(10);
117 * original Drools Model/Rules classloader hash.
119 protected int modelClassLoaderHash;
122 * Expanded version of the constructor.
124 * @param groupId maven group id
125 * @param artifactId maven artifact id
126 * @param version maven version
127 * @param decoderConfigurations list of topic -> decoders -> filters mapping
128 * @param encoderConfigurations list of topic -> encoders -> filters mapping
130 * @throws IllegalArgumentException invalid arguments passed in
132 public MavenDroolsController(String groupId,
135 List<TopicCoderFilterConfiguration> decoderConfigurations,
136 List<TopicCoderFilterConfiguration> encoderConfigurations) {
138 logger.info("drools-controller instantiation [{}:{}:{}]", groupId, artifactId, version);
140 if (groupId == null || groupId.isEmpty()) {
141 throw new IllegalArgumentException("Missing maven group-id coordinate");
144 if (artifactId == null || artifactId.isEmpty()) {
145 throw new IllegalArgumentException("Missing maven artifact-id coordinate");
148 if (version == null || version.isEmpty()) {
149 throw new IllegalArgumentException("Missing maven version coordinate");
152 this.policyContainer = makePolicyContainer(groupId, artifactId, version);
153 this.init(decoderConfigurations, encoderConfigurations);
155 logger.debug("{}: instantiation completed ", this);
159 * init encoding/decoding configuration.
161 * @param decoderConfigurations list of topic -> decoders -> filters mapping
162 * @param encoderConfigurations list of topic -> encoders -> filters mapping
164 protected void init(List<TopicCoderFilterConfiguration> decoderConfigurations,
165 List<TopicCoderFilterConfiguration> encoderConfigurations) {
167 this.decoderConfigurations = decoderConfigurations;
168 this.encoderConfigurations = encoderConfigurations;
170 this.initCoders(decoderConfigurations, true);
171 this.initCoders(encoderConfigurations, false);
173 this.modelClassLoaderHash = this.policyContainer.getClassLoader().hashCode();
177 public void updateToVersion(String newGroupId, String newArtifactId, String newVersion,
178 List<TopicCoderFilterConfiguration> decoderConfigurations,
179 List<TopicCoderFilterConfiguration> encoderConfigurations)
180 throws LinkageError {
182 logger.info("updating version -> [{}:{}:{}]", newGroupId, newArtifactId, newVersion);
184 if (newGroupId == null || newGroupId.isEmpty()) {
185 throw new IllegalArgumentException("Missing maven group-id coordinate");
188 if (newArtifactId == null || newArtifactId.isEmpty()) {
189 throw new IllegalArgumentException("Missing maven artifact-id coordinate");
192 if (newVersion == null || newVersion.isEmpty()) {
193 throw new IllegalArgumentException("Missing maven version coordinate");
196 if (newGroupId.equalsIgnoreCase(DroolsController.NO_GROUP_ID)
197 || newArtifactId.equalsIgnoreCase(DroolsController.NO_ARTIFACT_ID)
198 || newVersion.equalsIgnoreCase(DroolsController.NO_VERSION)) {
199 throw new IllegalArgumentException("BRAINLESS maven coordinates provided: "
200 + newGroupId + ":" + newArtifactId + ":"
204 if (newGroupId.equalsIgnoreCase(this.getGroupId())
205 && newArtifactId.equalsIgnoreCase(this.getArtifactId())
206 && newVersion.equalsIgnoreCase(this.getVersion())) {
207 logger.warn("All in the right version: " + newGroupId + ":"
208 + newArtifactId + ":" + newVersion + " vs. " + this);
212 if (!newGroupId.equalsIgnoreCase(this.getGroupId())
213 || !newArtifactId.equalsIgnoreCase(this.getArtifactId())) {
214 throw new IllegalArgumentException(
215 "Group ID and Artifact ID maven coordinates must be identical for the upgrade: "
216 + newGroupId + ":" + newArtifactId + ":"
217 + newVersion + " vs. " + this);
221 String messages = this.policyContainer.updateToVersion(newVersion);
222 logger.warn("{} UPGRADE results: {}", this, messages);
225 * If all sucessful (can load new container), now we can remove all coders from previous sessions
232 this.init(decoderConfigurations, encoderConfigurations);
234 logger.info("UPDATE-TO-VERSION: completed {}", this);
238 * initialize decoders for all the topics supported by this controller
239 * Note this is critical to be done after the Policy Container is
240 * instantiated to be able to fetch the corresponding classes.
242 * @param coderConfigurations list of topic -> decoders -> filters mapping
244 protected void initCoders(List<TopicCoderFilterConfiguration> coderConfigurations,
247 logger.info("INIT-CODERS: {}", this);
249 if (coderConfigurations == null) {
254 for (TopicCoderFilterConfiguration coderConfig: coderConfigurations) {
255 String topic = coderConfig.getTopic();
257 CustomGsonCoder customGsonCoder = coderConfig.getCustomGsonCoder();
258 if (customGsonCoder != null
259 && customGsonCoder.getClassContainer() != null
260 && !customGsonCoder.getClassContainer().isEmpty()) {
262 String customGsonCoderClass = customGsonCoder.getClassContainer();
263 if (!isClass(customGsonCoderClass)) {
264 throw makeRetrieveEx(customGsonCoderClass);
266 logClassFetched(customGsonCoderClass);
270 List<PotentialCoderFilter> coderFilters = coderConfig.getCoderFilters();
271 if (coderFilters == null || coderFilters.isEmpty()) {
275 for (PotentialCoderFilter coderFilter : coderFilters) {
276 String potentialCodedClass = coderFilter.getCodedClass();
277 JsonProtocolFilter protocolFilter = coderFilter.getFilter();
279 if (!isClass(potentialCodedClass)) {
280 throw makeRetrieveEx(potentialCodedClass);
282 logClassFetched(potentialCodedClass);
286 getCoderManager().addDecoder(EventProtocolParams.builder()
287 .groupId(this.getGroupId())
288 .artifactId(this.getArtifactId())
290 .eventClass(potentialCodedClass)
291 .protocolFilter(protocolFilter)
292 .customGsonCoder(customGsonCoder)
293 .modelClassLoaderHash(this.policyContainer.getClassLoader().hashCode()));
295 getCoderManager().addEncoder(
296 EventProtocolParams.builder().groupId(this.getGroupId())
297 .artifactId(this.getArtifactId()).topic(topic)
298 .eventClass(potentialCodedClass).protocolFilter(protocolFilter)
299 .customGsonCoder(customGsonCoder)
300 .modelClassLoaderHash(this.policyContainer.getClassLoader().hashCode()));
307 * Logs an error and makes an exception for an item that cannot be retrieved.
308 * @param itemName the item to retrieve
309 * @return a new exception
311 private IllegalArgumentException makeRetrieveEx(String itemName) {
312 logger.error("{} cannot be retrieved", itemName);
313 return new IllegalArgumentException(itemName + " cannot be retrieved");
317 * Logs the name of the class that was fetched.
318 * @param className class name fetched
320 private void logClassFetched(String className) {
321 logger.info("CLASS FETCHED {}", className);
328 protected void removeDecoders() {
329 logger.info("REMOVE-DECODERS: {}", this);
331 if (this.decoderConfigurations == null) {
336 for (TopicCoderFilterConfiguration coderConfig: decoderConfigurations) {
337 String topic = coderConfig.getTopic();
338 getCoderManager().removeDecoders(this.getGroupId(), this.getArtifactId(), topic);
345 protected void removeEncoders() {
347 logger.info("REMOVE-ENCODERS: {}", this);
349 if (this.encoderConfigurations == null) {
353 for (TopicCoderFilterConfiguration coderConfig: encoderConfigurations) {
354 String topic = coderConfig.getTopic();
355 getCoderManager().removeEncoders(this.getGroupId(), this.getArtifactId(), topic);
361 public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) {
362 if (!isClass(coderClass.getName())) {
363 logger.error("{}{} cannot be retrieved. ", this, coderClass.getName());
367 if (modelHash == this.modelClassLoaderHash) {
368 logger.info("{}{} class loader matches original drools controller rules classloader {}",
369 coderClass.getName(), this, coderClass.getClassLoader());
372 logger.warn("{}{} class loaders don't match {} vs {}", this, coderClass.getName(),
373 coderClass.getClassLoader(), this.policyContainer.getClassLoader());
379 public boolean start() {
381 logger.info("START: {}", this);
383 synchronized (this) {
390 return this.policyContainer.start();
394 public boolean stop() {
396 logger.info("STOP: {}", this);
398 synchronized (this) {
405 return this.policyContainer.stop();
409 public void shutdown() {
410 logger.info("{}: SHUTDOWN", this);
415 } catch (Exception e) {
416 logger.error("{} SHUTDOWN FAILED because of {}", this, e.getMessage(), e);
418 this.policyContainer.shutdown();
425 logger.info("{}: HALT", this);
430 } catch (Exception e) {
431 logger.error("{} HALT FAILED because of {}", this, e.getMessage(), e);
433 this.policyContainer.destroy();
438 * removes this drools controllers and encoders and decoders from operation.
440 protected void removeCoders() {
441 logger.info("{}: REMOVE-CODERS", this);
444 this.removeDecoders();
445 } catch (IllegalArgumentException e) {
446 logger.error("{} REMOVE-DECODERS FAILED because of {}", this, e.getMessage(), e);
450 this.removeEncoders();
451 } catch (IllegalArgumentException e) {
452 logger.error("{} REMOVE-ENCODERS FAILED because of {}", this, e.getMessage(), e);
457 public boolean isAlive() {
462 public boolean offer(String topic, String event) {
463 logger.debug("{}: OFFER raw event from {}", this, topic);
465 if (this.locked || !this.alive || this.policyContainer.getPolicySessions().isEmpty()) {
469 // 1. Now, check if this topic has a decoder:
471 if (!getCoderManager().isDecodingSupported(this.getGroupId(),
472 this.getArtifactId(),
475 logger.warn("{}: DECODING-UNSUPPORTED {}:{}:{}", this,
476 topic, this.getGroupId(), this.getArtifactId());
484 anEvent = getCoderManager().decode(this.getGroupId(),
485 this.getArtifactId(),
488 } catch (UnsupportedOperationException uoe) {
489 logger.debug("{}: DECODE FAILED: {} <- {} because of {}", this, topic,
490 event, uoe.getMessage(), uoe);
492 } catch (Exception e) {
493 logger.warn("{}: DECODE FAILED: {} <- {} because of {}", this, topic,
494 event, e.getMessage(), e);
498 return offer(anEvent);
503 public <T> boolean offer(T event) {
504 logger.debug("{}: OFFER event", this);
506 if (this.locked || !this.alive || this.policyContainer.getPolicySessions().isEmpty()) {
510 synchronized (this.recentSourceEvents) {
511 this.recentSourceEvents.add(event);
514 PdpJmx.getInstance().updateOccured();
518 for (DroolsControllerFeatureApi feature : getDroolsProviders().getList()) {
520 if (feature.beforeInsert(this, event)) {
523 } catch (Exception e) {
524 logger.error("{}: feature {} before-insert failure because of {}",
525 this, feature.getClass().getName(), e.getMessage(), e);
529 boolean successInject = this.policyContainer.insertAll(event);
530 if (!successInject) {
531 logger.warn(this + "Failed to inject into PolicyContainer {}", this.getSessionNames());
534 for (DroolsControllerFeatureApi feature : getDroolsProviders().getList()) {
536 if (feature.afterInsert(this, event, successInject)) {
539 } catch (Exception e) {
540 logger.error("{}: feature {} after-insert failure because of {}",
541 this, feature.getClass().getName(), e.getMessage(), e);
550 public boolean deliver(TopicSink sink, Object event) {
552 logger.info("{}DELIVER: {} FROM {} TO {}", this, event, this, sink);
554 for (DroolsControllerFeatureApi feature : getDroolsProviders().getList()) {
556 if (feature.beforeDeliver(this, sink, event)) {
560 catch (Exception e) {
561 logger.error("{}: feature {} before-deliver failure because of {}", this, feature.getClass().getName(),
567 throw new IllegalArgumentException(this + " invalid sink");
571 throw new IllegalArgumentException(this + " invalid event");
575 throw new IllegalStateException(this + " is locked");
579 throw new IllegalStateException(this + " is stopped");
583 getCoderManager().encode(sink.getTopic(), event, this);
585 synchronized (this.recentSinkEvents) {
586 this.recentSinkEvents.add(json);
589 boolean success = sink.send(json);
591 for (DroolsControllerFeatureApi feature : getDroolsProviders().getList()) {
593 if (feature.afterDeliver(this, sink, event, json, success)) {
597 catch (Exception e) {
598 logger.error("{}: feature {} after-deliver failure because of {}", this, feature.getClass().getName(),
608 public String getVersion() {
609 return this.policyContainer.getVersion();
613 public String getArtifactId() {
614 return this.policyContainer.getArtifactId();
618 public String getGroupId() {
619 return this.policyContainer.getGroupId();
623 * Get model class loader hash.
625 * @return the modelClassLoaderHash
627 public int getModelClassLoaderHash() {
628 return modelClassLoaderHash;
632 public synchronized boolean lock() {
633 logger.info("LOCK: {}", this);
640 public synchronized boolean unlock() {
641 logger.info("UNLOCK: {}", this);
648 public boolean isLocked() {
655 public PolicyContainer getContainer() {
656 return this.policyContainer;
659 @JsonProperty("sessions")
660 @GsonJsonProperty("sessions")
662 public List<String> getSessionNames() {
663 return getSessionNames(true);
669 * @param abbreviated true for the short form, otherwise the long form
670 * @return session names
672 protected List<String> getSessionNames(boolean abbreviated) {
673 List<String> sessionNames = new ArrayList<>();
675 for (PolicySession session: this.policyContainer.getPolicySessions()) {
677 sessionNames.add(session.getName());
679 sessionNames.add(session.getFullName());
682 } catch (Exception e) {
683 logger.warn("Can't retrieve CORE sessions: " + e.getMessage(), e);
684 sessionNames.add(e.getMessage());
689 @JsonProperty("sessionCoordinates")
690 @GsonJsonProperty("sessionCoordinates")
692 public List<String> getCanonicalSessionNames() {
693 return getSessionNames(false);
697 public List<String> getBaseDomainNames() {
698 return new ArrayList<>(this.policyContainer.getKieContainer().getKieBaseNames());
702 * provides the underlying core layer container sessions.
704 * @return the attached Policy Container
706 protected List<PolicySession> getSessions() {
707 List<PolicySession> sessions = new ArrayList<>();
708 sessions.addAll(this.policyContainer.getPolicySessions());
713 * provides the underlying core layer container session with name sessionName.
715 * @param sessionName session name
716 * @return the attached Policy Container
717 * @throws IllegalArgumentException when an invalid session name is provided
718 * @throws IllegalStateException when the drools controller is in an invalid state
720 protected PolicySession getSession(String sessionName) {
721 if (sessionName == null || sessionName.isEmpty()) {
722 throw new IllegalArgumentException("A Session Name must be provided");
725 List<PolicySession> sessions = this.getSessions();
726 for (PolicySession session : sessions) {
727 if (sessionName.equals(session.getName()) || sessionName.equals(session.getFullName())) {
732 throw invalidSessNameEx(sessionName);
735 private IllegalArgumentException invalidSessNameEx(String sessionName) {
736 return new IllegalArgumentException("Invalid Session Name: " + sessionName);
740 public Map<String,Integer> factClassNames(String sessionName) {
741 validateSessionName(sessionName);
743 Map<String,Integer> classNames = new HashMap<>();
745 PolicySession session = getSession(sessionName);
746 KieSession kieSession = session.getKieSession();
748 Collection<FactHandle> facts = kieSession.getFactHandles();
749 for (FactHandle fact : facts) {
751 String className = kieSession.getObject(fact).getClass().getName();
752 if (classNames.containsKey(className)) {
753 classNames.put(className, classNames.get(className) + 1);
755 classNames.put(className, 1);
757 } catch (Exception e) {
758 logger.warn("Object cannot be retrieved from fact {}", fact, e);
765 private void validateSessionName(String sessionName) {
766 if (sessionName == null || sessionName.isEmpty()) {
767 throw invalidSessNameEx(sessionName);
772 public long factCount(String sessionName) {
773 validateSessionName(sessionName);
775 PolicySession session = getSession(sessionName);
776 return session.getKieSession().getFactCount();
780 public List<Object> facts(String sessionName, String className, boolean delete) {
781 validateSessionName(sessionName);
783 if (className == null || className.isEmpty()) {
784 throw new IllegalArgumentException("Invalid Class Name: " + className);
788 ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className);
789 if (factClass == null) {
790 throw new IllegalArgumentException("Class cannot be fetched in model's classloader: " + className);
793 PolicySession session = getSession(sessionName);
794 KieSession kieSession = session.getKieSession();
796 List<Object> factObjects = new ArrayList<>();
798 Collection<FactHandle> factHandles = kieSession.getFactHandles(new ClassObjectFilter(factClass));
799 for (FactHandle factHandle : factHandles) {
801 factObjects.add(kieSession.getObject(factHandle));
803 kieSession.delete(factHandle);
805 } catch (Exception e) {
806 logger.warn("Object cannot be retrieved from fact {}", factHandle, e);
814 public <T> List<T> facts(@NonNull String sessionName, @NonNull Class<T> clazz) {
815 return facts(sessionName, clazz.getName(), false)
817 .filter(clazz::isInstance)
819 .collect(Collectors.toList());
823 public List<Object> factQuery(String sessionName, String queryName, String queriedEntity,
824 boolean delete, Object... queryParams) {
825 validateSessionName(sessionName);
827 if (queryName == null || queryName.isEmpty()) {
828 throw new IllegalArgumentException("Invalid Query Name: " + queryName);
831 if (queriedEntity == null || queriedEntity.isEmpty()) {
832 throw new IllegalArgumentException("Invalid Queried Entity: " + queriedEntity);
835 PolicySession session = getSession(sessionName);
836 KieSession kieSession = session.getKieSession();
838 boolean found = false;
839 for (KiePackage kiePackage : kieSession.getKieBase().getKiePackages()) {
840 for (Query q : kiePackage.getQueries()) {
841 if (q.getName() != null && q.getName().equals(queryName)) {
848 throw new IllegalArgumentException("Invalid Query Name: " + queryName);
851 List<Object> factObjects = new ArrayList<>();
853 QueryResults queryResults = kieSession.getQueryResults(queryName, queryParams);
854 for (QueryResultsRow row : queryResults) {
856 factObjects.add(row.get(queriedEntity));
858 kieSession.delete(row.getFactHandle(queriedEntity));
860 } catch (Exception e) {
861 logger.warn("Object cannot be retrieved from row: {}", row, e);
869 public <T> boolean delete(@NonNull String sessionName, @NonNull T fact) {
870 String factClassName = fact.getClass().getName();
872 PolicySession session = getSession(sessionName);
873 KieSession kieSession = session.getKieSession();
875 Collection<FactHandle> factHandles = kieSession.getFactHandles(new ClassObjectFilter(fact.getClass()));
876 for (FactHandle factHandle : factHandles) {
878 if (Objects.equals(fact, kieSession.getObject(factHandle))) {
879 logger.info("Deleting {} from {}", factClassName, sessionName);
880 kieSession.delete(factHandle);
883 } catch (Exception e) {
884 logger.warn("Object cannot be retrieved from fact {}", factHandle, e);
891 public <T> boolean delete(@NonNull T fact) {
892 return this.getSessionNames().stream().map((ss) -> delete(ss, fact)).reduce(false, Boolean::logicalOr);
896 public <T> boolean delete(@NonNull String sessionName, @NonNull Class<T> fact) {
897 PolicySession session = getSession(sessionName);
898 KieSession kieSession = session.getKieSession();
900 boolean success = true;
901 Collection<FactHandle> factHandles = kieSession.getFactHandles(new ClassObjectFilter(fact));
902 for (FactHandle factHandle : factHandles) {
904 kieSession.delete(factHandle);
905 } catch (Exception e) {
906 logger.warn("Object cannot be retrieved from fact {}", factHandle, e);
914 public <T> boolean delete(@NonNull Class<T> fact) {
915 return this.getSessionNames().stream().map((ss) -> delete(ss, fact)).reduce(false, Boolean::logicalOr);
920 public Class<?> fetchModelClass(String className) {
921 return ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className);
925 * Get recent source events.
927 * @return the recentSourceEvents
930 public Object[] getRecentSourceEvents() {
931 synchronized (this.recentSourceEvents) {
932 Object[] events = new Object[recentSourceEvents.size()];
933 return recentSourceEvents.toArray(events);
938 * Get recent sink events.
940 * @return the recentSinkEvents
943 public String[] getRecentSinkEvents() {
944 synchronized (this.recentSinkEvents) {
945 String[] events = new String[recentSinkEvents.size()];
946 return recentSinkEvents.toArray(events);
951 public boolean isBrained() {
957 public String toString() {
958 StringBuilder builder = new StringBuilder();
960 .append("MavenDroolsController [policyContainer=")
961 .append(policyContainer.getName())
966 .append(", modelClassLoaderHash=")
967 .append(modelClassLoaderHash)
969 return builder.toString();
972 // these may be overridden by junit tests
974 protected EventProtocolCoder getCoderManager() {
975 return EventProtocolCoder.manager;
978 protected OrderedServiceImpl<DroolsControllerFeatureApi> getDroolsProviders() {
979 return DroolsControllerFeatureApi.providers;
982 protected PolicyContainer makePolicyContainer(String groupId, String artifactId, String version) {
983 return new PolicyContainer(groupId, artifactId, version);
986 protected boolean isClass(String className) {
987 return ReflectionUtil.isClass(this.policyContainer.getClassLoader(), className);