Package kilim.http
Class HttpServer
- java.lang.Object
-
- kilim.http.HttpServer
-
public class HttpServer extends java.lang.ObjectA very rudimentary HTTP server bound to a specific given port.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpServer.Factory
-
Field Summary
Fields Modifier and Type Field Description NioSelectorSchedulernio
-
Constructor Summary
Constructors Constructor Description HttpServer()HttpServer(int port, java.lang.Class<? extends HttpSession> httpSessionClass)Creates a separate thread and a selector for the select loop and calls#listen(int, Class)listenHttpServer(int port, HttpSession.StringRouter handler)HttpServer(int port, NioSelectorScheduler.SessionFactory factory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidlisten(int port, java.lang.Class<? extends HttpSession> httpSessionClass, Scheduler httpSessionScheduler)Sets up a listener on the supplied port, and when a fresh connection comes in, it creates a new instance of the httpSessionClass task and exceutes it on the supplied scheduler.voidlisten(int port, NioSelectorScheduler.SessionFactory factory, Scheduler httpSessionScheduler)
-
-
-
Field Detail
-
nio
public NioSelectorScheduler nio
-
-
Constructor Detail
-
HttpServer
public HttpServer()
-
HttpServer
public HttpServer(int port, java.lang.Class<? extends HttpSession> httpSessionClass) throws java.io.IOExceptionCreates a separate thread and a selector for the select loop and calls#listen(int, Class)listen- Parameters:
port- . Port to listen for http connections.httpSessionClass- An instance of the supplied class is created and bound to the incoming socket connection, and the task is scheduled for execution on the default scheduler.- Throws:
java.io.IOException
-
HttpServer
public HttpServer(int port, NioSelectorScheduler.SessionFactory factory) throws java.io.IOException- Throws:
java.io.IOException
-
HttpServer
public HttpServer(int port, HttpSession.StringRouter handler) throws java.io.IOException- Throws:
java.io.IOException
-
-
Method Detail
-
listen
public void listen(int port, java.lang.Class<? extends HttpSession> httpSessionClass, Scheduler httpSessionScheduler) throws java.io.IOExceptionSets up a listener on the supplied port, and when a fresh connection comes in, it creates a new instance of the httpSessionClass task and exceutes it on the supplied scheduler. It is the httpSession task's responsbility to close the socket.- Parameters:
port- . Port to listen for http connections.httpSessionClass- class of task to instantiation on incoming connectionhttpSessionScheduler- the scheduler on which to schedule the http session task.- Throws:
java.io.IOException
-
listen
public void listen(int port, NioSelectorScheduler.SessionFactory factory, Scheduler httpSessionScheduler) throws java.io.IOException- Throws:
java.io.IOException
-
-