// Path: westty-core/src/main/java/org/deephacks/westty/internal/core/http/HttpDecoder.java
// public final static class WesttyHttpMessage extends DefaultHttpRequest {
//     private HttpHandler handler;
// 
//     public WesttyHttpMessage(HttpVersion version, HttpMethod method, String uri,
//             HttpHandler handler) {
//         super(version, method, uri);
//         this.handler = handler;
//     }
// 
//     public HttpHandler getHandler() {
//         return handler;
//     }
// }


import org.deephacks.westty.internal.core.http.HttpDecoder.WesttyHttpMessage;
import org.jboss.netty.channel.*;
import org.jboss.netty.channel.group.ChannelGroup;
import org.jboss.netty.channel.group.DefaultChannelGroup;
import org.jboss.netty.handler.codec.frame.TooLongFrameException;
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.deephacks.westty.internal.core.http;



class HttpUpstreamHandler extends SimpleChannelUpstreamHandler {
    private final static Logger log = LoggerFactory.getLogger(HttpUpstreamHandler.class);

    private ChannelGroup clients = new DefaultChannelGroup("connected-clients");

    @Override
    public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        clients.add(ctx.getChannel());
        super.channelConnected(ctx, e);
    }

    @Override
    public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        clients.remove(ctx.getChannel());
        super.channelClosed(ctx, e);
    }

    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
// Path: westty-core/src/main/java/org/deephacks/westty/internal/core/http/HttpDecoder.java
// public final static class WesttyHttpMessage extends DefaultHttpRequest {
//     private HttpHandler handler;
// 
//     public WesttyHttpMessage(HttpVersion version, HttpMethod method, String uri,
//             HttpHandler handler) {
//         super(version, method, uri);
//         this.handler = handler;
//     }
// 
//     public HttpHandler getHandler() {
//         return handler;
//     }
// }


// Path: westty-core/src/main/java/org/deephacks/westty/internal/core/http/HttpUpstreamHandler.java
import org.deephacks.westty.internal.core.http.HttpDecoder.WesttyHttpMessage;
import org.jboss.netty.channel.*;
import org.jboss.netty.channel.group.ChannelGroup;
import org.jboss.netty.channel.group.DefaultChannelGroup;
import org.jboss.netty.handler.codec.frame.TooLongFrameException;
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;

/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.deephacks.westty.internal.core.http;



class HttpUpstreamHandler extends SimpleChannelUpstreamHandler {
    private final static Logger log = LoggerFactory.getLogger(HttpUpstreamHandler.class);

    private ChannelGroup clients = new DefaultChannelGroup("connected-clients");

    @Override
    public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        clients.add(ctx.getChannel());
        super.channelConnected(ctx, e);
    }

    @Override
    public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        clients.remove(ctx.getChannel());
        super.channelClosed(ctx, e);
    }

    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
        if (e.getMessage() instanceof WesttyHttpMessage) {