KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > framework > internal > orchestrator > Orchestrator


1 /*
2  * ========================================================================
3  *
4  * Copyright 2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.framework.internal.orchestrator;
21
22 import org.apache.cactus.framework.internal.orchestrator.handlers.GetResultHandler;
23 import org.apache.cactus.framework.internal.orchestrator.handlers.GetTestHandler;
24 import org.apache.cactus.framework.internal.orchestrator.handlers.SetResultHandler;
25 import org.apache.cactus.framework.internal.orchestrator.handlers.SetTestHandler;
26 import org.mortbay.http.HttpContext;
27 import org.mortbay.http.HttpServer;
28 import org.mortbay.http.SocketListener;
29
30 public class Orchestrator
31 {
32     private int port;
33     
34     private HttpServer server;
35     
36     public Orchestrator(int port)
37     {
38         this.port = port;
39     }
40
41     public int getPort()
42     {
43         return this.port;
44     }
45     
46     public void start() throws Throwable JavaDoc
47     {
48         // Setup HTTP server and attach to it handlers to manage
49
// the executing test and to manage retrieval of test results
50

51         this.server = new HttpServer();
52         SocketListener listener = new SocketListener();
53         listener.setPort(getPort());
54         this.server.addListener(listener);
55
56         HttpContext context = this.server.addContext("/");
57         
58         context.addHandler(new SetResultHandler());
59         context.addHandler(new GetResultHandler());
60
61         SetTestHandler setTestHandler = new SetTestHandler();
62         context.addHandler(setTestHandler);
63         context.addHandler(new GetTestHandler(setTestHandler));
64
65         this.server.start();
66     }
67
68     public void stop() throws InterruptedException JavaDoc
69     {
70         this.server.stop();
71     }
72     
73 }
74
Popular Tags