KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > body > jini > JiniBodyImpl


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.jini;
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 jini calls. This helps isolate JINI-specific
59  * code into a small set of specific classes, thus enabling reuse if we one day decide to switch
60  * to anothe jini objects library.
61  */

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

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

213     public byte[] getCertificateEncoded()
214         throws IOException JavaDoc, SecurityNotAvailableException {
215         return body.getCertificateEncoded();
216     }
217
218     public SecurityContext getPolicy(SecurityContext securityContext)
219         throws IOException JavaDoc, SecurityNotAvailableException {
220         return body.getPolicy(securityContext);
221     }
222     
223     public ArrayList JavaDoc getEntities() throws SecurityNotAvailableException, IOException JavaDoc {
224             return body.getEntities();
225         }
226
227     //
228
// -- PRIVATE METHODS -----------------------------------------------
229
//
230
//
231
// -- SERIALIZATION -----------------------------------------------
232
//
233

234     /*
235           private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
236           long startTime=System.currentTimeMillis();
237           out.defaultWriteObject();
238           long endTime=System.currentTimeMillis();
239           System.out.println(" SERIALIZATION OF JINIBODYIMPL lasted " + (endTime - startTime));
240
241           }
242
243
244           private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
245           in.defaultReadObject();
246           }
247     */

248 }
249
Popular Tags