org/objectweb/proactive/core/process/AbstractSequentialListProcessDecorator.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.process;
00032 
00033 import org.objectweb.proactive.core.descriptor.services.UniversalService;
00034 import org.objectweb.proactive.core.process.filetransfer.FileTransferWorkShop;
00035 import org.objectweb.proactive.core.util.RemoteProcessMessageLogger;
00036 
00037 import java.util.ArrayList;
00038 
00039 
00048 public abstract class AbstractSequentialListProcessDecorator
00049     implements ExternalProcessDecorator {
00050     boolean isFirstElementService = false;
00051 
00052     //Array of processes
00053     protected ArrayList processes;
00054 
00055     // position of the next process to return  
00056     protected int currentProcessRank = 0;
00057 
00058     public AbstractSequentialListProcessDecorator() {
00059         processes = new ArrayList();
00060     }
00061 
00066     public void addProcessToList(ExternalProcess process) {
00067         this.processes.add(process);
00068     }
00069 
00074     public void addServiceToList(UniversalService service) {
00075         this.processes.add(service);
00076     }
00077 
00083     public void addProcessToList(int rank, ExternalProcess process) {
00084         this.processes.add(rank, process);
00085     }
00086 
00092     public void addServiceToList(int rank, UniversalService service) {
00093         this.processes.add(rank, service);
00094     }
00095 
00100     public ExternalProcess getFirstProcess() {
00101         currentProcessRank++;
00102         return (ExternalProcess) processes.get(0);
00103     }
00104 
00109     public UniversalService getFirstService() {
00110         currentProcessRank++;
00111         return (UniversalService) processes.get(0);
00112     }
00113 
00118     public ExternalProcess getNextProcess() {
00119         ExternalProcess res = null;
00120         if (currentProcessRank < processes.size()) {
00121             res = (ExternalProcess) processes.get(currentProcessRank);
00122             currentProcessRank++;
00123         }
00124         return res;
00125     }
00126 
00127     //
00128     //--------------------------Implements ExternalProcessDecorator----------------------
00129 
00133     public ExternalProcess getTargetProcess() {
00134         return ((ExternalProcessDecorator) processes.get(currentProcessRank)).getTargetProcess();
00135     }
00136 
00140     public void setTargetProcess(ExternalProcess targetProcess) {
00141         ((ExternalProcessDecorator) processes.get(currentProcessRank)).setTargetProcess(targetProcess);
00142     }
00143 
00147     public int getCompositionType() {
00148         return ((ExternalProcess) processes.get(currentProcessRank)).getCompositionType();
00149     }
00150 
00154     public void setCompositionType(int compositionType) {
00155         ((ExternalProcessDecorator) processes.get(currentProcessRank)).setCompositionType(compositionType);
00156     }
00157 
00158     public FileTransferWorkShop getFileTransferWorkShopRetrieve() {
00159 
00160         /* TODO Check if this is the correct place
00161          * implement this. Then implement it
00162          */
00163         return null;
00164     }
00165 
00166     public FileTransferWorkShop getFileTransferWorkShopDeploy() {
00167 
00168         /* TODO Check if this is the correct place
00169          * implement this. Then implement it
00170          */
00171         return null;
00172     }
00173 
00174     public void startFileTransfer() {
00175 
00176         /* TODO Check if this is the correct place
00177          * implement this. Then implement it
00178          */
00179     }
00180 
00181     public boolean isRequiredFileTransferDeployOnNodeCreation() {
00182 
00183         /* TODO Check if this is the correct place
00184          * implement this. Then implement it
00185          */
00186         return false;
00187     }
00188 
00192     public void closeStream() {
00193         ((ExternalProcess) processes.get(currentProcessRank)).closeStream();
00194     }
00195 
00199     public RemoteProcessMessageLogger getInputMessageLogger() {
00200         return ((ExternalProcess) processes.get(currentProcessRank)).getInputMessageLogger();
00201     }
00202 
00206     public RemoteProcessMessageLogger getErrorMessageLogger() {
00207         return ((ExternalProcess) processes.get(currentProcessRank)).getErrorMessageLogger();
00208     }
00209 
00213     public MessageSink getOutputMessageSink() {
00214         return ((ExternalProcess) processes.get(currentProcessRank)).getOutputMessageSink();
00215     }
00216 
00220     public void setInputMessageLogger(
00221         RemoteProcessMessageLogger inputMessageLogger) {
00222         for (int i = 0; i < processes.size(); i++) {
00223             ((ExternalProcess) processes.get(i)).setInputMessageLogger(inputMessageLogger);
00224         }
00225     }
00226 
00230     public void setErrorMessageLogger(
00231         RemoteProcessMessageLogger errorMessageLogger) {
00232         for (int i = 0; i < processes.size(); i++) {
00233             ((ExternalProcess) processes.get(i)).setErrorMessageLogger(errorMessageLogger);
00234         }
00235     }
00236 
00240     public void setOutputMessageSink(MessageSink outputMessageSink) {
00241         for (int i = 0; i < processes.size(); i++) {
00242             ((ExternalProcess) processes.get(i)).setOutputMessageSink(outputMessageSink);
00243         }
00244     }
00245 
00249     public String[] getEnvironment() {
00250         return ((ExternalProcess) processes.get(currentProcessRank)).getEnvironment();
00251     }
00252 
00256     public void setEnvironment(String[] environment) {
00257         ((ExternalProcess) processes.get(currentProcessRank)).setEnvironment(environment);
00258     }
00259 
00263     public String getUsername() {
00264         return ((ExternalProcess) processes.get(currentProcessRank)).getUsername();
00265     }
00266 
00270     public void setUsername(String username) {
00271         ((ExternalProcess) processes.get(currentProcessRank)).setUsername(username);
00272     }
00273 
00277     public String getCommand() {
00278         return null;
00279     }
00280 
00284     public String getProcessId() {
00285         return "ps";
00286     }
00287 
00291     public int getNodeNumber() {
00292         return ((ExternalProcessDecorator) processes.get(currentProcessRank)).getNodeNumber();
00293     }
00294 
00298     public UniversalProcess getFinalProcess() {
00299         return ((ExternalProcessDecorator) processes.get(currentProcessRank)).getFinalProcess();
00300     }
00301 
00302     public ArrayList getListProcess() {
00303         return this.processes;
00304     }
00305 
00309     public void stopProcess() {
00310         ((ExternalProcess) processes.get(currentProcessRank)).stopProcess();
00311     }
00312 
00316     public int waitFor() throws InterruptedException {
00317         int status = 0;
00318         status = ((ExternalProcess) processes.get(currentProcessRank)).waitFor();
00319         return status;
00320     }
00321 
00325     public boolean isStarted() {
00326         boolean started = true;
00327         started = ((ExternalProcess) processes.get(currentProcessRank)).isStarted();
00328         return started;
00329     }
00330 
00334     public boolean isFinished() {
00335         boolean finished = true;
00336         finished = ((ExternalProcess) processes.get(currentProcessRank)).isFinished();
00337         return finished;
00338     }
00339 
00340     public boolean isSequential() {
00341         return true;
00342     }
00343 
00347     public void setCommandPath(String path) {
00348         ((ExternalProcess) processes.get(currentProcessRank)).setCommandPath(path);
00349     }
00350 
00354     public String getCommandPath() {
00355         return ((ExternalProcess) processes.get(currentProcessRank)).getCommandPath();
00356     }
00357 
00358     //
00359     //-----------------protected methods----------------------------------------
00360     //
00361     protected abstract ExternalProcess createProcess();
00362 
00363     public int exitValue() throws IllegalThreadStateException {
00364         // TODO Auto-generated method stub
00365         return 0;
00366     }
00367 
00368     public void setStarted(boolean isStarted) {
00369         // TODO Auto-generated method stub
00370     }
00371 
00372     public void setFinished(boolean isStarted) {
00373         // TODO Auto-generated method stub
00374     }
00375 
00376     public boolean isFirstElementIsService() {
00377         return isFirstElementService;
00378     }
00379 
00380     public void setFirstElementIsService(boolean isFirstElementIsService) {
00381         this.isFirstElementService = isFirstElementIsService;
00382     }
00383 }

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