aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/gnunet/mq/Envelope.java
blob: fa19225d5eb2d7f3074bf5905f67f458aed84d3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package org.gnunet.mq;

import org.gnunet.util.Cancelable;
import org.gnunet.util.GnunetMessage;

/**
 * Container for a message to be sent by a message queue.
 */
public class Envelope implements Cancelable {
    public final GnunetMessage.Body message;
    private MessageQueue parent_queue;
    private NotifySentHandler notify_sent_handler;

    public Envelope(GnunetMessage.Body message) {
        this.message = message;
    }

    public void notifySent(NotifySentHandler h) {
        this.notify_sent_handler = h;
    }

    public void injectSent() {
        if (notify_sent_handler != null)
            notify_sent_handler.onSent();
    }

    public void cancel() {
        if (parent_queue == null)
            throw new AssertionError("can not cancel an unqueued message");
    }

    /* pkg-private */ void invokeSentNotification() {
        if (null != notify_sent_handler)
            notify_sent_handler.onSent();
    }
}