KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > comanche > RequestReceiver


1 package comanche;
2 import java.io.*;
3 import java.net.*;
4 import org.objectweb.fractal.api.control.BindingController;
5
6 public class RequestReceiver implements Runnable JavaDoc, BindingController {
7   private Scheduler s;
8   private RequestHandler rh;
9   // configuration aspect
10
public String JavaDoc[] listFc () { return new String JavaDoc[] { "s", "rh" }; }
11   public Object JavaDoc lookupFc (String JavaDoc itfName) {
12     if (itfName.equals("s")) { return s; }
13     else if (itfName.equals("rh")) { return rh; }
14     else return null;
15   }
16   public void bindFc (String JavaDoc itfName, Object JavaDoc itfValue) {
17     if (itfName.equals("s")) { s = (Scheduler)itfValue; }
18     else if (itfName.equals("rh")) { rh = (RequestHandler)itfValue; }
19   }
20   public void unbindFc (String JavaDoc itfName) {
21     if (itfName.equals("s")) { s = null; }
22     else if (itfName.equals("rh")) { rh = null; }
23   }
24   // functional aspect
25
public void run () {
26     try {
27       ServerSocket ss = new ServerSocket(8080);
28       System.out.println("Comanche HTTP Server ready on port 8080.");
29       while (true) {
30         final Socket socket = ss.accept();
31         s.schedule(new Runnable JavaDoc () {
32           public void run () {
33             try {
34               rh.handleRequest(new Request(socket));
35             } catch (IOException _) { }
36           }
37         });
38       }
39     } catch (IOException e) { e.printStackTrace(); }
40   }
41 }
42
Popular Tags