2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2020 Nordix Foundation.
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.service.engine.main;
24 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
25 import org.onap.policy.apex.service.engine.event.ApexEvent;
26 import org.onap.policy.apex.service.engine.runtime.EngineService;
27 import org.slf4j.ext.XLogger;
28 import org.slf4j.ext.XLoggerFactory;
31 * The Class ApexEngineServiceHandler holds the reference to the Apex engine
32 * service and the EngDep service for that engine. It also acts as an event
33 * receiver for asynchronous and synchronous events.
35 public class ApexEngineServiceHandler {
36 // The logger for this class
37 private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEngineServiceHandler.class);
39 // The Apex engine service, the Apex engine itself
40 private final EngineService apexEngineService;
43 * Instantiates a new engine holder with its engine service and EngDep service.
45 * @param apexEngineService the apex engine service
46 * @param engDepService the EngDep service
48 ApexEngineServiceHandler(final EngineService apexEngineService) {
49 this.apexEngineService = apexEngineService;
53 * This method forwards an event to the Apex service.
55 * @param apexEvent The event to forward to Apex
57 public void forwardEvent(final ApexEvent apexEvent) {
59 // Send the event to the engine runtime
60 apexEngineService.getEngineServiceEventInterface().sendEvent(apexEvent);
61 } catch (final Exception e) {
62 final String errorMessage = "error transferring event \"" + apexEvent.getName() + "\" to the Apex engine";
63 LOGGER.debug(errorMessage, e);
64 throw new ApexActivatorRuntimeException(errorMessage, e);
69 * Terminate the Apex engine.
71 * @throws ApexException on termination errors
73 public void terminate() throws ApexException {
74 // Shut down each engine instance
75 if (apexEngineService != null) {
76 apexEngineService.stop();
77 apexEngineService.clear();