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 , BindingController { 7 private Scheduler s; 8 private RequestHandler rh; 9 public String [] listFc () { return new String [] { "s", "rh" }; } 11 public Object lookupFc (String 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 itfName, Object itfValue) { 17 if (itfName.equals("s")) { s = (Scheduler)itfValue; } 18 else if (itfName.equals("rh")) { rh = (RequestHandler)itfValue; } 19 } 20 public void unbindFc (String itfName) { 21 if (itfName.equals("s")) { s = null; } 22 else if (itfName.equals("rh")) { rh = null; } 23 } 24 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 () { 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 |