651c54803a3f05e22e34d34d76e47129138c6964
[dmaap/messagerouter/dmaapclient.git] / src / main / java / com / att / nsa / mr / client / MRPublisher.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.nsa.mr.client;
23
24 import java.io.IOException;
25 import java.util.Collection;
26
27 /**
28  * A MR publishing interface.
29  *
30  */
31 public interface MRPublisher extends MRClient
32 {
33         /**
34          * A simple message container 
35          */
36         public static class message
37         {
38                 public message ( String partition, String msg )
39                 {
40                         fPartition = partition == null ? "" : partition;
41                         fMsg = msg;
42                         if ( fMsg == null )
43                         {
44                                 throw new IllegalArgumentException ( "Can't send a null message." );
45                         }
46                 }
47
48                 public message ( message msg )
49                 {
50                         this ( msg.fPartition, msg.fMsg );
51                 }
52
53                 public final String fPartition;
54                 public final String fMsg;
55         }
56         
57         /**
58          * Send the given message without partition. partition will be placed at HTTP request level.
59          * @param msg message to sent
60          * @return the number of pending messages
61          * @throws IOException exception
62          */
63         int send ( String msg ) throws IOException;
64         /**
65          * Send the given message using the given partition.
66          * @param partition partition
67          * @param msg message
68          * @return the number of pending messages
69          * @throws IOException exception
70          */
71         int send ( String partition, String msg ) throws IOException;
72
73         /**
74          * Send the given message using its partition.
75          * @param msg mesg
76          * @return the number of pending messages
77          * @throws IOException exp
78          */
79         int send ( message msg ) throws IOException;
80
81         /**
82          * Send the given messages using their partitions.
83          * @param msgs msg
84          * @return the number of pending messages
85          * @throws IOException exp
86          */
87         int send ( Collection<message> msgs ) throws IOException;
88
89         /**
90          * Close this publisher. It's an error to call send() after close()
91          */
92         void close ();
93 }