aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/gnunet/statistics/SetRequest.java
blob: c5fff6620b85339a41c7cfe124639dbed81f7540 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package org.gnunet.statistics;

import org.gnunet.mq.Envelope;
import org.gnunet.mq.MessageQueue;
import org.gnunet.requests.Request;
import org.gnunet.requests.RequestContainer;
import org.gnunet.statistics.messages.SetMessage;
import org.gnunet.util.RelativeTime;


public class SetRequest extends Request {
    /**
     * Time after we give up on setting values in statistics
     */
    private static final RelativeTime SET_TIMEOUT = RelativeTime.SECOND.multiply(10);

    private final static int SETFLAG_RELATIVE = 1;
    private final static int SETFLAG_PERSIST = 2;
    private final String subsystem;
    private final String name;
    private final boolean persist;
    private final long value;
    private final boolean relative;

    public SetRequest(String subsystem, String name, long value, boolean relative, boolean persist) {
        this.subsystem = subsystem;
        this.name = name;
        this.persist = persist;
        this.value = value;
        this.relative = relative;

    }

    @Override
    public Envelope assembleRequest() {
        SetMessage m = new SetMessage();
        m.statisticName = name;
        m.subsystemName = subsystem;
        m.value = value;
        if (relative)
            m.flags |= SETFLAG_RELATIVE;
        if (persist)
            m.flags |= SETFLAG_PERSIST;
        return new Envelope(m);
    }

    public void cancel() {
        //To change body of implemented methods use File | Settings | File Templates.
    }
}