2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.testsuites.integration.executor.engine;
24 import java.util.ArrayList;
25 import java.util.List;
27 import org.onap.policy.apex.core.engine.engine.EnEventListener;
28 import org.onap.policy.apex.core.engine.event.EnEvent;
29 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
30 import org.slf4j.ext.XLogger;
31 import org.slf4j.ext.XLoggerFactory;
34 * The listener interface for receiving testApexAction events. The class that is interested in
35 * processing a testApexAction event implements this interface, and the object created with that
36 * class is registered with a component using the component's <code>addTestApexActionListener</code>
37 * method. When the testApexAction event occurs, that object's appropriate method is invoked.
39 * @author Liam Fallon (liam.fallon@ericsson.com)
41 public class TestApexActionListener implements EnEventListener {
42 private static final XLogger logger = XLoggerFactory.getXLogger(TestApexActionListener.class);
44 private List<EnEvent> resultEvents = new ArrayList<>();
47 private final String id;
50 * Instantiates a new test apex action listener.
54 public TestApexActionListener(final String id) {
61 * @param allowNulls if true and the returned event is null, then return, otherwise wait until
62 * an event is returned.
65 public EnEvent getResult(final boolean allowNulls) {
66 EnEvent result = null;
68 while (resultEvents.isEmpty()) {
69 ThreadUtilities.sleep(100);
71 result = resultEvents.remove(0);
72 if (result != null || allowNulls) {
83 public void onEnEvent(final EnEvent actionEvent) {
84 ThreadUtilities.sleep(100);
85 if (actionEvent != null) {
86 logger.info("Action event from engine: {}", actionEvent.getName());
88 resultEvents.add(actionEvent);