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.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
00053 protected static Logger logger = ProActiveLogger.getLogger(Loggers.FAULT_TOLERANCE);
00054
00055
00056 private final static Runtime runtime = Runtime.getRuntime();
00057
00058
00059 protected FTServer server;
00060
00061
00062 protected static ClassServerHelper classServerHelper = new ClassServerHelper();
00063 protected String codebase;
00064
00065
00066 protected Hashtable checkpointStorage;
00067
00071 public CheckpointServerImpl(FTServer server) {
00072 this.server = server;
00073
00074 this.checkpointStorage = new Hashtable();
00075
00076
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
00097 protected long getSize(Serializable c) {
00098 try {
00099 ByteArrayOutputStream baos = new ByteArrayOutputStream();
00100 ObjectOutputStream oos = new ObjectOutputStream(baos);
00101
00102
00103 oos.writeObject(c);
00104
00105 return baos.toByteArray().length;
00106 } catch (IOException e) {
00107 e.printStackTrace();
00108 return 0;
00109 }
00110 }
00111
00112
00113
00114
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 }