00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.body;
00032
00033 import java.io.IOException;
00034 import java.security.PublicKey;
00035 import java.security.cert.X509Certificate;
00036 import java.util.ArrayList;
00037
00038 import org.objectweb.proactive.Body;
00039 import org.objectweb.proactive.core.ProActiveException;
00040 import org.objectweb.proactive.core.ProActiveRuntimeException;
00041 import org.objectweb.proactive.core.UniqueID;
00042 import org.objectweb.proactive.core.body.ft.internalmsg.FTMessage;
00043 import org.objectweb.proactive.core.body.reply.Reply;
00044 import org.objectweb.proactive.core.body.request.Request;
00045 import org.objectweb.proactive.core.component.request.Shortcut;
00046 import org.objectweb.proactive.core.config.ProActiveConfiguration;
00047 import org.objectweb.proactive.core.exceptions.NonFunctionalException;
00048 import org.objectweb.proactive.core.exceptions.manager.NFEListener;
00049 import org.objectweb.proactive.core.runtime.ProActiveRuntimeForwarderImpl;
00050 import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl;
00051 import org.objectweb.proactive.ext.security.Communication;
00052 import org.objectweb.proactive.ext.security.SecurityContext;
00053 import org.objectweb.proactive.ext.security.crypto.KeyExchangeException;
00054 import org.objectweb.proactive.ext.security.exceptions.RenegotiateSessionException;
00055 import org.objectweb.proactive.ext.security.exceptions.SecurityNotAvailableException;
00056 import org.objectweb.proactive.ext.security.securityentity.Entity;
00057
00058
00070 public class BodyAdapterForwarder extends BodyAdapter implements Cloneable,
00071 RemoteBody {
00072
00076 protected RemoteBodyForwarder proxiedRemoteBody;
00077
00082 public BodyAdapterForwarder(RemoteBodyForwarder remoteBodyForwarder) {
00083 this.proxiedRemoteBody = remoteBodyForwarder;
00084 bodyID = null;
00085 }
00086
00092 public BodyAdapterForwarder(RemoteBodyForwarder remoteBodyForwarder,
00093 UniqueID id) {
00094 this.proxiedRemoteBody = remoteBodyForwarder;
00095
00096 try {
00097 this.bodyID = id;
00098 this.jobID = remoteBodyForwarder.getJobID(id);
00099 } catch (IOException e) {
00100 jobID = null;
00101 System.err.println("Connexion to RemoteBodyForwarder(id=" + id +
00102 "failled, this BodyAdapterForwarder will be unusable");
00103 System.err.println(
00104 "You probably need to check your hierarchical deployment configuration file.");
00105 }
00106 }
00107
00114 public BodyAdapterForwarder(BodyAdapterForwarder defaultAdapterForwarder,
00115 BodyAdapter remoteAdapter) {
00116 this.proxiedRemoteBody = defaultAdapterForwarder.proxiedRemoteBody;
00117 this.bodyID = remoteAdapter.bodyID;
00118 this.jobID = remoteAdapter.jobID;
00119 }
00120
00121 private void readObject(java.io.ObjectInputStream in)
00122 throws java.io.IOException, ClassNotFoundException {
00123 in.defaultReadObject();
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 if (ProActiveConfiguration.isForwarder()) {
00136 ProActiveRuntimeForwarderImpl partf = (ProActiveRuntimeForwarderImpl) ProActiveRuntimeImpl.getProActiveRuntime();
00137
00138 try {
00139 partf.getBodyForwarder().add((BodyAdapterForwarder) this.clone());
00140 this.proxiedRemoteBody = partf.getBodyAdapterForwarder().proxiedRemoteBody;
00141 } catch (CloneNotSupportedException e) {
00142 e.printStackTrace();
00143 UniversalBody.bodyLogger.warn(
00144 "Cannot create a forwarder for this RemoteObject.");
00145 }
00146 }
00147 }
00148
00149
00150
00151
00152 public void changeProxiedBody(Body newBody) throws IOException {
00153 this.proxiedRemoteBody.changeProxiedBody(bodyID, newBody);
00154 }
00155
00156 public UniversalBody lookup(String url) throws java.io.IOException {
00157 return this.proxiedRemoteBody.lookup(bodyID, url);
00158 }
00159
00160 public void register(String url) throws java.io.IOException {
00161 this.proxiedRemoteBody.register(bodyID, url);
00162 }
00163
00164 public void unregister(String url) throws java.io.IOException {
00165 this.proxiedRemoteBody.unregister(bodyID, url);
00166 }
00167
00168 public boolean equals(Object o) {
00169 if (!(o instanceof BodyAdapterForwarder)) {
00170 return false;
00171 }
00172
00173 BodyAdapterForwarder rba = (BodyAdapterForwarder) o;
00174
00175 return rba.bodyID == this.bodyID;
00176 }
00177
00178 public int hashCode() {
00179 return bodyID.hashCode();
00180 }
00181
00182 protected void construct(BodyAdapterForwarder localBody,
00183 BodyAdapter remoteBody, UniqueID id) throws ProActiveException {
00184 this.bodyID = id;
00185 this.proxiedRemoteBody = localBody.proxiedRemoteBody;
00186
00187 if (BodyAdapter.bodyLogger.isDebugEnabled()) {
00188 BodyAdapter.bodyLogger.debug(proxiedRemoteBody.getClass());
00189 }
00190
00191 this.bodyID = remoteBody.getID();
00192 this.jobID = remoteBody.getJobID();
00193 }
00194
00195
00196
00197
00198 public String getJobID() {
00199 return jobID;
00200 }
00201
00202
00203
00204
00205 public int receiveRequest(Request request)
00206 throws IOException, RenegotiateSessionException {
00207 return proxiedRemoteBody.receiveRequest(bodyID, request);
00208 }
00209
00213 public int receiveReply(Reply r) throws IOException {
00214 return proxiedRemoteBody.receiveReply(bodyID, r);
00215 }
00216
00220 public String getNodeURL() {
00221 try {
00222 return proxiedRemoteBody.getNodeURL(bodyID);
00223 } catch (IOException e) {
00224 return "cannot contact the body to get the nodeURL";
00225 }
00226 }
00227
00231 public UniqueID getID() {
00232 return bodyID;
00233 }
00234
00238 public void updateLocation(UniqueID uid, UniversalBody body)
00239 throws IOException {
00240 proxiedRemoteBody.updateLocation(bodyID, uid, body);
00241 }
00242
00246 public void createShortcut(Shortcut shortcut) throws IOException {
00247
00248 throw new ProActiveRuntimeException(
00249 "create shortcut method not implemented yet");
00250 }
00251
00255 public BodyAdapter getRemoteAdapter() {
00256 try {
00257 return proxiedRemoteBody.getRemoteAdapter(bodyID);
00258 } catch (IOException e) {
00259 e.printStackTrace();
00260
00261 return null;
00262 }
00263 }
00264
00268 public void terminate() throws IOException {
00269 proxiedRemoteBody.terminate(bodyID);
00270 }
00271
00275 public void enableAC() throws IOException {
00276 proxiedRemoteBody.enableAC(bodyID);
00277 }
00278
00282 public void disableAC() throws IOException {
00283 proxiedRemoteBody.disableAC(bodyID);
00284 }
00285
00289 public void setImmediateService(String methodName)
00290 throws IOException {
00291 proxiedRemoteBody.setImmediateService(bodyID, methodName);
00292 }
00293
00297 public void setImmediateService(String methodName, Class[] parametersTypes)
00298 throws IOException {
00299 proxiedRemoteBody.setImmediateService(bodyID, methodName,
00300 parametersTypes);
00301 }
00302
00306 public void removeImmediateService(String methodName,
00307 Class[] parametersTypes) throws IOException {
00308 proxiedRemoteBody.removeImmediateService(bodyID, methodName,
00309 parametersTypes);
00310 }
00311
00315 public void terminateSession(long sessionID)
00316 throws IOException, SecurityNotAvailableException {
00317 proxiedRemoteBody.terminateSession(bodyID, sessionID);
00318 }
00319
00323 public X509Certificate getCertificate()
00324 throws SecurityNotAvailableException, IOException {
00325 return proxiedRemoteBody.getCertificate(bodyID);
00326 }
00327
00331 public long startNewSession(Communication policy)
00332 throws SecurityNotAvailableException, IOException,
00333 RenegotiateSessionException {
00334 return proxiedRemoteBody.startNewSession(bodyID, policy);
00335 }
00336
00340 public PublicKey getPublicKey()
00341 throws SecurityNotAvailableException, IOException {
00342 return proxiedRemoteBody.getPublicKey(bodyID);
00343 }
00344
00348 public byte[] randomValue(long sessionID, byte[] cl_rand)
00349 throws SecurityNotAvailableException, RenegotiateSessionException,
00350 IOException {
00351 return proxiedRemoteBody.randomValue(bodyID, sessionID, cl_rand);
00352 }
00353
00357 public byte[][] secretKeyExchange(long sessionID, byte[] encodedAESKey,
00358 byte[] encodedIVParameters, byte[] encodedClientMacKey,
00359 byte[] encodedLockData, byte[] parametersSignature)
00360 throws SecurityNotAvailableException, RenegotiateSessionException,
00361 IOException {
00362 return proxiedRemoteBody.secretKeyExchange(bodyID, sessionID,
00363 encodedAESKey, encodedIVParameters, encodedClientMacKey,
00364 encodedLockData, parametersSignature);
00365 }
00366
00370 public SecurityContext getPolicy(SecurityContext securityContext)
00371 throws SecurityNotAvailableException, IOException {
00372 return proxiedRemoteBody.getPolicy(bodyID, securityContext);
00373 }
00374
00378 public byte[] getCertificateEncoded()
00379 throws SecurityNotAvailableException, IOException {
00380 return proxiedRemoteBody.getCertificateEncoded(bodyID);
00381 }
00382
00386 public ArrayList<Entity> getEntities()
00387 throws SecurityNotAvailableException, IOException {
00388 return proxiedRemoteBody.getEntities(bodyID);
00389 }
00390
00391
00392
00393
00394 public Object receiveFTMessage(FTMessage ev) throws IOException {
00395 return this.proxiedRemoteBody.receiveFTMessage(bodyID, ev);
00396 }
00397
00398
00399
00400
00401 public void addNFEListener(NFEListener listener) {
00402 try {
00403 proxiedRemoteBody.addNFEListener(bodyID, listener);
00404 } catch (IOException e) {
00405
00406 e.printStackTrace();
00407 }
00408 }
00409
00410 public void removeNFEListener(NFEListener listener) {
00411 try {
00412 proxiedRemoteBody.removeNFEListener(bodyID, listener);
00413 } catch (IOException e) {
00414
00415 e.printStackTrace();
00416 }
00417 }
00418
00419 public int fireNFE(NonFunctionalException e) {
00420 try {
00421 return proxiedRemoteBody.fireNFE(bodyID, e);
00422 } catch (IOException e1) {
00423
00424 e1.printStackTrace();
00425
00426 return 0;
00427 }
00428 }
00429
00430 public byte[][] publicKeyExchange(long sessionID, byte[] myPublicKey,
00431 byte[] myCertificate, byte[] signature)
00432 throws SecurityNotAvailableException, RenegotiateSessionException,
00433 KeyExchangeException, IOException {
00434 try {
00435 return proxiedRemoteBody.publicKeyExchange(bodyID, sessionID,
00436 myPublicKey, myCertificate, signature);
00437 } catch (IOException e1) {
00438
00439 e1.printStackTrace();
00440
00441 return null;
00442 }
00443 }
00444
00448 public String[] list(String url) throws IOException {
00449 throw new IOException ("Lookup is not implemented for this Adapter");
00450 }
00451 }