00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00058 protected static Logger logger = ProActiveLogger.getLogger(Loggers.FAULT_TOLERANCE);
00059
00060
00061 protected FTServer server;
00062
00063
00064 protected Hashtable bodies;
00065
00066
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
00088 bodies.put(id, new Integer(RUNNING));
00089
00090
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
00106 bodies.remove(id);
00107
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
00117 int currentState = ((Integer) this.bodies.get(id)).intValue();
00118 if (currentState == RUNNING) {
00119
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
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
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 }