diff options
Diffstat (limited to 'src/main/java/org/gnunet/mq/Envelope.java')
-rw-r--r-- | src/main/java/org/gnunet/mq/Envelope.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/main/java/org/gnunet/mq/Envelope.java b/src/main/java/org/gnunet/mq/Envelope.java new file mode 100644 index 0000000..fa19225 --- /dev/null +++ b/src/main/java/org/gnunet/mq/Envelope.java | |||
@@ -0,0 +1,36 @@ | |||
1 | package org.gnunet.mq; | ||
2 | |||
3 | import org.gnunet.util.Cancelable; | ||
4 | import org.gnunet.util.GnunetMessage; | ||
5 | |||
6 | /** | ||
7 | * Container for a message to be sent by a message queue. | ||
8 | */ | ||
9 | public class Envelope implements Cancelable { | ||
10 | public final GnunetMessage.Body message; | ||
11 | private MessageQueue parent_queue; | ||
12 | private NotifySentHandler notify_sent_handler; | ||
13 | |||
14 | public Envelope(GnunetMessage.Body message) { | ||
15 | this.message = message; | ||
16 | } | ||
17 | |||
18 | public void notifySent(NotifySentHandler h) { | ||
19 | this.notify_sent_handler = h; | ||
20 | } | ||
21 | |||
22 | public void injectSent() { | ||
23 | if (notify_sent_handler != null) | ||
24 | notify_sent_handler.onSent(); | ||
25 | } | ||
26 | |||
27 | public void cancel() { | ||
28 | if (parent_queue == null) | ||
29 | throw new AssertionError("can not cancel an unqueued message"); | ||
30 | } | ||
31 | |||
32 | /* pkg-private */ void invokeSentNotification() { | ||
33 | if (null != notify_sent_handler) | ||
34 | notify_sent_handler.onSent(); | ||
35 | } | ||
36 | } | ||