org/objectweb/proactive/ext/mixedlocation/UniversalBodyWrapper.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.ext.mixedlocation;
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.core.ProActiveRuntimeException;
00039 import org.objectweb.proactive.core.UniqueID;
00040 import org.objectweb.proactive.core.body.BodyAdapter;
00041 import org.objectweb.proactive.core.body.UniversalBody;
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.exceptions.NonFunctionalException;
00047 import org.objectweb.proactive.core.exceptions.manager.NFEListener;
00048 import org.objectweb.proactive.ext.security.Communication;
00049 import org.objectweb.proactive.ext.security.SecurityContext;
00050 import org.objectweb.proactive.ext.security.crypto.KeyExchangeException;
00051 import org.objectweb.proactive.ext.security.exceptions.RenegotiateSessionException;
00052 import org.objectweb.proactive.ext.security.exceptions.SecurityNotAvailableException;
00053 import org.objectweb.proactive.ext.security.securityentity.Entity;
00054 
00055 
00056 public class UniversalBodyWrapper implements UniversalBody, Runnable {
00057     protected UniversalBody wrappedBody;
00058     protected long time;
00059     protected UniqueID id;
00060     protected boolean stop;
00061     protected long creationTime;
00062     protected String jobID;
00063 
00064     //protected  Thread t ;
00065 
00071     public UniversalBodyWrapper(UniversalBody body, long time) {
00072         this.wrappedBody = body;
00073         this.time = time;
00074         this.creationTime = System.currentTimeMillis();
00075         //     t =new Thread(this);
00076         this.id = this.wrappedBody.getID();
00077 
00078         //   t.start();
00079     }
00080 
00081     public int receiveRequest(Request request)
00082         throws IOException, RenegotiateSessionException {
00083         //       System.out.println("UniversalBodyWrapper.receiveRequest");
00084         if (this.wrappedBody == null) {
00085             throw new IOException();
00086         }
00087 
00088         //the forwarder should be dead
00089         if (System.currentTimeMillis() > (this.creationTime + this.time)) {
00090             //   this.updateServer();
00091             //   this.wrappedBody = null;
00092             //  t.start();
00093             //   System.gc();
00094             throw new IOException();
00095         } else {
00096             try {
00097                 return this.wrappedBody.receiveRequest(request);
00098             } catch (IOException e) {
00099                 e.printStackTrace();
00100                 throw e;
00101             }
00102         }
00103 
00104         //      this.stop();
00105     }
00106 
00107     public int receiveReply(Reply r) throws IOException {
00108         return this.wrappedBody.receiveReply(r);
00109     }
00110 
00114     public void terminate() throws IOException {
00115         this.wrappedBody.terminate();
00116     }
00117 
00118     public String getNodeURL() {
00119         return this.wrappedBody.getNodeURL();
00120     }
00121 
00122     public UniqueID getID() {
00123         return this.id;
00124     }
00125 
00126     public String getJobID() {
00127         if (jobID == null) {
00128             jobID = wrappedBody.getJobID();
00129         }
00130 
00131         return jobID;
00132     }
00133 
00134     public void updateLocation(UniqueID id, UniversalBody body)
00135         throws IOException {
00136         this.wrappedBody.updateLocation(id, body);
00137     }
00138 
00139     public BodyAdapter getRemoteAdapter() {
00140         return this.wrappedBody.getRemoteAdapter();
00141     }
00142 
00143     public void enableAC() throws java.io.IOException {
00144         this.wrappedBody.enableAC();
00145     }
00146 
00147     public void disableAC() throws java.io.IOException {
00148         this.wrappedBody.disableAC();
00149     }
00150 
00151     public void setImmediateService(String methodName)
00152         throws java.io.IOException {
00153         this.wrappedBody.setImmediateService(methodName);
00154     }
00155 
00156     public void removeImmediateService(String methodName,
00157         Class[] parametersTypes) throws IOException {
00158         this.wrappedBody.removeImmediateService(methodName, parametersTypes);
00159     }
00160 
00161     public void setImmediateService(String methodName, Class[] parametersTypes)
00162         throws IOException {
00163         this.wrappedBody.setImmediateService(methodName, parametersTypes);
00164     }
00165 
00166     protected void updateServer() {
00167         //        System.out.println("UniversalBodyWrapper.updateServer");
00168         //  LocationServer server = LocationServerFactory.getLocationServer();
00169         //        try {
00170         //            server.updateLocation(id, this.wrappedBody);
00171         //        } catch (Exception e) {
00172         //            System.out.println("XXXX Error XXXX");
00173         //           // e.printStackTrace();
00174         //        }
00175     }
00176 
00177     //protected synchronized void stop() {
00178     // this.stop=true;  
00179     // this.notifyAll();
00180     //}
00181     //
00182     //protected synchronized void waitForStop(long time) {
00183     //  if (!this.stop) {
00184     //   try {
00185     //           wait(time);    
00186     //  } catch (InterruptedException e) {
00187     //          e.printStackTrace();
00188     //  }
00189     //  }
00190     //  
00191     //}
00192     public void run() {
00193         //        System.out.println("UniversalBodyWrapper.run life expectancy " + time);
00194         try {
00195             // Thread.currentThread().sleep(time);
00196             //  this.waitForStop(time);
00197         } catch (Exception e) {
00198             e.printStackTrace();
00199         }
00200 
00201         //        System.out.println("UniversalBodyWrapper.run end of life...");
00202         this.updateServer();
00203         this.wrappedBody = null;
00204         //        System.gc();
00205     }
00206 
00207     //    /**
00208     //     * Get information about the handlerizable object
00209     //     * @return information about the handlerizable object
00210     //     */
00211     //    public String getHandlerizableInfo() throws java.io.IOException {
00212     //        return this.wrappedBody.getHandlerizableInfo();
00213     //    }
00214     //
00215     //    /** Give a reference to a local map of handlers
00216     //     * @return A reference to a map of handlers
00217     //     */
00218     //    public HashMap getHandlersLevel() throws java.io.IOException {
00219     //        return this.wrappedBody.getHandlersLevel();
00220     //    }
00221     //
00222     //    /**
00223     //     * Clear the local map of handlers
00224     //     */
00225     //    public void clearHandlersLevel() throws java.io.IOException {
00226     //        this.wrappedBody.clearHandlersLevel();
00227     //    }
00228     //
00229     //    /** Set a new handler within the table of the Handlerizable Object
00230     //     * @param exception A class of non functional exception. It is a subclass of <code>NonFunctionalException</code>.
00231     //     * @param handler A class of handler associated with a class of non functional exception.
00232     //     */
00233     //    public void setExceptionHandler(Handler handler, Class exception)
00234     //        throws java.io.IOException {
00235     //        this.wrappedBody.setExceptionHandler(handler, exception);
00236     //    }
00237     //
00238     //    /** Remove a handler from the table of the Handlerizable Object
00239     //     * @param exception A class of non functional exception. It is a subclass of <code>NonFunctionalException</code>.
00240     //     * @return The removed handler or null
00241     //     */
00242     //    public Handler unsetExceptionHandler(Class exception)
00243     //        throws java.io.IOException {
00244     //        return this.wrappedBody.unsetExceptionHandler(exception);
00245     //    }
00246     //  NFEProducer implementation
00247     public void addNFEListener(NFEListener listener) {
00248         wrappedBody.addNFEListener(listener);
00249     }
00250 
00251     public void removeNFEListener(NFEListener listener) {
00252         wrappedBody.removeNFEListener(listener);
00253     }
00254 
00255     public int fireNFE(NonFunctionalException e) {
00256         return wrappedBody.fireNFE(e);
00257     }
00258 
00259     // SECURITY
00260     public void terminateSession(long sessionID)
00261         throws java.io.IOException, SecurityNotAvailableException {
00262         wrappedBody.terminateSession(sessionID);
00263     }
00264 
00265     public X509Certificate getCertificate()
00266         throws java.io.IOException, SecurityNotAvailableException {
00267         return wrappedBody.getCertificate();
00268     }
00269 
00270     public long startNewSession(Communication policy)
00271         throws java.io.IOException, RenegotiateSessionException, 
00272             SecurityNotAvailableException {
00273         return wrappedBody.startNewSession(policy);
00274     }
00275 
00276     public PublicKey getPublicKey()
00277         throws java.io.IOException, SecurityNotAvailableException {
00278         return wrappedBody.getPublicKey();
00279     }
00280 
00281     public byte[] randomValue(long sessionID, byte[] cl_rand)
00282         throws IOException, SecurityNotAvailableException, 
00283             RenegotiateSessionException {
00284         return wrappedBody.randomValue(sessionID, cl_rand);
00285     }
00286 
00287     public byte[][] publicKeyExchange(long sessionID, byte[] my_pub,
00288         byte[] my_cert, byte[] sig_code)
00289         throws IOException, SecurityNotAvailableException, 
00290             RenegotiateSessionException, KeyExchangeException {
00291         return wrappedBody.publicKeyExchange(sessionID, my_pub, my_cert,
00292             sig_code);
00293     }
00294 
00295     public byte[][] secretKeyExchange(long sessionID, byte[] tmp, byte[] tmp1,
00296         byte[] tmp2, byte[] tmp3, byte[] tmp4)
00297         throws IOException, SecurityNotAvailableException, 
00298             RenegotiateSessionException {
00299         return wrappedBody.secretKeyExchange(sessionID, tmp, tmp1, tmp2, tmp3,
00300             tmp4);
00301     }
00302 
00303     /* (non-Javadoc)
00304      * @see org.objectweb.proactive.core.body.UniversalBody#getCertificateEncoded()
00305      */
00306     public byte[] getCertificateEncoded()
00307         throws IOException, SecurityNotAvailableException {
00308         return wrappedBody.getCertificateEncoded();
00309     }
00310 
00311     /* (non-Javadoc)
00312      * @see org.objectweb.proactive.core.body.UniversalBody#getPolicy(org.objectweb.proactive.ext.security.SecurityContext)
00313      */
00314     public SecurityContext getPolicy(SecurityContext securityContext)
00315         throws SecurityNotAvailableException, IOException {
00316         return wrappedBody.getPolicy(securityContext);
00317     }
00318 
00319     public ArrayList<Entity> getEntities()
00320         throws SecurityNotAvailableException, IOException {
00321         return wrappedBody.getEntities();
00322     }
00323 
00327     public Object receiveFTMessage(FTMessage ev) throws IOException {
00328         return this.wrappedBody.receiveFTMessage(ev);
00329     }
00330 
00331     public void createShortcut(Shortcut shortcut) throws IOException {
00332         // TODO implement
00333         throw new ProActiveRuntimeException(
00334             "create shortcut method not implemented yet");
00335     }
00336 }

Generated on Mon Jan 22 15:16:10 2007 for ProActive by  doxygen 1.5.1