abd6db2d95d1f410d58b024642fe162d97efd889
[policy/apex-pdp.git] /
1 /*-
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.service.engine.runtime.impl;
22
23 import org.onap.policy.apex.core.engine.engine.EnEventListener;
24 import org.onap.policy.apex.core.engine.event.EnEvent;
25 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
26 import org.onap.policy.apex.service.engine.event.ApexEvent;
27 import org.onap.policy.apex.service.engine.event.impl.enevent.ApexEvent2EnEventConverter;
28 import org.onap.policy.apex.service.engine.runtime.ApexEventListener;
29
30 /**
31  * The Class EnEventListenerImpl is used by the Apex engine implementation to listen for events
32  * coming from the core APEX engine. This listener converts the {@link EnEvent} instances into
33  * {@link ApexEvent} instances using an {@link ApexEvent2EnEventConverter} instance and forwards the
34  * events to an {@link ApexEventListener} instance for outputting to listening applications. The
35  * {@link ApexEventListener} is implemented in the external application communicating with Apex.
36  *
37  * @author Liam Fallon (liam.fallon@ericsson.com)
38  */
39 public final class EnEventListenerImpl implements EnEventListener {
40     // Listener for ApexEvents
41     private ApexEventListener apexEventListener = null;
42
43     // Converter for Engine events to Apex Events
44     private ApexEvent2EnEventConverter apexEnEventConverter = null;
45
46     /**
47      * Instantiates a new listener implementation.
48      *
49      * @param apexEventListener the apex event listener
50      * @param apexEnEventConverter the ApexEvent to enEvent converter
51      */
52     public EnEventListenerImpl(final ApexEventListener apexEventListener,
53             final ApexEvent2EnEventConverter apexEnEventConverter) {
54         this.apexEventListener = apexEventListener;
55         this.apexEnEventConverter = apexEnEventConverter;
56     }
57
58     /*
59      * (non-Javadoc)
60      *
61      * @see
62      * org.onap.policy.apex.core.engine.engine.EnEventListener#onEnEvent(org.onap.policy.apex.core.
63      * engine.event.EnEvent)
64      */
65     @Override
66     public void onEnEvent(final EnEvent enEvent) throws ApexException {
67         for (final ApexEvent apexEvent : apexEnEventConverter.toApexEvent(enEvent.getName(), enEvent)) {
68             apexEventListener.onApexEvent(apexEvent);
69         }
70     }
71 }