38
|
1 package jungle.test.bbs;
|
|
2
|
|
3 import javax.servlet.Servlet;
|
|
4
|
40
|
5 import jungle.test.bbs.codesegment.PutAnotherLogCodeSegment;
|
|
6 import jungle.test.bbs.codesegment.PutHostLogCodeSegment;
|
|
7
|
38
|
8 import org.mortbay.jetty.Server;
|
|
9 import org.mortbay.jetty.servlet.ServletHandler;
|
|
10 import org.mortbay.jetty.servlet.ServletHolder;
|
|
11
|
39
|
12 import alice.daemon.AliceDaemon;
|
|
13 import alice.datasegment.DataSegment;
|
|
14 import alice.jungle.codesegment.LogUpdateCodeSegment;
|
|
15 import alice.jungle.remote.RemoteConfig;
|
|
16
|
38
|
17 /**
|
|
18 * Hello world!
|
|
19 *
|
|
20 */
|
39
|
21 public class DistributeApp
|
38
|
22 {
|
|
23 public static void main( String[] args ) throws Exception
|
|
24 {
|
|
25 BulletinBoard cassaBBS = null;
|
39
|
26 cassaBBS = new NetworkJungleBulletinBoard();
|
|
27 RemoteConfig conf = new RemoteConfig(args);
|
40
|
28 if(conf.hostname == null) {
|
|
29 /* Host Side */
|
|
30 new AliceDaemon(conf).listen();
|
|
31 PutHostLogCodeSegment cs = new PutHostLogCodeSegment();
|
|
32 cs.arg1.setKey("local","log");
|
|
33 } else {
|
|
34 /* Client Side */
|
39
|
35 DataSegment.connect(conf.key, "", conf.hostname, conf.connectPort);
|
|
36 LogUpdateCodeSegment cs = new LogUpdateCodeSegment();
|
40
|
37 cs.arg1.setKey("remote", "hostLog");
|
|
38 PutAnotherLogCodeSegment cs2 = new PutAnotherLogCodeSegment();
|
|
39 cs2.arg1.setKey("local", "log");
|
39
|
40 }
|
|
41
|
|
42
|
38
|
43 String createBoardMessagePath = "/createBoardMessage";
|
|
44 String createBoardPath = "/createBoard";
|
|
45 String editMessagePath = "/editMessage";
|
|
46 String showBoardMessagePath = "/showBoardMessage";
|
|
47
|
|
48 Servlet createBoardMessage = new CreateBoardMessageServlet(cassaBBS);
|
|
49 Servlet createBoard = new CreateBoardServlet(cassaBBS);
|
|
50 Servlet editBoardMessage = new EditMessageServlet(cassaBBS);
|
|
51 Servlet index = new ShowBoardsServlet(cassaBBS,createBoardPath,showBoardMessagePath);
|
|
52 Servlet board = new ShowBoardMessageServlet(cassaBBS,createBoardMessagePath,editMessagePath);
|
|
53
|
|
54 Server serv = new Server(8080);
|
|
55 ServletHandler context = new ServletHandler();
|
|
56 context.addServletWithMapping(new ServletHolder(createBoardMessage),createBoardMessagePath);
|
|
57 context.addServletWithMapping(new ServletHolder(createBoard),createBoardPath);
|
|
58 context.addServletWithMapping(new ServletHolder(editBoardMessage),editMessagePath);
|
|
59 context.addServletWithMapping(new ServletHolder(index),"/");
|
|
60 context.addServletWithMapping(new ServletHolder(board),showBoardMessagePath);
|
|
61 serv.addHandler(context);
|
|
62 serv.start();
|
|
63 }
|
|
64 }
|