KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Launcher


1 import com.coldcore.coloradoftp.core.Core;
2 import com.coldcore.coloradoftp.factory.ObjectFactory;
3 import com.coldcore.coloradoftp.factory.ObjectName;
4 import com.coldcore.coloradoftp.factory.impl.SpringFactory;
5 import org.springframework.core.io.FileSystemResource;
6 import org.springframework.core.io.Resource;
7
8 import java.io.File JavaDoc;
9
10 /**
11  * Launcher.
12  *
13  * A simple class to start an FTP server as a standalone application.
14  * When started, FTP server can be killed by killing the process it is running in, but doing
15  * so will terminate the server immediately without calling its stop or poisoned routines.
16  *
17  *
18  * ColoradoFTP - The Open Source FTP Server (http://cftp.coldcore.com)
19  */

20 public class Launcher {
21
22   private static String JavaDoc filename = "conf/beans.xml";
23
24
25   public static void main(String JavaDoc[] args) {
26     System.out.println();
27     System.out.println("========================================");
28     System.out.println("ColoradoFTP - the open source FTP server");
29     System.out.println("Make sure to visit www.coldcore.com");
30     System.out.println("========================================");
31
32     File JavaDoc file = new File JavaDoc(filename);
33     if (args.length > 0) file = new File JavaDoc(args[0]);
34
35     System.out.println("Reading configuration from: "+file.getAbsolutePath());
36     System.out.println("To set a different configuration file use 'Launcher filename'");
37
38     if (!file.exists()) {
39       System.out.println("Configuration file not found, terminating...");
40       System.exit(1);
41     }
42
43     try {
44       Resource resource = new FileSystemResource(file);
45       ObjectFactory.setInternalFactory(new SpringFactory(resource));
46     } catch (Throwable JavaDoc e) {
47       System.out.println("Cannot initialize object factory, terminating...");
48       e.printStackTrace();
49       System.exit(1);
50     }
51     System.out.println("Object factory initialized");
52
53     Core core = null;
54     try {
55       core = (Core) ObjectFactory.getObject(ObjectName.CORE);
56       core.start();
57     } catch (Throwable JavaDoc e) {
58       System.out.println("Unable to start the server, terminating...");
59       e.printStackTrace();
60       System.exit(1);
61     }
62
63     //todo Shutdown Hook
64
//addShutdownHook(core);
65

66     System.out.println("Server started, use Ctrl+C to kill the process");
67   }
68
69 /*
70   private static void addShutdownHook(final Core core) {
71     Runnable shutdownHook = new Runnable() {
72       public void run() {
73         System.out.println("Stopping server...");
74         core.poison();
75         //todo wait till everyone disconnects
76         core.stop();
77       }
78     };
79     Runtime runtime = Runtime.getRuntime();
80     runtime.addShutdownHook(new Thread(shutdownHook));
81   }
82 */

83
84 }
85
Popular Tags