View Javadoc

1   package org.xvsm.remote.freepastry;
2   
3   import java.io.Serializable;
4   import java.util.SortedMap;
5   
6   import rice.Continuation;
7   import rice.Continuation.StandardContinuation;
8   import rice.p2p.commonapi.Id;
9   import rice.p2p.commonapi.IdFactory;
10  import rice.p2p.commonapi.IdRange;
11  import rice.p2p.commonapi.IdSet;
12  import rice.persistence.Cache;
13  import rice.persistence.Storage;
14  import rice.persistence.StorageManager;
15  
16  /***
17   * overrides the StorageManager class of the FreePastry API and removes the
18   * caching functionality, as this functionality is not useful for us.
19   * 
20   * @author Hannu-Daniel Goiss
21   */
22  public class MyStorageManagerImpl implements StorageManager {
23  	private IdFactory factory;
24  	private Storage storage;
25  
26  	public MyStorageManagerImpl(IdFactory factory, Storage storage) {
27  		this.factory = factory;
28  		this.storage = storage;
29  	}
30  
31  	public Storage getStorage() {
32  		return storage;
33  	}
34  
35  	public boolean exists(Id id) {
36  		return storage.exists(id);
37  	}
38  
39  	public void rename(final Id oldId, final Id newId, Continuation c) {
40  		storage.rename(oldId, newId, new StandardContinuation(c) {
41  			public void receiveResult(Object o) {
42  				parent.receiveResult(o);
43  			}
44  
45  			public String toString() {
46  				return "rename of " + oldId + " to " + newId;
47  			}
48  		});
49  	}
50  
51  	public void getObject(final Id id, Continuation c) {
52  		storage.getObject(id, new StandardContinuation(c) {
53  			public void receiveResult(Object o) {
54  				// if (o != null) {
55  
56  				parent.receiveResult(o);
57  				// } else {
58  				// throw new Exception("Storage not found");
59  				// }
60  			}
61  
62  			public String toString() {
63  				return "getObject of " + id;
64  			}
65  		});
66  	}
67  
68  	public Serializable getMetadata(Id id) {
69  		return storage.getMetadata(id);
70  	}
71  
72  	public void setMetadata(final Id id, final Serializable metadata,
73  			Continuation command) {
74  		storage.setMetadata(id, metadata, new StandardContinuation(command) {
75  			public void receiveResult(Object o) {
76  				// storage.setMetadata(id, metadata, parent);
77  				parent.receiveResult(o);
78  			}
79  
80  			public String toString() {
81  				return "setMetadata of " + id;
82  			}
83  		});
84  	}
85  
86  	public IdSet scan(IdRange range) {
87  		return storage.scan(range);
88  	}
89  
90  	public IdSet scan() {
91  		return storage.scan();
92  	}
93  
94  	public SortedMap scanMetadata(IdRange range) {
95  		return storage.scanMetadata(range);
96  	}
97  
98  	public SortedMap scanMetadata() {
99  		return storage.scanMetadata();
100 	}
101 
102 	public SortedMap scanMetadataValuesHead(Object value) {
103 		return storage.scanMetadataValuesHead(value);
104 	}
105 
106 	public SortedMap scanMetadataValuesNull() {
107 		return storage.scanMetadataValuesNull();
108 	}
109 
110 	public long getTotalSize() {
111 		return storage.getTotalSize();
112 	}
113 
114 	public int getSize() {
115 		return storage.getSize();
116 	}
117 
118 	public void store(Id id, Serializable metadata, Serializable obj,
119 			Continuation c) {
120 		storage.store(id, metadata, obj, c);
121 	}
122 
123 	public void unstore(Id id, Continuation c) {
124 		storage.unstore(id, c);
125 	}
126 
127 	public void cache(Id id, Serializable metadata, Serializable obj,
128 			Continuation c) {
129 		c.receiveResult(obj);
130 		// cache.cache(id, metadata, obj, c);
131 	}
132 
133 	public void uncache(Id id, Continuation c) {
134 		// cache.uncache(id, c);
135 	}
136 
137 	public long getMaximumSize() {
138 		return 0;
139 		// return cache.getMaximumSize();
140 	}
141 
142 	public void setMaximumSize(int size, Continuation c) {
143 		// cache.setMaximumSize(size, c);
144 	}
145 
146 	public void flush(Continuation c) {
147 		storage.flush(new StandardContinuation(c) {
148 			public void receiveResult(Object o) {
149 				// storage.flush(parent);
150 				parent.receiveResult(o);
151 			}
152 		});
153 	}
154 
155 	public Cache getCache() {
156 		// TODO Auto-generated method stub
157 		return null;
158 	}
159 }