org/objectweb/proactive/core/body/ft/servers/FTServer.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.body.ft.servers;
00032 
00033 import java.rmi.RemoteException;
00034 import java.rmi.server.UnicastRemoteObject;
00035 import java.util.ArrayList;
00036 
00037 import org.apache.log4j.Logger;
00038 import org.objectweb.proactive.core.UniqueID;
00039 import org.objectweb.proactive.core.body.UniversalBody;
00040 import org.objectweb.proactive.core.body.ft.checkpointing.Checkpoint;
00041 import org.objectweb.proactive.core.body.ft.checkpointing.CheckpointInfo;
00042 import org.objectweb.proactive.core.body.ft.message.HistoryUpdater;
00043 import org.objectweb.proactive.core.body.ft.message.MessageInfo;
00044 import org.objectweb.proactive.core.body.ft.servers.faultdetection.FaultDetector;
00045 import org.objectweb.proactive.core.body.ft.servers.location.LocationServer;
00046 import org.objectweb.proactive.core.body.ft.servers.recovery.RecoveryProcess;
00047 import org.objectweb.proactive.core.body.ft.servers.resource.ResourceServer;
00048 import org.objectweb.proactive.core.body.ft.servers.storage.CheckpointServer;
00049 import org.objectweb.proactive.core.body.ft.servers.util.ActiveQueueJob;
00050 import org.objectweb.proactive.core.body.ft.servers.util.JobBarrier;
00051 import org.objectweb.proactive.core.body.reply.Reply;
00052 import org.objectweb.proactive.core.body.request.Request;
00053 import org.objectweb.proactive.core.node.Node;
00054 import org.objectweb.proactive.core.util.log.Loggers;
00055 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00056 
00057 
00064 public class FTServer extends UnicastRemoteObject implements FaultDetector,
00065     LocationServer, RecoveryProcess, ResourceServer, CheckpointServer {
00066     //logger
00067     protected static Logger logger = ProActiveLogger.getLogger(Loggers.FAULT_TOLERANCE);
00068 
00070     public static final int DEFAULT_PORT = 1100;
00071 
00073     public static final int DEFAULT_FDETECT_SCAN_PERIOD = 10000;
00074 
00076     public static final String DEFAULT_SERVER_NAME = "FTServer";
00077 
00078     // internal servers
00079     private FaultDetector faultDetector;
00080     private LocationServer locationServer;
00081     private RecoveryProcess recoveryProcess;
00082     private ResourceServer resourceServer;
00083     private CheckpointServer checkpointServer;
00084 
00088     public FTServer() throws RemoteException {
00089         super();
00090         // this.killingQueue.start();
00091     }
00092 
00097     public void init(FaultDetector fd, LocationServer ls, RecoveryProcess rp,
00098         ResourceServer rs, CheckpointServer cs) {
00099         this.faultDetector = fd;
00100         this.locationServer = ls;
00101         this.recoveryProcess = rp;
00102         this.resourceServer = rs;
00103         this.checkpointServer = cs;
00104     }
00105 
00109 
00113     public boolean isUnreachable(UniversalBody body) throws RemoteException {
00114         return this.faultDetector.isUnreachable(body);
00115     }
00116 
00120     public void startFailureDetector() throws RemoteException {
00121         this.faultDetector.startFailureDetector();
00122     }
00123 
00127     public void suspendFailureDetector() throws RemoteException {
00128         this.faultDetector.suspendFailureDetector();
00129     }
00130 
00134     public void stopFailureDetector() throws RemoteException {
00135         this.faultDetector.stopFailureDetector();
00136     }
00137 
00141     public void forceDetection() throws RemoteException {
00142         this.faultDetector.forceDetection();
00143     }
00144 
00148     public UniversalBody searchObject(UniqueID id, UniversalBody oldLocation,
00149         UniqueID caller) throws RemoteException {
00150         return this.locationServer.searchObject(id, oldLocation, caller);
00151     }
00152 
00156     public void updateLocation(UniqueID id, UniversalBody newLocation)
00157         throws RemoteException {
00158         this.locationServer.updateLocation(id, newLocation);
00159     }
00160 
00164     public ArrayList getAllLocations() throws RemoteException {
00165         return this.locationServer.getAllLocations();
00166     }
00167 
00171     public UniversalBody getLocation(UniqueID id) throws RemoteException {
00172         return this.locationServer.getLocation(id);
00173     }
00174 
00178     public void register(UniqueID id) throws RemoteException {
00179         this.recoveryProcess.register(id);
00180     }
00181 
00185     public void unregister(UniqueID id) throws RemoteException {
00186         this.recoveryProcess.unregister(id);
00187     }
00188 
00192     public void failureDetected(UniqueID id) throws RemoteException {
00193         this.recoveryProcess.failureDetected(id);
00194     }
00195 
00199     public void updateState(UniqueID id, int state) throws RemoteException {
00200         this.recoveryProcess.updateState(id, state);
00201     }
00202 
00206     public int getSystemSize() throws RemoteException {
00207         return this.recoveryProcess.getSystemSize();
00208     }
00209 
00213     public void submitJob(ActiveQueueJob job) throws RemoteException {
00214         this.recoveryProcess.submitJob(job);
00215     }
00216 
00220     public JobBarrier submitJobWithBarrier(ActiveQueueJob job)
00221         throws RemoteException {
00222         return this.recoveryProcess.submitJobWithBarrier(job);
00223     }
00224 
00228     public void addFreeNode(Node n) throws RemoteException {
00229         this.resourceServer.addFreeNode(n);
00230     }
00231 
00235     public Node getFreeNode() throws RemoteException {
00236         return this.resourceServer.getFreeNode();
00237     }
00238 
00243     // Commented code is used to benchmark recovery time. A failure is triggered
00244     // artifially by sending a kill message to one active object.
00245     //public static final int numCkpt = 4; // totalWorker * failureFrequency
00246     //public static final int numberOfWorker = 4;
00247     //public static final long timeToWait = 45000; // TTC/2
00248     //public static final int totalFailure = 1;
00249     //private int ckptCounter = 1;
00250     //private int failureCounter = 1;
00251     //private int firstCkptCounter = numberOfWorker;
00252     //private ActiveQueue killingQueue = new ActiveQueue("Killing thread");
00253     public int storeCheckpoint(Checkpoint c, int incarnation)
00254         throws RemoteException {
00255         //this.firstCkptCounter--;
00256         //if (this.firstCkptCounter < 0){
00257         //    if ((this.failureCounter <= totalFailure) && 
00258         //            ((ckptCounter) == numCkpt)) {
00259         //        this.killingQueue.addJob(
00260         //                new KillerJob(this,this.getLocation(c.getBodyID()),timeToWait));
00261         //        this.ckptCounter=0; // the following ++ set it to 1 ...
00262         //        this.failureCounter++;
00263         //    }
00264         //    this.ckptCounter++;
00265         //}
00266         return this.checkpointServer.storeCheckpoint(c, incarnation);
00267     }
00268 
00272     public Checkpoint getCheckpoint(UniqueID id, int sequenceNumber)
00273         throws RemoteException {
00274         return this.checkpointServer.getCheckpoint(id, sequenceNumber);
00275     }
00276 
00280     public Checkpoint getLastCheckpoint(UniqueID id) throws RemoteException {
00281         return this.checkpointServer.getLastCheckpoint(id);
00282     }
00283 
00287     public void addInfoToCheckpoint(CheckpointInfo ci, UniqueID id,
00288         int sequenceNumber, int incarnation) throws RemoteException {
00289         this.checkpointServer.addInfoToCheckpoint(ci, id, sequenceNumber,
00290             incarnation);
00291     }
00292 
00296     public CheckpointInfo getInfoFromCheckpoint(UniqueID id, int sequenceNumber)
00297         throws RemoteException {
00298         return this.checkpointServer.getInfoFromCheckpoint(id, sequenceNumber);
00299     }
00300 
00304     public void commitHistory(HistoryUpdater rh) throws RemoteException {
00305         this.checkpointServer.commitHistory(rh);
00306     }
00307 
00311     public void outputCommit(MessageInfo mi) throws RemoteException {
00312         this.checkpointServer.outputCommit(mi);
00313     }
00314 
00318     public String getServerCodebase() throws RemoteException {
00319         return this.checkpointServer.getServerCodebase();
00320     }
00321 
00325     public void storeRequest(UniqueID receiverId, Request request)
00326         throws RemoteException {
00327         this.checkpointServer.storeRequest(receiverId, request);
00328     }
00329 
00333     public void storeReply(UniqueID receiverID, Reply reply)
00334         throws RemoteException {
00335         this.checkpointServer.storeReply(receiverID, reply);
00336     }
00337 
00341 
00345     public CheckpointServer getCheckpointServer() {
00346         return checkpointServer;
00347     }
00348 
00352     public void setCheckpointServer(CheckpointServer checkpointServer) {
00353         this.checkpointServer = checkpointServer;
00354     }
00355 
00359     public FaultDetector getFaultDetector() {
00360         return faultDetector;
00361     }
00362 
00366     public void setFaultDetector(FaultDetector faultDetector) {
00367         this.faultDetector = faultDetector;
00368     }
00369 
00373     public LocationServer getLocationServer() {
00374         return locationServer;
00375     }
00376 
00380     public void setLocationServer(LocationServer locationServer) {
00381         this.locationServer = locationServer;
00382     }
00383 
00387     public RecoveryProcess getRecoveryProcess() {
00388         return recoveryProcess;
00389     }
00390 
00394     public void setRecoveryProcess(RecoveryProcess recoveryProcess) {
00395         this.recoveryProcess = recoveryProcess;
00396     }
00397 
00401     public ResourceServer getResourceServer() {
00402         return resourceServer;
00403     }
00404 
00408     public void setResourceServer(ResourceServer resourceServer) {
00409         this.resourceServer = resourceServer;
00410     }
00411 
00415     public void initialize() throws RemoteException {
00416         logger.info("[GLOBAL] Reinitializing server ...");
00417         this.checkpointServer.initialize();
00418         this.locationServer.initialize();
00419         this.recoveryProcess.initialize();
00420         this.resourceServer.initialize();
00421         logger.info("[GLOBAL] Server reinitialized");
00422     }
00423 }

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