X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FMain.java;h=4d0659b59a9960dbb3d3a4c8bfe6ec0e0ed16ad5;hb=c6c34cf552ed4c1691b1a97388f5a09827f2e31b;hp=b11584c7c57274c10b30d983208fe1eb96b4b950;hpb=4f4c5c1eab2c76e1b7092a8463d998ac58c07fc2;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/Main.java b/src/org/ibex/mail/Main.java index b11584c..4d0659b 100644 --- a/src/org/ibex/mail/Main.java +++ b/src/org/ibex/mail/Main.java @@ -19,6 +19,9 @@ import javax.net.ssl.SSLSocket; // restrict the maximum number of open connections from any given source IP (probably max 4) public class Main { + public static final ThreadPool threadPool = new ThreadPool(10); + public static final Cron cron = new Cron(threadPool); + public static void main(String[] s) throws Exception { try { File f = new File(Mailbox.STORAGE_ROOT + "/restart"); @@ -44,20 +47,19 @@ public class Main { ServerSocket sock563 = (ServerSocket) sslserversocketfactory.createServerSocket(563); //ServerSocket sock995 = new ServerSocket(995); //ServerSocket sock113 = new ServerSocket(113); - new Thread() { + + cron.executeLater(500, new Runnable() { public void run() { - while(true) { - try { Thread.sleep(500); } catch (Exception e) { } - try { - File f = new File(Mailbox.STORAGE_ROOT + "/restart"); - if (f.exists()) { - Log.error("RESTART", "restarting..."); - System.exit(0); - } - } catch (Exception e) { Log.error(this, e); } - } - } - }.start(); + try { + File f = new File(Mailbox.STORAGE_ROOT + "/restart"); + if (f.exists()) { + Log.error("RESTART", "restarting..."); + System.exit(0); + } + } catch (Exception e) { Log.error(this, e); } + cron.executeLater(500, this); + } }); + new Acceptor(sock143).start(); new Acceptor(sock119).start(); new Acceptor(sock25).start(); @@ -77,13 +79,13 @@ public class Main { try { ss.setReuseAddress(true); final Socket s = ss.accept(); - new Thread() { + threadPool.start(new Runnable() { public void run() { try { accept(new Connection(s, "megacz.com")); } catch (Throwable t) { Log.error(Main.class, t); } } - }.start(); + }); } catch (Throwable t) { Log.error(Main.class, t); Misc.sleep(1000); @@ -119,11 +121,11 @@ public class Main { private KerberosAuth ka = new KerberosAuth("MEGACZ.COM", "chaitin.megacz.com"); public Account anonymous() { try { - final Mailbox root = + final MailTree root = FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/list", false); if (root==null) return null; - return new Account("anonymous", null, root){ - public Mailbox getMailbox(Class protocol) { + return new Account("anonymous", null, root) { + public MailTree getMailbox(Class protocol) { return super.getMailbox(protocol); } }; @@ -134,10 +136,10 @@ public class Main { //if (!EtcPasswd.verify(user, pass)) return null; //if (!CheckPassword.verify(user, pass)) return null; if (!ka.auth(user, pass)) return null; - final Mailbox root = + final MailTree root = FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/user", true); return new Account(user, null, root.slash(user, true)){ - public Mailbox getMailbox(Class protocol) { + public MailTree getMailbox(Class protocol) { return super.getMailbox(protocol); } };