|
From: Peter P. <pr...@us...> - 2007-02-02 15:49:26
|
Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2402/src/edu/harvard/syrah/pyxida Modified Files: Pyxida.java Added Files: LogServer.java Log Message: Created a centralised Pyxida log server that all nodes report to. Index: Pyxida.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/Pyxida.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Pyxida.java 1 Feb 2007 14:59:14 -0000 1.18 --- Pyxida.java 2 Feb 2007 15:49:22 -0000 1.19 *************** *** 6,9 **** --- 6,10 ---- import edu.harvard.syrah.prp.Log; import edu.harvard.syrah.pyxida.api.APIManager; + import edu.harvard.syrah.pyxida.log.LogManager; import edu.harvard.syrah.pyxida.nc.NCManager; import edu.harvard.syrah.pyxida.ping.PingManager; *************** *** 20,24 **** private static final Log log = new Log(Pyxida.class); ! private static final String VERSION = "0.1"; static { --- 21,27 ---- private static final Log log = new Log(Pyxida.class); ! private static final int MAJOR_VERSION_NUM = 0; ! private static final int MINOR_VERSION_NUM = 2; ! private static final String VERSION = MAJOR_VERSION_NUM + "." + MINOR_VERSION_NUM; static { *************** *** 44,47 **** --- 47,51 ---- private APIManager apiManager; private PingManager pingManager; + private LogManager logManager; private ObjCommIF comm; final CB0 statCB; *************** *** 68,72 **** } ! private void init() { random = new Random(System.currentTimeMillis()); registerStatsTimer(); --- 72,76 ---- } ! private void init(final CB0 cbDone) { random = new Random(System.currentTimeMillis()); registerStatsTimer(); *************** *** 92,97 **** switch (result.state) { case OK: { ! // Initialise the external APIs ! apiManager = new APIManager(ncManager); apiManager.init(new CB0() { --- 96,100 ---- switch (result.state) { case OK: { ! // Initialise the external APIs apiManager = new APIManager(ncManager); apiManager.init(new CB0() { *************** *** 99,120 **** switch (result.state) { case OK: { ! log.main("Pyxida node initialised correctly."); break; } ! case TIMEOUT: ! case ERROR: { ! log.error("Initialising failed: " + result.toString()); ! break; } } } }); - break; } ! case TIMEOUT: ! case ERROR: { ! log.error("Could not initialise the NCManager: " + result.what); ! break; } } --- 102,120 ---- switch (result.state) { case OK: { ! // Initialise the log manager ! logManager = new LogManager(comm, ncManager); ! logManager.init(cbDone); break; } ! default: { ! cbDone.call(result); } } } }); break; } ! default: { ! cbDone.call(result); } } *************** *** 125,132 **** break; } ! case TIMEOUT: ! case ERROR: { ! log.error("Could not bind to objcomm port: " + result.what); ! break; } } --- 125,130 ---- break; } ! default: { ! cbDone.call(result); } } *************** *** 169,173 **** pyxida = new Pyxida(); ! pyxida.init(); try { --- 167,186 ---- pyxida = new Pyxida(); ! ! pyxida.init(new CB0() { ! protected void cb(CBResult result) { ! switch (result.state) { ! case OK: { ! log.main("Pyxida node initialised successfully"); ! break; ! } ! case TIMEOUT: ! case ERROR: { ! log.error("Could not initialise Pyxida node: " + result.toString()); ! break; ! } ! } ! } ! }); try { --- NEW FILE: LogServer.java --- package edu.harvard.syrah.pyxida; import edu.harvard.syrah.prp.ANSI; import edu.harvard.syrah.prp.Log; import edu.harvard.syrah.pyxida.log.ReportCoordReplyMsg; import edu.harvard.syrah.pyxida.log.ReportCoordReqMsg; import edu.harvard.syrah.sbon.async.*; import edu.harvard.syrah.sbon.async.CBResult.CBState; import edu.harvard.syrah.sbon.async.CallbacksIF.CB0; import edu.harvard.syrah.sbon.async.CallbacksIF.CB1; import edu.harvard.syrah.sbon.comm.AddressFactory; import edu.harvard.syrah.sbon.comm.AddressIF; import edu.harvard.syrah.sbon.comm.obj.*; public class LogServer { private static final Log log = new Log(LogServer.class); static { /* * All config properties in the file must start with 'pyxida.' */ Config.read("pyxida", System.getProperty("pyxida.config", "config/pyxida.cfg")); } private static final String CONFIG_FILE = System.getProperty("pyxida.config", "config/pyxida.cfg"); // Imperial blocks ports outside of 55000-56999 public static final int COMM_PORT = Integer.parseInt(Config.getConfigProps().getProperty("pyxida.port", "55504")); // By default tell nodes to report their coords every 10 seconds private static final long LOG_INTERVAL = 10 * 1000; private static LogServer logServer = null; ObjCommIF comm; private void init(final CB0 cbDone) { // Initiliase the ObjComm communication module comm = new ObjComm(); AddressIF objCommAddr = AddressFactory.createServer(COMM_PORT); log.debug("Starting objcomm server..."); comm.initServer(objCommAddr, new CB0() { protected void cb(CBResult result) { if (result.state == CBState.OK) { comm.registerMessageCB(ReportCoordReqMsg.class, new ReportCoordMsgHandler()); } cbDone.call(result); } }); } /** * @param args */ public static void main(String[] args) { log.main("Pyxida Log Server Version 0.1 starting..."); if (args.length > 0 && args[0].equals("-d")) { Log.setPackageRoot(LogServer.class); String[] newArgs = new String[args.length - 1]; for (int i = 0; i < newArgs.length; i++) newArgs[i] = args[i]; args = newArgs; } // Turn on assertions boolean assertsEnabled = false; assert assertsEnabled = true; if (!assertsEnabled) log.error("Please run the code with assertions turned on: java -ea ..."); // Turn on colour support ANSI.use(Boolean.valueOf(Config.getConfigProps().getProperty("sbon.console.ansi", "true"))); /* * Create the event loop */ EventLoop.set(new EventLoop(Long.valueOf(Config.getConfigProps().getProperty( "sbon.eventloop.statedump", "600000")), Boolean.valueOf(Config.getConfigProps().getProperty( "sbon.eventloop.showidle", "false")))); logServer = new LogServer(); logServer.init(new CB0() { protected void cb(CBResult result) { switch (result.state) { case OK: { log.main("Pyxida log server initialised successfully"); break; } case TIMEOUT: case ERROR: { log.error("Could not initialise Pyxida log server: " + result.toString()); break; } } } }); try { EventLoop.get().main(); } catch (OutOfMemoryError e) { EventLoop.get().dumpState(true); e.printStackTrace(); log.error("Error: Out of memory: " + e); } log.main("Shutdown"); System.exit(0); } class ReportCoordMsgHandler extends ObjCommCB<ReportCoordReqMsg> { private final Log log = new Log(ReportCoordMsgHandler.class); @Override protected void cb(CBResult result, ReportCoordReqMsg reqMsg, AddressIF remoteAddr, Long delay, CB1<Boolean> cbHandled) { switch (result.state) { case OK: { log.info("addr=" + remoteAddr + " c=" + reqMsg.coord); ReportCoordReplyMsg replyMsg = new ReportCoordReplyMsg(); replyMsg.interval = LOG_INTERVAL; LogServer.this.comm.sendResponseMessage(replyMsg, remoteAddr, reqMsg.getMsgId(), new CB0() { protected void cb(CBResult result) { if (result.state != CBState.OK) { log.warn("Could not send reply: " + result); } } }); cbHandled.call(CBResult.OK(), true); break; } case TIMEOUT: case ERROR: { log.warn(result.toString()); break; } } } } } |