org/objectweb/proactive/branchnbound/core/queue/TaskQueue.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.branchnbound.core.queue;
00032 
00033 import java.io.InputStream;
00034 import java.io.OutputStream;
00035 import java.io.Serializable;
00036 import java.util.Collection;
00037 import java.util.Vector;
00038 
00039 import org.apache.log4j.Logger;
00040 import org.objectweb.proactive.branchnbound.core.Result;
00041 import org.objectweb.proactive.branchnbound.core.Task;
00042 import org.objectweb.proactive.branchnbound.core.exception.NoResultsException;
00043 import org.objectweb.proactive.core.util.log.Loggers;
00044 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00045 import org.objectweb.proactive.core.util.wrapper.BooleanMutableWrapper;
00046 import org.objectweb.proactive.core.util.wrapper.BooleanWrapper;
00047 import org.objectweb.proactive.core.util.wrapper.IntMutableWrapper;
00048 
00049 
00059 public abstract class TaskQueue implements Serializable {
00060 
00062     public final static Logger logger = ProActiveLogger.getLogger(Loggers.P2P_SKELETONS_MANAGER);
00063 
00065     private Result bestCurrentResult;
00066 
00072     public abstract void addAll(Collection tasks);
00073 
00077     public abstract IntMutableWrapper size();
00078 
00082     public abstract BooleanMutableWrapper hasNext();
00083 
00088     public abstract Task next();
00089 
00093     public abstract void flushAll();
00094 
00099     public abstract BooleanWrapper isHungry();
00100 
00106     public abstract void setHungryLevel(int level);
00107 
00114     public abstract void backupTasks(Task rootTask, Vector pendingTasks,
00115         OutputStream backupOutputStream);
00116 
00121     public abstract void loadTasks(InputStream taskFile);
00122 
00129     public abstract Task getRootTaskFromBackup();
00130 
00135     public abstract void addResult(Result result);
00136 
00140     public abstract IntMutableWrapper howManyResults();
00141 
00145     public abstract Collection getAllResults();
00146 
00151     public abstract void backupResults(OutputStream backupResultFile);
00152 
00157     public abstract void loadResults(InputStream backupResultFile);
00158 
00163     public abstract void addTask(Task t);
00164 
00170     public void informNewBestResult(Result newBest) {
00171         if ((this.bestCurrentResult == null) ||
00172                 newBest.isBetterThan(this.bestCurrentResult)) {
00173             this.bestCurrentResult = newBest;
00174             if (logger.isInfoEnabled()) {
00175                 logger.info("A new best result was found: " +
00176                     this.bestCurrentResult);
00177             }
00178         }
00179     }
00180 
00184     public Result getBestCurrentResult() {
00185         if (this.bestCurrentResult != null) {
00186             return this.bestCurrentResult;
00187         }
00188         return new Result(new NoResultsException());
00189     }
00190 }

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