0475c13943784a34e95f8eca7763e9a37d05fca5
[appc.git] / appc-event-listener / appc-event-listener-bundle / src / main / java / org / openecomp / appc / listener / EventHandler.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 package org.openecomp.appc.listener;
24
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.Set;
28
29 /**
30  * EventHandler defines a class that wraps DMaaP operations (most notably Get Message and Post Message) to make them
31  * easier to use.
32  *
33  */
34 public interface EventHandler {
35
36     /**
37      * Gets a list of messages as Strings on the read topic.
38      * 
39      * @return A list of String messages. Never returns null.
40      */
41     public List<String> getIncomingEvents();
42
43     /**
44      * Gets a list of messages as String on the read topic.
45      * 
46      * @param limit
47      *            The maximum amount of entries to return
48      * @return A list of String messages. Never returns null.
49      */
50     public List<String> getIncomingEvents(int limit);
51
52     /**
53      * Gets a list of messages Mapped to the given Class. If a message cannot be mapped to that class, it is discarded.
54      *
55      * @param cls
56      *            The class to map the message to.
57      * @return A list of objects of the provided class. Never returns null.
58      */
59     public <T> List<T> getIncomingEvents(Class<T> cls);
60
61     /**
62      * Gets a list of messages Mapped to the given Class. If a message cannot be mapped to that class, it is discarded.
63      *
64      * @param cls
65      *            The class to map the message to.
66      * @param limit
67      *            The maximum amount of entries to return
68      * @return A list of objects of the provided class. Never returns null.
69      */
70     public <T> List<T> getIncomingEvents(Class<T> cls, int limit);
71
72     /**
73      * Posts the String message to the write topic(s).
74      * 
75      * @param event
76      *            The String to post.
77      */
78     public void postStatus(String event);
79
80     /**
81      * Posts the String message to the write topic(s) on the specified partition. Partitions are only used to guarantee
82      * ordering and do not impact if data is retreived.
83      *
84      * @param partition
85      *            The partition to post to or null if no partition should be used.
86      * @param event
87      *            The String to post.
88      */
89     public void postStatus(String partition, String event);
90
91     /**
92      * @return The client/group id used to read messages
93      */
94     public String getClientId();
95
96     /**
97      * Set the client/group id used to read messages
98      * 
99      * @param clientId
100      *            The new clientId to use
101      */
102     public void setClientId(String clientId);
103
104     /**
105      * @return The client/group name to use.
106      */
107     public String getClientName();
108
109     /**
110      * Set the client/group name used to read messages.
111      * 
112      * @param clientName
113      *            The new clientName to use
114      */
115     public void setClientName(String clientName);
116
117     /**
118      * @return The name of the topic to read from
119      */
120     public String getReadTopic();
121
122     /**
123      * Set the name of the topic to read from.
124      * 
125      * @param topic
126      *            The new topic to read from
127      */
128     public void setReadTopic(String topic);
129
130     /**
131      * @return The name of the topic to write to
132      */
133     public Set<String> getWriteTopics();
134
135     /**
136      * Set the name of the topic to write to
137      * 
138      * @param topic
139      *            The new topic to write to
140      */
141     public void setWriteTopics(Set<String> topic);
142
143     /**
144      * Adds a DMaaP host to the host pool
145      * 
146      * @param host
147      *            The host to add to the pool in &lt;host&gt;:&lt;port&gt; format
148      */
149     public void addToPool(String host);
150
151     /**
152      * Remove the host name from the pool if it exists
153      * 
154      * @param host
155      *            The host to add to the pool in &lt;host&gt;:&lt;port&gt; format
156      */
157     public void removeFromPool(String host);
158
159     /**
160      * Get all of the hosts in the DMaaP pool
161      * 
162      * @return A collection of host in &lt;host&gt;:&lt;port&gt; format
163      */
164     public Collection<String> getPool();
165
166     /**
167      * Clear any provided api credentials and make future requests as an unauthenticated user
168      */
169     public void clearCredentials();
170
171     /**
172      * Set the api credentials and make future requests as an authenticated user
173      * 
174      * @param access
175      *            The access portion of the credentials (either user name or api key)
176      * @param secret
177      *            The secret portion of the credentials (either password or api secret)
178      */
179     public void setCredentials(String access, String secret);
180     
181     /**
182      * Close consumer/producer DMaaP clients
183      */
184     public void closeClients();
185
186 }