blob: 953b5e14f6cacaa8d908fe39e0d9851c545cc889 (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
package org.gnunet.requests;
import org.gnunet.util.AbsoluteTime;
import org.gnunet.util.Connection;
import org.gnunet.util.RelativeTime;
/**
* Abstract base class for a Request.
*
* Every request defines what happens when one of the following happens:
* <ul>
* <li>
* The request is canceled. There may be some cleanup necessary, depending on whether the request has already been
* sent to the service or not.
* </li>
* <li>
* On timeout.
* </li>
* <li>
* On reconnect. In particular, every Request has to decide whether it will be kept after a reconnect to the service.
* </li>
* <li>
* On destruction of the request queue. Some request may be important enough to delay the destruction until they have been sent.
* </li>
* </ul>
*
* @author Florian Dold
*/
public abstract class Request {
protected AbsoluteTime deadline = AbsoluteTime.FOREVER;
/**
* Called whenever the request could not be transmitted due to timeout.
*
* @return true if the request should be queued again
*/
public boolean onTransmitTimeout() {
// per default, just drop the message on timeout!
return false;
}
/**
*
*
* @return true if the request should be kept after the destroy request
*/
public boolean onDestroy() {
// per default, do not keep on destroy
return false;
}
/**
* @return true if the request should be kept after the reconnect
*/
public boolean onReconnect() {
// per default, do not keep on reconnect
return false;
}
/**
* @param alreadyTransmitted true if message has already been sent over the network
*/
public void onCancel(boolean alreadyTransmitted) {
// do nothing
}
public void setDeadline(AbsoluteTime deadline) {
this.deadline = deadline;
}
/**
* Called to determine after how long the request should time out.
* Per default, the deadline is FOREVER.
*
* @return the deadline for this request
*/
public AbsoluteTime getDeadline() {
return deadline;
}
public abstract void transmit(Connection.MessageSink sink);
}
|