org/objectweb/proactive/core/body/ft/servers/recovery/RecoveryProcessImpl.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.recovery;
00032 
00033 import java.rmi.RemoteException;
00034 import java.util.Hashtable;
00035 import java.util.Iterator;
00036 import java.util.Vector;
00037 
00038 import org.apache.log4j.Logger;
00039 import org.objectweb.proactive.core.UniqueID;
00040 import org.objectweb.proactive.core.body.ft.servers.FTServer;
00041 import org.objectweb.proactive.core.body.ft.servers.util.ActiveQueue;
00042 import org.objectweb.proactive.core.body.ft.servers.util.ActiveQueueJob;
00043 import org.objectweb.proactive.core.body.ft.servers.util.JobBarrier;
00044 import org.objectweb.proactive.core.util.log.Loggers;
00045 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00046 
00047 
00052 public abstract class RecoveryProcessImpl implements RecoveryProcess {
00053 
00055     public static final int MAX_ACTIVE_QUEUES = 50;
00056 
00057     //logger
00058     protected static Logger logger = ProActiveLogger.getLogger(Loggers.FAULT_TOLERANCE);
00059 
00060     // global server
00061     protected FTServer server;
00062 
00063     // state table (bodyID --> state)
00064     protected Hashtable bodies;
00065 
00066     // internal pool of thread (ActiveQueue)
00067     private Vector activeQueuePool;
00068     private int activeQueuesCounter;
00069 
00070     public RecoveryProcessImpl(FTServer server) {
00071         this.server = server;
00072         this.bodies = new Hashtable();
00073         this.activeQueuePool = new Vector();
00074         this.activeQueuesCounter = 0;
00075     }
00076 
00081     protected abstract void recover(UniqueID failed);
00082 
00086     public void register(UniqueID id) throws RemoteException {
00087         //register with RUNNING default state
00088         bodies.put(id, new Integer(RUNNING));
00089 
00090         //adapt active queues pool
00091         synchronized (this.activeQueuePool) {
00092             if (this.activeQueuePool.size() < RecoveryProcessImpl.MAX_ACTIVE_QUEUES) {
00093                 ActiveQueue aq = new ActiveQueue("ActiveQueue");
00094                 aq.start();
00095                 this.activeQueuePool.add(aq);
00096             }
00097         }
00098         logger.info("[RECOVERY] Body " + id + " has registered");
00099     }
00100 
00104     public void unregister(UniqueID id) throws RemoteException {
00105         // remove from the register table
00106         bodies.remove(id);
00107         // remove from the location table
00108         this.server.updateLocation(id, null);
00109         logger.info("[RECOVERY] Body " + id + " has unregistered");
00110     }
00111 
00115     public void failureDetected(UniqueID id) throws RemoteException {
00116         // id is recovering ??
00117         int currentState = ((Integer) this.bodies.get(id)).intValue();
00118         if (currentState == RUNNING) {
00119             // we can suppose that id is failed
00120             logger.info("[RECOVERY] Failure is detected for " + id);
00121             this.bodies.put(id, new Integer(RECOVERING));
00122             this.recover(id);
00123         } else if (currentState == RECOVERING) {
00124             // id is recovering ...  do nothing  
00125         }
00126     }
00127 
00131     public void updateState(UniqueID id, int state) throws RemoteException {
00132         logger.info("[RECOVERY]  " + id + " is updating its state : " + state);
00133         this.bodies.put(id, new Integer(state));
00134     }
00135 
00140     public void submitJob(ActiveQueueJob job) {
00141         synchronized (this.activeQueuePool) {
00142             ((ActiveQueue) (this.activeQueuePool.get(this.activeQueuesCounter))).addJob(job);
00143             this.activeQueuesCounter = (this.activeQueuesCounter + 1) % (this.activeQueuePool.size());
00144         }
00145     }
00146 
00153     public JobBarrier submitJobWithBarrier(ActiveQueueJob job) {
00154         synchronized (this.activeQueuePool) {
00155             JobBarrier b = ((ActiveQueue) (this.activeQueuePool.get(this.activeQueuesCounter))).addJobWithBarrier(job);
00156             this.activeQueuesCounter = (this.activeQueuesCounter + 1) % (this.activeQueuePool.size());
00157             return b;
00158         }
00159     }
00160 
00164     public int getSystemSize() throws RemoteException {
00165         return this.bodies.size();
00166     }
00167 
00171     public void initialize() throws RemoteException {
00172         this.bodies = new Hashtable();
00173         // killing activeQueues
00174         Iterator itAQ = this.activeQueuePool.iterator();
00175         while (itAQ.hasNext()) {
00176             ((ActiveQueue) (itAQ.next())).killMe();
00177         }
00178         this.activeQueuePool = new Vector();
00179         this.activeQueuesCounter = 0;
00180     }
00181 }

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