org/objectweb/proactive/core/body/ft/servers/storage/CheckpointServerImpl.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.storage;
00032 
00033 import java.io.ByteArrayOutputStream;
00034 import java.io.IOException;
00035 import java.io.ObjectOutputStream;
00036 import java.io.Serializable;
00037 import java.rmi.RemoteException;
00038 import java.util.Hashtable;
00039 
00040 import org.apache.log4j.Logger;
00041 import org.objectweb.proactive.core.body.ft.servers.FTServer;
00042 import org.objectweb.proactive.core.rmi.ClassServerHelper;
00043 import org.objectweb.proactive.core.util.log.Loggers;
00044 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00045 
00046 
00051 public abstract class CheckpointServerImpl implements CheckpointServer {
00052     //logger
00053     protected static Logger logger = ProActiveLogger.getLogger(Loggers.FAULT_TOLERANCE);
00054 
00055     // used memory
00056     private final static Runtime runtime = Runtime.getRuntime();
00057 
00058     // global server
00059     protected FTServer server;
00060 
00061     // ClassFileServer and the assiociated codebase
00062     protected static ClassServerHelper classServerHelper = new ClassServerHelper();
00063     protected String codebase;
00064 
00065     // The stable storage (idCheckpointer --> [list of] [checkpoints])
00066     protected Hashtable checkpointStorage;
00067 
00071     public CheckpointServerImpl(FTServer server) {
00072         this.server = server;
00073 
00074         this.checkpointStorage = new Hashtable();
00075 
00076         //classloader
00077         try {
00078             CheckpointServerImpl.classServerHelper.setShouldCreateClassServer(true);
00079             this.codebase = CheckpointServerImpl.classServerHelper.initializeClassServer();
00080             System.setProperty("java.rmi.server.codebase", this.codebase);
00081             logger.info("ClassServer is bound on " + this.codebase);
00082         } catch (IOException e) {
00083             this.codebase = "NO CODEBASE";
00084             System.err.println("** ERROR ** Unable to launch FT server : ");
00085             e.printStackTrace();
00086         }
00087     }
00088 
00092     public String getServerCodebase() throws RemoteException {
00093         return this.codebase;
00094     }
00095 
00096     // UTIL METHODS
00097     protected long getSize(Serializable c) {
00098         try {
00099             ByteArrayOutputStream baos = new ByteArrayOutputStream();
00100             ObjectOutputStream oos = new ObjectOutputStream(baos);
00101 
00102             // serialize the body
00103             oos.writeObject(c);
00104             // store the serialized form
00105             return baos.toByteArray().length;
00106         } catch (IOException e) {
00107             e.printStackTrace();
00108             return 0;
00109         }
00110     }
00111 
00112     /*
00113      * Return the memory actually used
00114      * For debugging stuff.
00115      */
00116     protected long getUsedMem() {
00117         return (CheckpointServerImpl.runtime.totalMemory() -
00118         CheckpointServerImpl.runtime.freeMemory()) / 1024;
00119     }
00120 
00124     public void initialize() throws RemoteException {
00125         this.checkpointStorage = new Hashtable();
00126     }
00127 }

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