Source code: Freenet/message/KeyedMM.java
1 package Freenet.message;
2 import Freenet.*;
3 import Freenet.support.Callback;
4 import java.util.*;
5 /*
6 This code is part of the Java Adaptive Network Client by Ian Clarke.
7 It is distributed under the GNU General Public Licence (GPL)
8 version 2. See http://www.gnu.org/ for further details of the GPL.
9 */
10
11 /**
12 * This is the MessageMemory pertaining to messages that need to
13 * remember the keys used.
14 *
15 * @author <A HREF="mailto:I.Clarke@strs.co.uk">Ian Clarke</A>
16 **/
17
18 public class KeyedMM extends MessageMemory
19 {
20 // Public Fields
21 Key searchKey, lastAttempt;
22 Class messageType;
23 Vector usedAddresses;
24 Address lastAddr;
25
26 // this is the address that data is sent to, originally it is set back to the sender, but can be reset for Inserts for example
27 Address dataref;
28
29
30 // pending gives whether a search is still pending for this chain. It is not necessary to set this currently, just a performance issue (it won't try to cancel the timer when this MM dies if this is false).
31 boolean pending = true;
32
33 // Constructor
34 /**
35 * @param origRec The address from which the DataRequest
36 * originated
37 * @param searchKey The key being searched for
38 * @param lastAttempt The key corresponding to the most
39 * recent attempt to send a DataRequest
40 * (used as a mask).
41 **/
42 public KeyedMM(Address origRec,
43 long depth,
44 Key searchKey,
45 Key lastAttempt,
46 Class messageType)
47 {
48 super(origRec,depth);
49 this.dataref = origRec;
50 this.searchKey = searchKey;
51 this.lastAttempt = lastAttempt;
52 this.messageType = messageType;
53 this.usedAddresses = new Vector();
54 }
55
56 public KeyedMM(Address origRec,
57 long depth,
58 ConnectionHandler replyCon,
59 Key searchKey,
60 Key lastAttempt,
61 Class messageType)
62 {
63 super(origRec,depth, replyCon);
64 this.dataref = origRec;
65 this.searchKey = searchKey;
66 this.lastAttempt = lastAttempt;
67 this.messageType = messageType;
68 this.usedAddresses = new Vector();
69 }
70
71
72 // cancel the timer, and if it exists (meaning some node is probably waiting for response, use the RequestCBs method to sendback a requestfailed.
73
74 public void lost(Long longid) {
75 if (pending) {
76 Callback cb = Core.timer.cancel(longid.longValue());
77 if (cb != null && cb instanceof RequestCB) {
78 ((RequestCB) cb).sendback();
79 }
80 }
81 }
82
83 }