KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > body > rmi > RemoteBodyImpl


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.core.body.rmi;
32
33 import java.io.IOException JavaDoc;
34 import java.rmi.RemoteException JavaDoc;
35 import java.security.PublicKey JavaDoc;
36 import java.security.cert.X509Certificate JavaDoc;
37 import java.util.ArrayList JavaDoc;
38
39 import org.apache.log4j.Logger;
40 import org.objectweb.proactive.core.UniqueID;
41 import org.objectweb.proactive.core.body.UniversalBody;
42 import org.objectweb.proactive.core.body.reply.Reply;
43 import org.objectweb.proactive.core.body.request.Request;
44 import org.objectweb.proactive.core.rmi.RandomPortSocketFactory;
45 import org.objectweb.proactive.ext.security.Communication;
46 import org.objectweb.proactive.ext.security.CommunicationForbiddenException;
47 import org.objectweb.proactive.ext.security.Policy;
48 import org.objectweb.proactive.ext.security.ProActiveSecurityManager;
49 import org.objectweb.proactive.ext.security.RenegotiateSessionException;
50 import org.objectweb.proactive.ext.security.SecurityContext;
51 import org.objectweb.proactive.ext.security.SecurityNotAvailableException;
52 import org.objectweb.proactive.ext.security.crypto.AuthenticationException;
53 import org.objectweb.proactive.ext.security.crypto.ConfidentialityTicket;
54 import org.objectweb.proactive.ext.security.crypto.KeyExchangeException;
55
56
57 /**
58  * An adapter for a LocalBody to be able to receive remote calls. This helps isolate RMI-specific
59  * code into a small set of specific classes, thus enabling reuse if we one day decide to switch
60  * to anothe remote objects library.
61  */

62 public class RemoteBodyImpl extends java.rmi.server.UnicastRemoteObject JavaDoc
63     implements RemoteBody, java.rmi.server.Unreferenced JavaDoc {
64     protected static Logger logger = Logger.getLogger(RemoteBodyImpl.class.getName());
65
66     /**
67     * A custom socket Factory
68     */

69     protected static RandomPortSocketFactory factory = new RandomPortSocketFactory(37002,
70             5000);
71
72     /**
73     * The encapsulated local body
74     * transient to deal with custom serialization of requests.
75     */

76     protected transient UniversalBody body;
77
78     //
79
// -- CONSTRUCTORS -----------------------------------------------
80
//
81
public RemoteBodyImpl() throws RemoteException JavaDoc {
82     }
83
84     public RemoteBodyImpl(UniversalBody body) throws RemoteException JavaDoc {
85         // super(0, factory, factory);
86
this.body = body;
87     }
88
89     //
90
// -- PUBLIC METHODS -----------------------------------------------
91
//
92
//
93
// -- implements RemoteBody -----------------------------------------------
94
//
95
public void receiveRequest(Request r) throws java.io.IOException JavaDoc, RenegotiateSessionException {
96         body.receiveRequest(r);
97     }
98
99     public void receiveReply(Reply r) throws java.io.IOException JavaDoc {
100         body.receiveReply(r);
101     }
102
103     public String JavaDoc getNodeURL() {
104         return body.getNodeURL();
105     }
106
107     public UniqueID getID() {
108         return body.getID();
109     }
110
111     public void updateLocation(UniqueID id, UniversalBody remoteBody)
112         throws java.io.IOException JavaDoc {
113         body.updateLocation(id, remoteBody);
114     }
115
116     public void unreferenced() {
117         // System.out.println("RemoteBodyImpl: unreferenced()");
118
System.gc();
119     }
120
121     public void enableAC() throws java.io.IOException JavaDoc {
122         body.enableAC();
123     }
124
125     public void disableAC() throws java.io.IOException JavaDoc {
126         body.disableAC();
127     }
128
129     public void setImmediateService(String JavaDoc methodName)
130         throws java.io.IOException JavaDoc {
131         body.setImmediateService(methodName);
132     }
133
134     // SECURITY
135
public void initiateSession(int type,UniversalBody rbody)
136         throws IOException JavaDoc, CommunicationForbiddenException,
137             AuthenticationException, RenegotiateSessionException,
138             SecurityNotAvailableException {
139         body.initiateSession(type,rbody);
140     }
141
142     public void terminateSession(long sessionID)
143         throws IOException JavaDoc, SecurityNotAvailableException {
144         body.terminateSession(sessionID);
145     }
146
147     public X509Certificate JavaDoc getCertificate()
148         throws SecurityNotAvailableException, IOException JavaDoc {
149         X509Certificate JavaDoc cert = body.getCertificate();
150         return cert;
151     }
152
153     public ProActiveSecurityManager getProActiveSecurityManager()
154         throws SecurityNotAvailableException, IOException JavaDoc {
155         return body.getProActiveSecurityManager();
156     }
157
158     public Policy getPolicyFrom(X509Certificate JavaDoc certificate)
159         throws SecurityNotAvailableException, IOException JavaDoc {
160         return body.getPolicyFrom(certificate);
161     }
162
163     public long startNewSession(Communication policy)
164         throws SecurityNotAvailableException, IOException JavaDoc,
165             RenegotiateSessionException {
166         return body.startNewSession(policy);
167     }
168
169     public ConfidentialityTicket negociateKeyReceiverSide(
170         ConfidentialityTicket confidentialityTicket, long sessionID)
171         throws SecurityNotAvailableException, KeyExchangeException, IOException JavaDoc {
172         return body.negociateKeyReceiverSide(confidentialityTicket, sessionID);
173     }
174
175     public PublicKey JavaDoc getPublicKey()
176         throws SecurityNotAvailableException, IOException JavaDoc {
177         return body.getPublicKey();
178     }
179
180     public byte[] randomValue(long sessionID, byte[] cl_rand)
181         throws Exception JavaDoc {
182         return body.randomValue(sessionID, cl_rand);
183     }
184
185     public byte[][] publicKeyExchange(long sessionID,
186         UniversalBody distantBody, byte[] my_pub, byte[] my_cert,
187         byte[] sig_code) throws Exception JavaDoc {
188         return body.publicKeyExchange(sessionID, distantBody, my_pub, my_cert,
189             sig_code);
190     }
191
192     public byte[][] secretKeyExchange(long sessionID, byte[] tmp, byte[] tmp1,
193         byte[] tmp2, byte[] tmp3, byte[] tmp4) throws Exception JavaDoc {
194         return body.secretKeyExchange(sessionID, tmp, tmp1, tmp2, tmp3, tmp4);
195     }
196
197     public Communication getPolicyTo(String JavaDoc type, String JavaDoc from, String JavaDoc to)
198         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
199         return body.getPolicyTo(type, from, to);
200     }
201
202     /* (non-Javadoc)
203      * @see org.objectweb.proactive.core.body.rmi.RemoteBody#getVNName()
204      */

205     public String JavaDoc getVNName() throws IOException JavaDoc, SecurityNotAvailableException {
206         return body.getVNName();
207     }
208
209     /* (non-Javadoc)
210      * @see org.objectweb.proactive.core.body.rmi.RemoteBody#getCertificateEncoded()
211      */

212     public byte[] getCertificateEncoded()
213         throws IOException JavaDoc, SecurityNotAvailableException {
214         return body.getCertificateEncoded();
215     }
216
217     /* (non-Javadoc)
218      * @see org.objectweb.proactive.core.body.rmi.RemoteBody#getPolicy(org.objectweb.proactive.ext.security.SecurityContext)
219      */

220     public SecurityContext getPolicy(SecurityContext securityContext)
221         throws IOException JavaDoc, SecurityNotAvailableException {
222         return body.getPolicy(securityContext);
223     }
224
225     public ArrayList JavaDoc getEntities() throws SecurityNotAvailableException, IOException JavaDoc {
226             return body.getEntities();
227         }
228
229     
230     //
231
// -- PRIVATE METHODS -----------------------------------------------
232
//
233
//
234
// -- SERIALIZATION -----------------------------------------------
235
//
236
private void writeObject(java.io.ObjectOutputStream JavaDoc out)
237         throws java.io.IOException JavaDoc {
238         // long startTime=System.currentTimeMillis();
239
//System.out.println("i am in serialization");
240
out.defaultWriteObject();
241         //System.out.println("i am in serialization");
242
//long endTime=System.currentTimeMillis();
243
//System.out.println(" SERIALIZATION OF REMOTEBODYIMPL lasted " + (endTime - startTime));
244
}
245
246     // private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
247
// in.defaultReadObject();
248
// }
249
// */
250
}
251
Popular Tags