14ca3f0fa47d1c5f03cc616ad9e2fb88d4dc16fc
[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,
45             final ApexEventProducer producer) {
46         this.peeredConsumer = consumer;
47         this.peeredProducer = producer;
48
49         // Set the peered reference on the producer and consumer
50         peeredConsumer.setPeeredReference(peeredMode, this);
51         peeredProducer.setPeeredReference(peeredMode, this);
52     }
53
54     /**
55      * Gets the synchronous consumer putting events into the cache.
56      *
57      * @return the source synchronous consumer
58      */
59     public ApexEventConsumer getPeeredConsumer() {
60         return peeredConsumer;
61     }
62
63     /**
64      * Gets the synchronous producer taking events from the cache.
65      *
66      * @return the synchronous producer that is taking events from the cache
67      */
68     public ApexEventProducer getPeeredProducer() {
69         return peeredProducer;
70     }
71 }