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.service.engine.main;
23 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
24 import org.onap.policy.apex.service.engine.engdep.EngDepMessagingService;
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 service and the EngDep
32 * service for that engine. It also acts as an event receiver for asynchronous and synchronous
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;
42 // The interface between the Apex engine and Apex policy deployment for the Apex engine
43 private final EngDepMessagingService engDepService;
46 * Instantiates a new engine holder with its engine service and EngDep service.
48 * @param apexEngineService the apex engine service
49 * @param engDepService the EngDep service
51 ApexEngineServiceHandler(final EngineService apexEngineService, final EngDepMessagingService engDepService) {
52 this.apexEngineService = apexEngineService;
53 this.engDepService = engDepService;
57 * This method forwards an event to the Apex service.
59 * @param apexEvent The event to forward to Apex
61 public void forwardEvent(final ApexEvent apexEvent) {
63 // Send the event to the engine runtime
64 apexEngineService.getEngineServiceEventInterface().sendEvent(apexEvent);
65 } catch (final Exception e) {
66 final String errorMessage = "error transferring event \"" + apexEvent.getName() + "\" to the Apex engine";
67 LOGGER.debug(errorMessage, e);
68 throw new ApexActivatorRuntimeException(errorMessage, e);
73 * Terminate the Apex engine.
75 * @throws ApexException on termination errors
77 public void terminate() throws ApexException {
78 // Shut down engine management
79 if (engDepService != null) {
83 // Shut down each engine instance
84 if (apexEngineService != null) {
85 apexEngineService.stop();