trunk/com/so/news/Main.java
author chris <chris@marvin>
Tue Jan 20 10:21:03 2009 +0100 (2009-01-20)
changeset 0 f907866f0e4b
permissions -rw-r--r--
Initial import.
     1 /*
     2  *   StarOffice News Server
     3  *   see AUTHORS for the list of contributors
     4  *
     5  *   This program is free software: you can redistribute it and/or modify
     6  *   it under the terms of the GNU General Public License as published by
     7  *   the Free Software Foundation, either version 3 of the License, or
     8  *   (at your option) any later version.
     9  *
    10  *   This program is distributed in the hope that it will be useful,
    11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  *   GNU General Public License for more details.
    14  *
    15  *   You should have received a copy of the GNU General Public License
    16  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  */
    18 
    19 package com.so.news;
    20 
    21 import java.net.BindException;
    22 
    23 import java.sql.Driver;
    24 import java.sql.DriverManager;
    25 import java.util.Enumeration;
    26 
    27 import com.so.news.storage.Database;
    28 import com.so.news.storage.Purger;
    29 
    30 /**
    31  * Startup class of the daemon.
    32  * @author Christian Lins
    33  */
    34 public class Main
    35 {
    36   /** Version information of the StarOffice News daemon */
    37   public static final String VERSION = "StarOffice News Server 0.5alpha1";
    38 
    39   /**
    40    * The main entrypoint.
    41    * @param args
    42    * @throws Exception
    43    */
    44   public static void main(String args[]) throws Exception
    45   {
    46     System.out.println(VERSION);
    47 
    48     // Command line arguments
    49     boolean auxPort = false;
    50     
    51     for(int n = 0; n < args.length; n++)
    52     {
    53       if(args[n].equals("--dumpjdbcdriver"))
    54       {
    55         System.out.println("Available JDBC drivers:");
    56         Enumeration<Driver> drvs =  DriverManager.getDrivers();
    57         while(drvs.hasMoreElements())
    58           System.out.println(drvs.nextElement());
    59         return;
    60       }
    61       else if(args[n].equals("--useaux"))
    62         auxPort = true;
    63     }
    64     
    65     // Try to load the Database
    66     try
    67     {
    68       Database.arise();
    69     }
    70     catch(Exception ex)
    71     {
    72       ex.printStackTrace(Debug.getInstance().getStream());
    73       System.err.println("Database initialization failed with " + ex.toString());
    74       
    75       return;
    76     }
    77     
    78     // Start the n3tpd garbage collector
    79     new Purger().start();
    80     
    81     // Start the listening daemon
    82     try
    83     {
    84       new NNTPDaemon(false).start();
    85     }
    86     catch(BindException ex)
    87     {
    88       ex.printStackTrace(Debug.getInstance().getStream());
    89       System.err.println("Could not bind to interface. Perhaps you need superuser rights?");
    90     }
    91     
    92     // Start auxilary listening port...
    93     if(auxPort)
    94       new NNTPDaemon(true).start();
    95   }
    96 }