4020a6d7d0865e3166c6839f949fe5896f501c38
[dmaap/messagerouter/msgrtr.git] / src / main / java / com / att / dmf / mr / metrics / publisher / CambriaPublisher.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
4  *  ================================================================================
5  *  Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  *  ================================================================================
7  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at
10  *        http://www.apache.org/licenses/LICENSE-2.0
11 *  
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *  ============LICENSE_END=========================================================
18  *  
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *  
21  *******************************************************************************/
22 package com.att.dmf.mr.metrics.publisher;
23
24 import java.io.IOException;
25 import java.util.Collection;
26
27 /**
28  * A Cambria publishing interface.
29  * 
30  * @author peter
31  *
32  */
33 public interface CambriaPublisher extends CambriaClient {
34         /**
35          * A simple message container
36          */
37         public static class message {
38                 /**
39                  * 
40                  * @param partition
41                  * @param msg
42                  */
43                 public message(String partition, String msg) {
44                         fPartition = partition == null ? "" : partition;
45                         fMsg = msg;
46                         if (fMsg == null) {
47                                 throw new IllegalArgumentException("Can't send a null message.");
48                         }
49                 }
50
51                 /**
52                  * 
53                  * @param msg
54                  */
55                 public message(message msg) {
56                         this(msg.fPartition, msg.fMsg);
57                 }
58
59                 /**
60                  *  declaring partition string
61                  */
62                 public final String fPartition;
63                 /**
64                  * declaring fMsg String
65                  */
66                 public final String fMsg;
67         }
68
69         /**
70          * Send the given message using the given partition.
71          * 
72          * @param partition
73          * @param msg
74          * @return the number of pending messages
75          * @throws IOException
76          */
77         int send(String partition, String msg) throws IOException;
78
79         /**
80          * Send the given message using its partition.
81          * 
82          * @param msg
83          * @return the number of pending messages
84          * @throws IOException
85          */
86         int send(message msg) throws IOException;
87
88         /**
89          * Send the given messages using their partitions.
90          * 
91          * @param msgs
92          * @return the number of pending messages
93          * @throws IOException
94          */
95         int send(Collection<message> msgs) throws IOException;
96
97         /**
98          * Close this publisher. It's an error to call send() after close()
99          */
100         void close();
101 }