Update apache camel from 2.x to 3.x
[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.Category;
24 import org.apache.camel.Consumer;
25 import org.apache.camel.Processor;
26 import org.apache.camel.Producer;
27 import org.apache.camel.spi.Metadata;
28 import org.apache.camel.spi.UriEndpoint;
29 import org.apache.camel.spi.UriParam;
30 import org.apache.camel.spi.UriPath;
31 import org.onap.aai.cl.api.Logger;
32 import org.onap.aai.cl.eelf.LoggerFactory;
33 import org.onap.aai.event.api.EventConsumer;
34 import org.onap.aai.event.api.EventPublisher;
35
36 @UriEndpoint(scheme = "event-bus", syntax = "event-bus:name",
37 consumerClass = EventBusConsumer.class, title = "event-bus",
38 firstVersion = "1.0.0", category = {Category.CORE})
39 public class EventBusEndPoint extends AbstractEventBusEndpoint {
40
41         @UriPath(description = "client name")
42         private String name;
43         @UriParam(label = "eventTopic", description = "event topic")
44         @Metadata(required = true)
45         private String eventTopic;
46         @UriParam(label = "poolSize", description = "pool size")
47         @Metadata(required = true, defaultValue="20")
48         private int poolSize = 20;
49         @UriParam(label = "pollingDelay", description = "polling delay")
50         @Metadata(required = true, defaultValue="30000")
51         private int pollingDelay = 30000;
52
53         EventConsumer consumer; //This would be injected via bean through camel route when passed with #
54
55         EventPublisher publisher; //This would be injected via bean through camel route when passed with #
56
57         private Logger logger = LoggerFactory.getInstance().getLogger(EventBusEndPoint.class);
58         
59         public EventBusEndPoint(String uri, EventBusComponent component) {
60                 super(uri, component);
61         }
62          
63         @Override
64         public Producer createProducer() throws Exception {
65                 return new EventBusProducer(this, publisher);
66         }
67
68         @Override
69         public Consumer createConsumer(Processor processor) throws Exception {
70                 return new EventBusConsumer(this, processor, consumer);
71         }
72
73         @Override
74         public boolean isSingleton() {
75                 return false;
76         }
77         
78         void end() throws Exception {
79            if(consumer != null)
80                    consumer.close();
81                 if(publisher != null)
82                    publisher.close();
83         }       
84         
85         public void setPoolSize(int poolSize) {
86                 this.poolSize = poolSize;
87         }
88
89         public void setPollingDelay(int pollingDelay) {
90                 this.pollingDelay = pollingDelay;
91         }
92
93         public int getPollingDelay() {
94         return pollingDelay;
95     }
96         public int getPoolSize() {
97                 return poolSize;
98         }
99         public String getEventTopic() {
100                 return eventTopic;
101         }
102
103         public String getName() {
104                 return name;
105         }
106
107         public void setName(String name) {
108                 this.name = name;
109         }
110
111         public void setEventTopic(String eventTopic) {
112                 this.eventTopic = eventTopic;
113         }
114
115         public void setConsumer(EventConsumer consumer) {
116                 this.consumer = consumer;
117         }
118
119         public void setPublisher(EventPublisher publisher) {
120                 this.publisher = publisher;
121         }
122 }