org/objectweb/proactive/core/filetransfer/FileTransferEngine.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.core.filetransfer;
00032 
00033 import java.io.IOException;
00034 import java.util.Vector;
00035 
00036 import org.apache.log4j.Logger;
00037 import org.objectweb.proactive.ActiveObjectCreationException;
00038 import org.objectweb.proactive.ProActive;
00039 import org.objectweb.proactive.core.node.Node;
00040 import org.objectweb.proactive.core.node.NodeException;
00041 import org.objectweb.proactive.core.util.log.Loggers;
00042 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00043 
00044 
00052 public class FileTransferEngine {
00053     //Not serializable on purpose: This is a service AO that cannot migrate!!
00054     protected static Logger logger = ProActiveLogger.getLogger(Loggers.FILETRANSFER);
00055     static FileTransferEngine singletonFTE = getFileTransferEngine();
00056     public Vector<FileTransferService> ftsPool;
00057 
00058     public FileTransferEngine() {
00059     }
00060 
00061     public void init() {
00062         ftsPool = new Vector<FileTransferService>();
00063     }
00064 
00065     public FileTransferService getFTS()
00066         throws ActiveObjectCreationException, NodeException {
00067         if (!ftsPool.isEmpty()) {
00068             return ftsPool.remove(0);
00069         }
00070 
00071         FileTransferService localFTS = (FileTransferService) ProActive.newActive(FileTransferService.class.getName(),
00072                 null);
00073         setImmediateServices(localFTS);
00074 
00075         return localFTS;
00076     }
00077 
00078     //TODO improove this method to getFTS on remote nodes from a pool
00079     public FileTransferService getFTS(Node node)
00080         throws ActiveObjectCreationException, NodeException {
00081         FileTransferService remoteFTS = (FileTransferService) ProActive.newActive(FileTransferService.class.getName(),
00082                 null, node);
00083 
00084         setImmediateServices(remoteFTS);
00085         return remoteFTS;
00086     }
00087 
00088     public FileTransferService getFTS(String srcNodeURL)
00089         throws ActiveObjectCreationException, NodeException {
00090         FileTransferService remoteFTS = (FileTransferService) ProActive.newActive(FileTransferService.class.getName(),
00091                 null, srcNodeURL);
00092 
00093         setImmediateServices(remoteFTS);
00094         return remoteFTS;
00095     }
00096 
00097     private void setImmediateServices(FileTransferService fts) {
00098         try {
00099             ProActive.setImmediateService(fts, "requestFileTransfer",
00100                 new Class[] { FileTransferRequest.class });
00101             ProActive.setImmediateService(fts, "getFileTransferRequestStatus",
00102                 new Class[] { FileTransferRequest.class });
00103         } catch (IOException e1) {
00104             logger.error(
00105                 "Unable to activate immediate service on method: FileTransferService.requestFileTransfer(...)");
00106             e1.printStackTrace();
00107         }
00108     }
00109 
00110     public void putFTS(FileTransferService fts) {
00111         ftsPool.add(fts);
00112     }
00113 
00114     //TODO improove this method using ProActive
00115     static synchronized public FileTransferEngine getFileTransferEngine() {
00116         if (singletonFTE == null) {
00117             try {
00118                 singletonFTE = (FileTransferEngine) ProActive.newActive(FileTransferEngine.class.getName(),
00119                         null);
00120             } catch (Exception e) {
00121                 e.printStackTrace();
00122             }
00123             singletonFTE.init();
00124         }
00125         return singletonFTE;
00126     }
00127 
00128     public synchronized static FileTransferEngine getFileTransferEngine(
00129         Node node) {
00130         try {
00131             return (FileTransferEngine) ProActive.lookupActive(FileTransferEngine.class.getName(),
00132                 node.getNodeInformation().getURL());
00133         } catch (Exception e) {
00134             e.printStackTrace();
00135         }
00136         return null;
00137     }
00138 }

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