KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ext > mixedlocation > UniversalBodyWrapper


1 /*
2  * Created by IntelliJ IDEA.
3  * User: fhuet
4  * Date: Apr 17, 2002
5  * Time: 7:09:56 PM
6  * To change template for new class use
7  * Code Style | Class Templates options (Tools | IDE Options).
8  */

9 package org.objectweb.proactive.ext.mixedlocation;
10
11 import java.io.IOException JavaDoc;
12 import java.security.PublicKey JavaDoc;
13 import java.security.cert.X509Certificate JavaDoc;
14 import java.util.ArrayList JavaDoc;
15
16 import org.objectweb.proactive.core.UniqueID;
17 import org.objectweb.proactive.core.body.UniversalBody;
18 import org.objectweb.proactive.core.body.reply.Reply;
19 import org.objectweb.proactive.core.body.request.Request;
20 import org.objectweb.proactive.ext.security.Communication;
21 import org.objectweb.proactive.ext.security.CommunicationForbiddenException;
22 import org.objectweb.proactive.ext.security.Policy;
23 import org.objectweb.proactive.ext.security.ProActiveSecurityManager;
24 import org.objectweb.proactive.ext.security.RenegotiateSessionException;
25 import org.objectweb.proactive.ext.security.SecurityContext;
26 import org.objectweb.proactive.ext.security.SecurityNotAvailableException;
27 import org.objectweb.proactive.ext.security.crypto.AuthenticationException;
28 import org.objectweb.proactive.ext.security.crypto.ConfidentialityTicket;
29 import org.objectweb.proactive.ext.security.crypto.KeyExchangeException;
30
31
32 public class UniversalBodyWrapper implements UniversalBody, Runnable JavaDoc {
33     protected UniversalBody wrappedBody;
34     protected long time;
35     protected UniqueID id;
36     protected boolean stop;
37     protected long creationTime;
38
39     //protected Thread t ;
40

41     /**
42      * Create a time-limited wrapper around a UniversalBody
43      * @param body the wrapped UniversalBody
44      * @param time the life expectancy of this wrapper in milliseconds
45      */

46     public UniversalBodyWrapper(UniversalBody body, long time) {
47         this.wrappedBody = body;
48         this.time = time;
49         this.creationTime = System.currentTimeMillis();
50         // t =new Thread(this);
51
this.id = this.wrappedBody.getID();
52
53         // t.start();
54
}
55
56     public void receiveRequest(Request request) throws IOException JavaDoc, RenegotiateSessionException {
57         // System.out.println("UniversalBodyWrapper.receiveRequest");
58
if (this.wrappedBody == null) {
59             throw new IOException JavaDoc();
60         }
61
62         //the forwarder should be dead
63
if (System.currentTimeMillis() > (this.creationTime + this.time)) {
64             // this.updateServer();
65
// this.wrappedBody = null;
66
// t.start();
67
// System.gc();
68
throw new IOException JavaDoc();
69         } else {
70             try {
71                 this.wrappedBody.receiveRequest(request);
72             } catch (IOException JavaDoc e) {
73                 e.printStackTrace();
74                 throw e;
75             }
76         }
77
78         // this.stop();
79
}
80
81     public void receiveReply(Reply r) throws IOException JavaDoc {
82         this.wrappedBody.receiveReply(r);
83     }
84
85     public String JavaDoc getNodeURL() {
86         return this.wrappedBody.getNodeURL();
87     }
88
89     public UniqueID getID() {
90         return this.id;
91     }
92
93     public void updateLocation(UniqueID id, UniversalBody body)
94         throws IOException JavaDoc {
95         this.wrappedBody.updateLocation(id, body);
96     }
97
98     public UniversalBody getRemoteAdapter() {
99         return this.wrappedBody.getRemoteAdapter();
100     }
101
102     public void enableAC() throws java.io.IOException JavaDoc {
103         this.wrappedBody.enableAC();
104     }
105
106     public void disableAC() throws java.io.IOException JavaDoc {
107         this.wrappedBody.disableAC();
108     }
109
110     public void setImmediateService(String JavaDoc methodName)
111         throws java.io.IOException JavaDoc {
112         this.wrappedBody.setImmediateService(methodName);
113     }
114
115     protected void updateServer() {
116         // System.out.println("UniversalBodyWrapper.updateServer");
117
// LocationServer server = LocationServerFactory.getLocationServer();
118
// try {
119
// server.updateLocation(id, this.wrappedBody);
120
// } catch (Exception e) {
121
// System.out.println("XXXX Error XXXX");
122
// // e.printStackTrace();
123
// }
124
}
125
126     //protected synchronized void stop() {
127
// this.stop=true;
128
// this.notifyAll();
129
//}
130
//
131
//protected synchronized void waitForStop(long time) {
132
// if (!this.stop) {
133
// try {
134
// wait(time);
135
// } catch (InterruptedException e) {
136
// e.printStackTrace();
137
// }
138
// }
139
//
140
//}
141
public void run() {
142         // System.out.println("UniversalBodyWrapper.run life expectancy " + time);
143
try {
144             // Thread.currentThread().sleep(time);
145
// this.waitForStop(time);
146
} catch (Exception JavaDoc e) {
147             e.printStackTrace();
148         }
149
150         // System.out.println("UniversalBodyWrapper.run end of life...");
151
this.updateServer();
152         this.wrappedBody = null;
153         System.gc();
154     }
155     
156     // SECURITY
157
public void initiateSession(int type,UniversalBody body)
158         throws java.io.IOException JavaDoc, CommunicationForbiddenException,
159             AuthenticationException, RenegotiateSessionException,
160             SecurityNotAvailableException {
161         wrappedBody.initiateSession(type,body);
162     }
163
164     public void terminateSession(long sessionID)
165         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
166         wrappedBody.terminateSession(sessionID);
167     }
168
169     public X509Certificate JavaDoc getCertificate()
170         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
171         return wrappedBody.getCertificate();
172     }
173
174     public ProActiveSecurityManager getProActiveSecurityManager()
175         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
176         return wrappedBody.getProActiveSecurityManager();
177     }
178
179     public Policy getPolicyFrom(X509Certificate JavaDoc certificate)
180         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
181         return wrappedBody.getPolicyFrom(certificate);
182     }
183
184     public long startNewSession(Communication policy)
185         throws java.io.IOException JavaDoc, RenegotiateSessionException,
186             SecurityNotAvailableException {
187         return wrappedBody.startNewSession(policy);
188     }
189
190     public ConfidentialityTicket negociateKeyReceiverSide(
191         ConfidentialityTicket confidentialityTicket, long sessionID)
192         throws java.io.IOException JavaDoc, KeyExchangeException,
193             SecurityNotAvailableException {
194         return wrappedBody.negociateKeyReceiverSide(confidentialityTicket,
195             sessionID);
196     }
197
198     public PublicKey JavaDoc getPublicKey()
199         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
200         return wrappedBody.getPublicKey();
201     }
202
203     public byte[] randomValue(long sessionID, byte[] cl_rand)
204         throws Exception JavaDoc, SecurityNotAvailableException {
205         return wrappedBody.randomValue(sessionID, cl_rand);
206     }
207
208     public byte[][] publicKeyExchange(long sessionID,
209         UniversalBody distantBody, byte[] my_pub, byte[] my_cert,
210         byte[] sig_code) throws Exception JavaDoc, SecurityNotAvailableException {
211         return wrappedBody.publicKeyExchange(sessionID, distantBody, my_pub,
212             my_cert, sig_code);
213     }
214
215     public byte[][] secretKeyExchange(long sessionID, byte[] tmp, byte[] tmp1,
216         byte[] tmp2, byte[] tmp3, byte[] tmp4)
217         throws Exception JavaDoc, SecurityNotAvailableException {
218         return wrappedBody.secretKeyExchange(sessionID, tmp, tmp1, tmp2, tmp3,
219             tmp4);
220     }
221
222     /* (non-Javadoc)
223      * @see org.objectweb.proactive.core.body.UniversalBody#getVNName()
224      */

225     public String JavaDoc getVNName() throws IOException JavaDoc, SecurityNotAvailableException {
226         return wrappedBody.getVNName();
227     }
228
229     /* (non-Javadoc)
230      * @see org.objectweb.proactive.core.body.UniversalBody#getCertificateEncoded()
231      */

232     public byte[] getCertificateEncoded()
233         throws IOException JavaDoc, SecurityNotAvailableException {
234         return wrappedBody.getCertificateEncoded();
235     }
236
237     /* (non-Javadoc)
238      * @see org.objectweb.proactive.core.body.UniversalBody#getPolicy(org.objectweb.proactive.ext.security.SecurityContext)
239      */

240     public SecurityContext getPolicy(SecurityContext securityContext)
241         throws SecurityNotAvailableException, IOException JavaDoc {
242         return wrappedBody.getPolicy(securityContext);
243     }
244     
245     public ArrayList JavaDoc getEntities() throws SecurityNotAvailableException, IOException JavaDoc {
246             return wrappedBody.getEntities();
247     }
248
249     public Communication getPolicyTo(String JavaDoc vn, String JavaDoc from, String JavaDoc to)
250         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
251         return this.wrappedBody.getPolicyTo(vn, from, to);
252     }
253
254     
255
256 }
257
Popular Tags