import java.servlet.*; import java.io.*; import java.util.*; import java.servlet.http.*; import java.lang.*; import java.lang.Thread.*; public class Ubiq extends GenericServlet { String Version = "2.4"; //Password is an attempt to prevent other classes //from accessing the data inside the User Data I/O class private String systemPassword = "KJaslkjdKDDShLBUasdf2837skdj"; BDUserData sysusers = new BDUserData(); Loop loop = new Loop(); ////////////////////////////// public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintStream out = new PrintStream(res.getOutputStream()); String systemcall = req.getURLLine(); runCall(systemcall, out); } ////////////////////////////// //each call is basically the parameter to the servlet from //the URL. Example: http://www.server.com/scm/kill //calls the stopService function public void runCall(String call, PrintStream out) { if (call == "scm/kill") stopService(out); else if (call == "scm/load") loadUsers(out); else if (call == "scm/save") saveUsers(out); else if (call == "scm/stop") stopLoop(out); else if (call == "scm/start") startLoop(out); else if (call == "user/load") loadUser(out); else if (call == "user/new") newUser(out); else default(out); } ////////////////////////////// public void stopService(PrintStream out) { destroy(); } ////////////////////////////// public void loadUsers(PrintStream out) { sysusers.initialize(systemPassword); } ////////////////////////////// public void saveUsers(PrintStream out) { sysusers.saveData(systemPassword); } ////////////////////////////// public void stopLoop(PrintStream out) { loop.stopMotion(); loop.stop(); } ////////////////////////////// public void loadUser(PrintStream out) { request_password(); // not implemented here printform(); // not implemented here } ////////////////////////////// public void newUser(PrintStream out) { printformnewuser(); // not implemented here addUser(); // not implemented here } ////////////////////////////// public void default(PrintStream out) { writeHeader(out); startLoop(out); writeData(out); write Footer(out); } ////////////////////////////// public void writeDate(PrintStream out) { Date today = new Date(); out.println("

Ubiquitous E-mailer is running


"); out.println("Run at " + today.toLocaleString() + "
"); } ////////////////////////////// public void startLoop(PrintStream out) { try { loop.start(); loop.setUserData(sysusers); } catch (IllegalThreadStateException e) { out.println("The mailer is already running.
"); } } ////////////////////////////// public void writeHeader(PrintStream out) { out.println(""); out.println("\n BigDave's Ubiquitous Pager Servlet\n\n"); out.println("\n\n
"); } ////////////////////////////// public void writeFooter(PrintStream out) { out.println("
"); out.println("Return to pager page"); out.println("\n"); } ////////////////////////////// public String getServletInfo() { return ("Ubiquitous Pager ver " + Version +" copyright (c) 1997 BigDave"); } ////////////////////////////// public void destroy() { sysusers = null; loop.stopMotion(); loop.stop(); loop = null; } }