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;
25 import org.onap.policy.apex.core.engine.engine.EnEventListener;
26 import org.onap.policy.apex.core.engine.event.EnEvent;
27 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
28 import org.slf4j.ext.XLogger;
29 import org.slf4j.ext.XLoggerFactory;
32 * The listener interface for receiving testApexAction events. The class that is interested in
33 * processing a testApexAction event implements this interface, and the object created with that
34 * class is registered with a component using the component's <code>addTestApexActionListener</code>
35 * method. When the testApexAction event occurs, that object's appropriate method is invoked.
37 * @author Liam Fallon (liam.fallon@ericsson.com)
39 public class TestApexActionListener implements EnEventListener {
40 private static final XLogger logger = XLoggerFactory.getXLogger(TestApexActionListener.class);
42 private List<EnEvent> resultEvents = new ArrayList<>();
44 private final String id;
47 * Instantiates a new test apex action listener.
51 public TestApexActionListener(final String id) {
58 * @param allowNulls if true and the returned event is null, then return, otherwise wait until
59 * an event is returned.
62 public EnEvent getResult(final boolean allowNulls) {
63 EnEvent result = null;
65 while (resultEvents.isEmpty()) {
66 ThreadUtilities.sleep(100);
68 result = resultEvents.remove(0);
69 if (result != null || allowNulls) {
80 public void onEnEvent(final EnEvent actionEvent) {
81 ThreadUtilities.sleep(100);
82 if (actionEvent != null) {
83 logger.info("Action event from engine: {}", actionEvent.getName());
85 resultEvents.add(actionEvent);
93 public String getId() {