+ 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");
+ if (f.exists()) f.delete();
+ } catch (Exception e) { Log.error(Main.class, e); }
+ new Main().main();
+ }
+
+ public void main() throws Exception {
+ if (System.getProperty("javax.net.ssl.keyStore")==null)
+ System.setProperty("javax.net.ssl.keyStore", Mailbox.STORAGE_ROOT+"/conf/ssl/ssl.keystore");
+ if (System.getProperty("javax.net.ssl.keyStorePassword")==null)
+ System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
+ SSLServerSocketFactory sslserversocketfactory =
+ (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
+ ServerSocket sslserversocket = (ServerSocket) sslserversocketfactory.createServerSocket(9999);
+ ServerSocket sock8025 = new ServerSocket(8025);
+ ServerSocket sock143 = new ServerSocket(143);
+ ServerSocket sock119 = new ServerSocket(119);
+ ServerSocket sock25 = new ServerSocket(25);
+ ServerSocket sock465 = (ServerSocket) sslserversocketfactory.createServerSocket(465);
+ ServerSocket sock993 = (ServerSocket) sslserversocketfactory.createServerSocket(993);
+ ServerSocket sock563 = (ServerSocket) sslserversocketfactory.createServerSocket(563);
+ //ServerSocket sock995 = new ServerSocket(995);
+ //ServerSocket sock113 = new ServerSocket(113);
+
+ cron.executeLater(500, new Runnable() {
+ public void run() {
+ 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();
+ new Acceptor(sock465).start();
+ new Acceptor(sock8025).start();
+ new Acceptor(sock993).start();
+ new Acceptor(sock563).start();
+ //new Acceptor(sock995).start();
+ //new Acceptor(sock113).start();
+ }
+
+ private class Acceptor extends Thread {
+ private ServerSocket ss;
+ public Acceptor(ServerSocket ss) { this.ss = ss; }
+ public void run() {
+ while(true) {
+ try {
+ ss.setReuseAddress(true);
+ final Socket s = ss.accept();
+ threadPool.start(new Runnable() {
+ public void run() {
+ try {
+ accept(new Connection(s, "megacz.com"));
+ } catch (Throwable t) { Log.error(Main.class, t); }
+ }
+ });
+ } catch (Throwable t) {
+ Log.error(Main.class, t);
+ Misc.sleep(1000);
+ }
+ }
+ }
+ }
+
+ public void accept(Connection conn) {