1 /*
2  * hunt-amqp: AMQP library for D programming language, based on hunt-net.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 module hunt.amqp.ProtonSender;
12 
13 
14 import hunt.proton.message.Message;
15 import hunt.amqp.ProtonLink;
16 import hunt.amqp.ProtonDelivery;
17 import hunt.amqp.Handler;
18 /**
19  * @author <a href="http://tfox.org">Tim Fox</a>
20  */
21 interface ProtonSender : ProtonLink!ProtonSender {
22 
23   /**
24    * Send the given message.
25    *
26    * @param message
27    *          the message to send
28    * @return the delivery used to send the message
29    */
30   ProtonDelivery send(Message message);
31 
32   /**
33    * Send the given message, registering the given handler to be called whenever the related delivery is updated due to
34    * receiving disposition frames from the peer.
35    *
36    * @param message
37    *          the message to send
38    * @param onUpdated
39    *          handler called when a disposition update is received for the delivery
40    * @return the delivery used to send the message
41    */
42   ProtonDelivery send(Message message, Handler!ProtonDelivery onUpdated);
43 
44   /**
45    * Send the given message, using the supplied delivery tag when creating the delivery.
46    *
47    * @param tag
48    *          the tag to use for the delivery used to send the message
49    * @param message
50    *          the message to send
51    * @return the delivery used to send the message
52    */
53   ProtonDelivery send(byte[] tag, Message message);
54 
55   /**
56    * Send the given message, using the supplied delivery tag when creating the delivery, and registering the given
57    * handler to be called whenever the related delivery is updated due to receiving disposition frames from the peer.
58    *
59    * @param tag
60    *          the tag to use for the delivery used to send the message
61    * @param message
62    *          the message to send
63    * @param onUpdated
64    *          handler called when a disposition update is received for the delivery
65    * @return the delivery used to send the message
66    */
67   ProtonDelivery send(byte[] tag, Message message, Handler!ProtonDelivery onUpdated);
68 
69   /**
70    * Gets whether the senders outgoing send queue is full, i.e. there is currently no credit to send and send
71    * operations will actually buffer locally until there is.
72    *
73    * @return whether the send queue is full
74    */
75   bool sendQueueFull();
76 
77   /**
78    * Sets a handler called when the send queue is not full, i.e. there is credit available to send messages.
79    *
80    * @param handler
81    *          the handler to process messages
82    * @return the sender
83    */
84   ProtonSender sendQueueDrainHandler(Handler!ProtonSender handler);
85 
86   /**
87    * Sets whether sent deliveries should be automatically locally-settled once they have become remotely-settled by the
88    * receiving peer.
89    *
90    * True by default.
91    *
92    * @param autoSettle
93    *          whether deliveries should be auto settled locally after being settled by the receiver
94    * @return the sender
95    */
96   ProtonSender setAutoSettle(bool autoSettle);
97 
98   /**
99    * Get whether the receiver is auto settling deliveries.
100    *
101    * @return whether deliveries should be auto settled locally after being settled by the receiver
102    * @see #setAutoSettle(boolean)
103    */
104   bool isAutoSettle();
105 
106   /**
107    * Sets whether the link is automatically marked {@link #drained()} after the send queue drain handler callback
108    * returns if the receiving peer requested that credit be drained, as indicated by the value of the
109    * {@link #getDrain()} flag.
110    *
111    * True by default.
112    *
113    * @param autoDrained
114    *          whether the link will automatically be drained after the send queue drain handler fires in drain mode
115    * @return the sender
116    */
117   ProtonSender setAutoDrained(bool autoDrained);
118 
119   /**
120    * Get whether the link will automatically be marked drained after the send queue drain handler fires in drain mode.
121    *
122    * @return whether the link will automatically be drained after the send queue drain handler fires in drain mode
123    * @see #setAutoDrained(boolean)
124    */
125   bool isAutoDrained();
126 
127   /**
128    * Manually mark the link drained, such that if the receiver has requested the link be drained (as indicated by the
129    * value of the {@link #getDrain()} flag) then any remaining credit is discarded and if necessary notice sent to the
130    * receiver indicating it has been.
131    *
132    * For use when {@link #isAutoDrained()} is false.
133    *
134    * @return the number of credits actually discarded
135    * @see #setAutoDrained(boolean)
136    */
137   int drained();
138 }