Package juju.reattore.server.http

Source Code of juju.reattore.server.http.HttpServer

/*  Reattore HTTP Server

    Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    $Id: HttpServer.java,v 1.14 2003/03/05 04:31:57 michaelh Exp $
*/

package juju.reattore.server.http;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;

import juju.reattore.core.reactor.impl.CombinedReactor;
import juju.reattore.server.intercept.Interceptor;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/** Main Http server entry point.

    @tag http
    @group Server
    @children Interceptor
*/
public class HttpServer {
    private static Log log = LogFactory.getLog(HttpServer.class);

    private int port = 8080;
    private int backlog = 512;
    private Interceptor intercept;

    /** Bind this server to the given reactor.  Used in configuration.
       
        @param reactor  The reactor to attach to.
        @throws IOException If the sockets cannot be started up.

        @todo Needs a start instead of building it into the setter.
     */
    public void setReactor(CombinedReactor reactor)
        throws IOException {
       
        try {
            HttpMediator mediator = new HttpMediator(reactor, intercept);

            /* Create the channel and bind it in */
            ServerSocketChannel ch = ServerSocketChannel.open();
            ch.configureBlocking(false);
           
            /* Bind away */
            ch.socket().bind(new InetSocketAddress(port), backlog);
           
            reactor.attach(ch, new HttpServerHandler(mediator));
           
            log.info("Ready to serve requests on port " + port);
        }
        catch (IOException ex) {
            log.error("Unable to start the server on port " + port, ex);
            throw ex;
        }
    }

    /** Configure the TCP port to bind to.

        @param val  The port to bind to.
     */
    public void setPort(int val) {
        port = val;
    }

    /** Configures the TCP server socket backlog limit.

        @param val  The backlog limit.
    */
    public void setBacklog(int val) {
        backlog = val;
    }

    /** Configures the top level interceptor.

        @param inter  Top level interceptor.
     */
    public void addChild(Interceptor inter) {
        this.intercept = inter;
    }
}
TOP

Related Classes of juju.reattore.server.http.HttpServer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.