9560a834c8a2bcaa3ae32d1fee74bb5f3b0df60c
[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.event;
22
23 import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
24
25 /**
26  * This class holds a reference to an event consumer and producer that have been peered.
27  * 
28  * @author Liam Fallon (liam.fallon@ericsson.com)
29  */
30 public class PeeredReference {
31     // The consumer putting events into APEX
32     private final ApexEventConsumer peeredConsumer;
33
34     // The synchronous producer taking events out of APEX
35     private final ApexEventProducer peeredProducer;
36
37     /**
38      * Create a peered consumer/producer reference
39      * 
40      * @param peeredMode the peered mode for which to return the reference
41      * @param consumer the consumer that is receiving event
42      * @param producer the producer that is sending events
43      */
44     public PeeredReference(final EventHandlerPeeredMode peeredMode, final ApexEventConsumer consumer, final ApexEventProducer producer) {
45         this.peeredConsumer = consumer;
46         this.peeredProducer = producer;
47
48         // Set the peered reference on the producer and consumer
49         peeredConsumer.setPeeredReference(peeredMode, this);
50         peeredProducer.setPeeredReference(peeredMode, this);
51     }
52
53     /**
54      * Gets the synchronous consumer putting events into the cache.
55      *
56      * @return the source synchronous consumer
57      */
58     public ApexEventConsumer getPeeredConsumer() {
59         return peeredConsumer;
60     }
61
62     /**
63      * Gets the synchronous producer taking events from the cache.
64      *
65      * @return the synchronous producer that is taking events from the cache
66      */
67     public ApexEventProducer getPeeredProducer() {
68         return peeredProducer;
69     }
70 }