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
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.event;
23 import java.util.EnumMap;
25 import org.onap.policy.apex.core.infrastructure.threading.ApplicationThreadFactory;
26 import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
28 public abstract class ApexPluginsEventConsumer implements ApexEventConsumer, Runnable {
29 // The name for this consumer
30 protected String name = null;
32 // The peer references for this event handler
33 protected Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap =
34 new EnumMap<>(EventHandlerPeeredMode.class);
36 // The consumer thread and stopping flag
37 protected Thread consumerThread;
38 protected boolean stopOrderedFlag = false;
45 // Configure and start the event reception thread
46 final String threadName = this.getClass().getName() + ":" + this.name;
47 consumerThread = new ApplicationThreadFactory(threadName).newThread(this);
48 consumerThread.setDaemon(true);
49 consumerThread.start();
56 public String getName() {
64 public PeeredReference getPeeredReference(final EventHandlerPeeredMode peeredMode) {
65 return peerReferenceMap.get(peeredMode);
72 public void setPeeredReference(final EventHandlerPeeredMode peeredMode, final PeeredReference peeredReference) {
73 peerReferenceMap.put(peeredMode, peeredReference);