View Javadoc

1   package org.opensync.schedule;
2   
3   import java.io.*;
4   import java.net.*;
5   
6   /***
7    * This class represents the http server of the scheduler
8    *
9    * @version	1.0
10   * @author	SOFTMED
11   */
12  
13  public class HTTPScheduler implements Runnable{
14  
15  
16    /***
17     * The server socket
18     *
19     */
20    public static ServerSocket serverSocket;
21    /***
22     * The scheduler object
23     *
24     *
25     */
26    protected Scheduler scheduler = null;
27    /***
28     * The listening port
29     *
30     */
31    protected int port;
32    /***
33     * Construct the HTTPScheuler
34     *
35     * @param	scheduler the scheduler object
36     * @param	port the listening port
37     */
38    public HTTPScheduler(Scheduler scheduler,int port) {
39      this.scheduler = scheduler;
40      this.port = port;
41    }
42    /***
43     * Run the server
44     *
45     */
46    public void run() {
47  
48      try {
49        serverSocket = new ServerSocket(port);
50        acceptConnections();
51      }
52      catch (IOException ex) {
53        // Do nothing, the serverSocket is already running.
54      }
55    }
56  
57    /***
58     * Listening http connection
59     *
60     * @exception	IOException
61     */
62    private void acceptConnections() throws IOException{
63      try{
64        while(true){
65          Socket socket = serverSocket.accept();
66          System.err.println("HTTPSchedulerService start");
67          HTTPSchedulerService service = new HTTPSchedulerService(socket,scheduler);
68          service.start();
69        }
70      }
71      finally{
72        serverSocket.close();
73      }
74    }
75  }