Changes for checkstyle 8.32
[policy/apex-pdp.git] / services / services-engine / src / main / java / org / onap / policy / apex / service / engine / event / ApexPluginsEventProducer.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2020 Nordix Foundation.
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.event;
22
23 import java.util.EnumMap;
24 import java.util.Map;
25 import java.util.Properties;
26 import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
27
28 public abstract class ApexPluginsEventProducer implements ApexEventProducer {
29     // The name for this producer
30     protected String name = null;
31     // The peer references for this event handler
32     protected Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap =
33             new EnumMap<>(EventHandlerPeeredMode.class);
34
35     /**
36      * {@inheritDoc}.
37      */
38     @Override
39     public String getName() {
40         return name;
41     }
42
43     /**
44      * {@inheritDoc}.
45      */
46     @Override
47     public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) {
48         return peerReferenceMap.get(peeredMode);
49     }
50
51     /**
52      * {@inheritDoc}.
53      */
54     @Override
55     public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) {
56         peerReferenceMap.put(peeredMode, peeredReference);
57     }
58
59     /**
60      * {@inheritDoc}.
61      */
62     @Override
63     public void sendEvent(final long executionId, final Properties executionProperties, final String eventName,
64             final Object event) {
65         // Check if this is a synchronized event, if so we have received a reply
66         final SynchronousEventCache synchronousEventCache =
67                 (SynchronousEventCache) peerReferenceMap.get(EventHandlerPeeredMode.SYNCHRONOUS);
68         if (synchronousEventCache != null) {
69             synchronousEventCache.removeCachedEventToApexIfExists(executionId);
70         }
71     }
72
73 }