View Javadoc
1 /* Reattore HTTP Server 2 3 Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 $Id: HttpServer.java,v 1.14 2003/03/05 04:31:57 michaelh Exp $ 20 */ 21 22 package juju.reattore.server.http; 23 24 import java.io.IOException; 25 import java.net.InetSocketAddress; 26 import java.nio.channels.ServerSocketChannel; 27 28 import juju.reattore.core.reactor.impl.CombinedReactor; 29 import juju.reattore.server.intercept.Interceptor; 30 31 import org.apache.commons.logging.Log; 32 import org.apache.commons.logging.LogFactory; 33 34 /*** Main Http server entry point. 35 36 @tag http 37 @group Server 38 @children Interceptor 39 */ 40 public class HttpServer { 41 private static Log log = LogFactory.getLog(HttpServer.class); 42 43 private int port = 8080; 44 private int backlog = 512; 45 private Interceptor intercept; 46 47 /*** Bind this server to the given reactor. Used in configuration. 48 49 @param reactor The reactor to attach to. 50 @throws IOException If the sockets cannot be started up. 51 52 @todo Needs a start instead of building it into the setter. 53 */ 54 public void setReactor(CombinedReactor reactor) 55 throws IOException { 56 57 try { 58 HttpMediator mediator = new HttpMediator(reactor, intercept); 59 60 /* Create the channel and bind it in */ 61 ServerSocketChannel ch = ServerSocketChannel.open(); 62 ch.configureBlocking(false); 63 64 /* Bind away */ 65 ch.socket().bind(new InetSocketAddress(port), backlog); 66 67 reactor.attach(ch, new HttpServerHandler(mediator)); 68 69 log.info("Ready to serve requests on port " + port); 70 } 71 catch (IOException ex) { 72 log.error("Unable to start the server on port " + port, ex); 73 throw ex; 74 } 75 } 76 77 /*** Configure the TCP port to bind to. 78 79 @param val The port to bind to. 80 */ 81 public void setPort(int val) { 82 port = val; 83 } 84 85 /*** Configures the TCP server socket backlog limit. 86 87 @param val The backlog limit. 88 */ 89 public void setBacklog(int val) { 90 backlog = val; 91 } 92 93 /*** Configures the top level interceptor. 94 95 @param inter Top level interceptor. 96 */ 97 public void addChild(Interceptor inter) { 98 this.intercept = inter; 99 } 100 }

This page was automatically generated by Maven