You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Emmanuel Lecharny (JIRA)" <ji...@apache.org> on 2014/09/07 07:45:28 UTC

[jira] [Comment Edited] (DIRMINA-389) Create a Connection Throttle Filter

    [ https://issues.apache.org/jira/browse/DIRMINA-389?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12507757#comment-12507757 ] 

Emmanuel Lecharny edited comment on DIRMINA-389 at 9/7/14 5:45 AM:
-------------------------------------------------------------------

----- SERVER CODE -----
{code}
public class ConnFilterServer extends IoHandlerAdapter {

	protected static final int PORT = 5678;
	
	public ConnFilterServer() throws IOException{
		IoAcceptor acceptor = new SocketAcceptor();
		ConnectionThrottleFilter ctFilter = new ConnectionThrottleFilter();
		acceptor.getFilterChain().addLast("ConnThrottle", ctFilter);
		acceptor.setHandler( this );
		acceptor.setLocalAddress( new InetSocketAddress(PORT));
		acceptor.bind();
		System.out.println("Connection Filter Server running...");
	}

	public void sessionClosed(IoSession session) throws Exception {
		SessionLog.info( session, "The session has been closed" );
	}
	
	public static void main(String[] args) throws IOException {
		new ConnFilterServer();
	}
}

{code}
--- END SERVER CODE ----


---CLIENT CODE---

{code}
public class ConnFilterClient extends IoHandlerAdapter implements IoFutureListener {

	public ConnFilterClient(){
		makeConnection( "localhost", ConnFilterServer.PORT );
		makeConnection( "localhost", ConnFilterServer.PORT );
	}
	
	private void makeConnection( String host, int port){
		IoConnector connector = new SocketConnector();
		connector.setHandler( this );
		ConnectFuture connFuture = connector.connect( new InetSocketAddress(host,port));
		connFuture.addListener( this );
	}
	
	public void operationComplete(IoFuture future) {
		if( future instanceof ConnectFuture ){
			ConnectFuture connFuture = (ConnectFuture)future;
			if( connFuture.isConnected() ){
				System.out.println("Connected...");
				IoSession session = connFuture.getSession();
				session.write( ByteBuffer.wrap("Hello World".getBytes()) );
			}
		}
	}

	public static void main(String[] args) {
		new ConnFilterClient();
	}
}

{code}
--- END CLIENT CODE ---


was (Author: elihusmails):
----- SERVER CODE -----
public class ConnFilterServer extends IoHandlerAdapter {

	protected static final int PORT = 5678;
	
	public ConnFilterServer() throws IOException{
		IoAcceptor acceptor = new SocketAcceptor();
		ConnectionThrottleFilter ctFilter = new ConnectionThrottleFilter();
		acceptor.getFilterChain().addLast("ConnThrottle", ctFilter);
		acceptor.setHandler( this );
		acceptor.setLocalAddress( new InetSocketAddress(PORT));
		acceptor.bind();
		System.out.println("Connection Filter Server running...");
	}

	public void sessionClosed(IoSession session) throws Exception {
		SessionLog.info( session, "The session has been closed" );
	}
	
	public static void main(String[] args) throws IOException {
		new ConnFilterServer();
	}
}
--- END SERVER CODE ----


---CLIENT CODE---
public class ConnFilterClient extends IoHandlerAdapter implements IoFutureListener {

	public ConnFilterClient(){
		makeConnection( "localhost", ConnFilterServer.PORT );
		makeConnection( "localhost", ConnFilterServer.PORT );
	}
	
	private void makeConnection( String host, int port){
		IoConnector connector = new SocketConnector();
		connector.setHandler( this );
		ConnectFuture connFuture = connector.connect( new InetSocketAddress(host,port));
		connFuture.addListener( this );
	}
	
	public void operationComplete(IoFuture future) {
		if( future instanceof ConnectFuture ){
			ConnectFuture connFuture = (ConnectFuture)future;
			if( connFuture.isConnected() ){
				System.out.println("Connected...");
				IoSession session = connFuture.getSession();
				session.write( ByteBuffer.wrap("Hello World".getBytes()) );
			}
		}
	}

	public static void main(String[] args) {
		new ConnFilterClient();
	}
}
--- END CLIENT CODE ---

> Create a Connection Throttle Filter
> -----------------------------------
>
>                 Key: DIRMINA-389
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-389
>             Project: MINA
>          Issue Type: New Feature
>          Components: Filter
>         Environment: All
>            Reporter: Mark Webb
>            Assignee: Mark Webb
>            Priority: Minor
>             Fix For: 2.0.8
>
>
> Create a filter that will throttle connections.  This filter will monitor newly created sessions and if new connections from the same IP address come in too fast, drop the connections.  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)