621b30f44ec944529f0fcedc26b04c3c2a28d2f5
[aai/router-core.git] / src / main / java / org / onap / aai / event / EventBusEndPoint.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.event;
22
23 import org.apache.camel.Consumer;
24 import org.apache.camel.Processor;
25 import org.apache.camel.Producer;
26 import org.apache.camel.spi.Metadata;
27 import org.apache.camel.spi.UriEndpoint;
28 import org.apache.camel.spi.UriParam;
29 import org.onap.aai.cl.api.Logger;
30 import org.onap.aai.cl.eelf.LoggerFactory;
31 import org.onap.aai.event.api.EventConsumer;
32 import org.onap.aai.event.api.EventPublisher;
33
34 @UriEndpoint(scheme = "event-bus", syntax = "event-bus:name",
35 consumerClass = EventBusConsumer.class, title = "event-bus")
36 public class EventBusEndPoint extends AbstractEventBusEndpoint {
37         @UriParam(label = "eventTopic")
38         @Metadata(required = "true")
39         private String eventTopic;
40         @UriParam(label = "poolSize")
41         @Metadata(required = "true", defaultValue="20")
42         private int poolSize = 20;
43         @UriParam(label = "pollingDelay")
44         @Metadata(required = "true", defaultValue="30000")
45         private int pollingDelay = 30000;
46  
47         EventConsumer consumer; //This would be injected via bean through camel route when passed with #
48         
49         EventPublisher publisher; //This would be injected via bean through camel route when passed with #
50         
51         private Logger logger = LoggerFactory.getInstance().getLogger(EventBusEndPoint.class);
52         
53         public EventBusEndPoint(String uri, EventBusComponent component) {
54                 super(uri, component);
55         }
56          
57         @Override
58         public Producer createProducer() throws Exception {
59                 return new EventBusProducer(this, publisher);
60         }
61
62         @Override
63         public Consumer createConsumer(Processor processor) throws Exception {
64                 return new EventBusConsumer(this, processor, consumer);
65         }
66
67         @Override
68         public boolean isSingleton() {
69                 return false;
70         }
71         
72         void close() throws Exception {
73            if(consumer != null)
74                    consumer.close();
75                 if(publisher != null)
76                    publisher.close();
77         }       
78         
79         public void setPoolSize(int poolSize) {
80                 this.poolSize = poolSize;
81         }
82
83         public void setPollingDelay(int pollingDelay) {
84                 this.pollingDelay = pollingDelay;
85         }
86
87         public int getPollingDelay() {
88         return pollingDelay;
89     }
90         public int getPoolSize() {
91                 return poolSize;
92         }
93         public String getEventTopic() {
94                 return eventTopic;
95         }
96
97         public void setEventTopic(String eventTopic) {
98                 this.eventTopic = eventTopic;
99         }
100
101         public void setConsumer(EventConsumer consumer) {
102                 this.consumer = consumer;
103         }
104
105         public void setPublisher(EventPublisher publisher) {
106                 this.publisher = publisher;
107         }
108 }