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: HttpServerHandler.java,v 1.6 2003/01/31 05:30:09 michaelh Exp $
20 */
21
22 package juju.reattore.server.http;
23
24 import java.io.IOException;
25 import java.nio.channels.SelectionKey;
26 import java.nio.channels.SocketChannel;
27
28 import juju.reattore.core.reactor.ServerSocketHandler;
29 import juju.reattore.server.intercept.Interceptor;
30
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33
34 /*** Handler that accepts a new incoming HTTP connection and hands it
35 off to a new HTTP handler.
36 */
37 public class HttpServerHandler
38 implements ServerSocketHandler {
39
40 private static Log log = LogFactory.getLog(HttpServerHandler.class);
41
42 private HttpMediator mediator;
43 private Interceptor intercept;
44
45 /*** Creates a new handler that uses the given mediator for
46 attaching.
47
48 @param mediator The mediator to use.
49 */
50 public HttpServerHandler(HttpMediator mediator) {
51 this.mediator = mediator;
52 }
53
54 /*** @see Handler
55 */
56 public int getInterestOps() {
57 /* Always interested in new connections */
58 return SelectionKey.OP_ACCEPT;
59 }
60
61 /*** @see Handler
62 */
63 public void handleNewClient(SocketChannel ch)
64 throws IOException {
65
66 /* Socket is already accepted. Create a new client and ask
67 the mediator to bind it in.
68 */
69 ch.configureBlocking(false);
70 mediator.doAttach(ch, new HttpClientHandler(ch, mediator));
71 }
72 }
This page was automatically generated by Maven