/**
 * $Revision: 1.0
 * $Date: 2013-5-21
 *
 * Copyright (C) 2013-2020 MNT. All rights reserved.
 *
 * 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 com.mnt.base.stream.client;

import com.mnt.base.stream.comm.RequestHandler;
import com.mnt.base.stream.netty.Connection;
import com.mnt.base.stream.netty.NConnectionHandler;

import io.netty.channel.ChannelHandlerContext;

public class NServerConnectionHandler extends NConnectionHandler {
	
	private NStreamClient streamClient;

    public NServerConnectionHandler(NStreamClient streamClient) {
        super();
        this.streamClient = streamClient;
    }

    @Override
    public RequestHandler createRequestHandler(Connection connection) {
        return new NServerResponseHandler(connection, streamClient);
    }

	@Override
	public Connection createConnection(
			ChannelHandlerContext channelHandlerContext, String connectionId) {
		return new NClientNIOConnection(channelHandlerContext, connectionId, streamClient);
	}
}


@@ -713,24 +713,128 @@
 .client;%0D%0A%0D%0A
+import com.mnt.base.stream.comm.EventHandler;%0D%0Aimport com.mnt.base.stream.comm.EventHandler.EventType;%0D%0A
 import com.m
@@ -862,32 +862,32 @@
 equestHandler;%0D%0A
-
 import com.mnt.b
@@ -1130,16 +1130,56 @@
 Client;%0D
+%0A%09private Connection connection = null;%0D
 %0A%0D%0A    p
@@ -1394,24 +1394,60 @@
 nection) %7B%0D%0A
+    %09this.connection = connection;%0D%0A
         retu
@@ -1726,11 +1726,328 @@
 );%0D%0A
-
 %09%7D%0D
+%0A%0D%0A%09@Override%0D%0A%09public void channelInactive(ChannelHandlerContext ctx) throws Exception %7B%0D%0A%09%09if(connection != null) %7B%0D%0A%09%09%09connection.close();%0D%0A%09%09%09EventHandler eh = streamClient.eventHandlerMap.get(EventType.Closed);%0D%0A%09%09%09%0D%0A%09%09%09if(eh != null) %7B%0D%0A%09%09%09%09eh.handleEvent();%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09super.channelInactive(ctx);%0D%0A%09%7D%0D%0A%09%0D%0A%09%0D
 %0A%7D%0D%0A

add client connection close trigger support.