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