// Path: jagnet-core/src/main/java/org/gillius/jagnet/ConnectionListener.java
// public interface ConnectionListener<T> extends ConnectionStateListener, ReceivedMessageListener<T> {
// 	@Override
// 	default void onReceive(ConnectionListenerContext ctx, T message) {}
// }
// 
// Path: jagnet-core/src/main/java/org/gillius/jagnet/ConnectionStateListener.java
// public interface ConnectionStateListener {
// 	default void onConnected(ConnectionListenerContext ctx) {}
// 
// 	default void onDisconnected(ConnectionListenerContext ctx) {}
// }
// 
// Path: jagnet-core/src/main/java/org/gillius/jagnet/SingleConnectionListenerContext.java
// public class SingleConnectionListenerContext implements ConnectionListenerContext {
// 	private final Connection connection;
// 
// 	public SingleConnectionListenerContext(Connection connection) {
// 		this.connection = connection;
// 	}
// 
// 	@Override
// 	public Connection getConnection() {
// 		return connection;
// 	}
// 
// 	@Override
// 	public void consumeCurrentEvent() {
// 		//do nothing as this is not a listener chain
// 	}
// }


import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.gillius.jagnet.ConnectionListener;
import org.gillius.jagnet.ConnectionStateListener;
import org.gillius.jagnet.SingleConnectionListenerContext;
package org.gillius.jagnet.netty;


class NettyHandler extends ChannelInboundHandlerAdapter {
	private final SingleConnectionListenerContext clc;
	private final ConnectionListener listener;
	private final ConnectionStateListener connectionStateListener;

	public NettyHandler(NettyConnection connection, ConnectionListener listener) {
		this(connection, listener, null);
	}

	public NettyHandler(NettyConnection connection, ConnectionListener listener, ConnectionStateListener connectionStateListener) {
		clc = connection.getContext();
		this.listener = listener;
		this.connectionStateListener = connectionStateListener;
	}

	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		listener.onConnected(clc);
		super.channelActive(ctx);
		if (connectionStateListener != null)
			connectionStateListener.onConnected(clc);
	}

	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
		listener.onReceive(clc, msg);
		super.channelRead(ctx, msg);
	}

// Path: jagnet-core/src/main/java/org/gillius/jagnet/ConnectionListener.java
// public interface ConnectionListener<T> extends ConnectionStateListener, ReceivedMessageListener<T> {
// 	@Override
// 	default void onReceive(ConnectionListenerContext ctx, T message) {}
// }
// 
// Path: jagnet-core/src/main/java/org/gillius/jagnet/ConnectionStateListener.java
// public interface ConnectionStateListener {
// 	default void onConnected(ConnectionListenerContext ctx) {}
// 
// 	default void onDisconnected(ConnectionListenerContext ctx) {}
// }
// 
// Path: jagnet-core/src/main/java/org/gillius/jagnet/SingleConnectionListenerContext.java
// public class SingleConnectionListenerContext implements ConnectionListenerContext {
// 	private final Connection connection;
// 
// 	public SingleConnectionListenerContext(Connection connection) {
// 		this.connection = connection;
// 	}
// 
// 	@Override
// 	public Connection getConnection() {
// 		return connection;
// 	}
// 
// 	@Override
// 	public void consumeCurrentEvent() {
// 		//do nothing as this is not a listener chain
// 	}
// }


// Path: jagnet-core/src/main/java/org/gillius/jagnet/netty/NettyHandler.java
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.gillius.jagnet.ConnectionListener;
import org.gillius.jagnet.ConnectionStateListener;
import org.gillius.jagnet.SingleConnectionListenerContext;

package org.gillius.jagnet.netty;


class NettyHandler extends ChannelInboundHandlerAdapter {
	private final SingleConnectionListenerContext clc;
	private final ConnectionListener listener;
	private final ConnectionStateListener connectionStateListener;

	public NettyHandler(NettyConnection connection, ConnectionListener listener) {
		this(connection, listener, null);
	}

	public NettyHandler(NettyConnection connection, ConnectionListener listener, ConnectionStateListener connectionStateListener) {
		clc = connection.getContext();
		this.listener = listener;
		this.connectionStateListener = connectionStateListener;
	}

	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		listener.onConnected(clc);
		super.channelActive(ctx);
		if (connectionStateListener != null)
			connectionStateListener.onConnected(clc);
	}

	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
		listener.onReceive(clc, msg);
		super.channelRead(ctx, msg);
	}

	@Override