[
https://issues.apache.org/jira/browse/DIRMINA-596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12650127#action_12650127
]
Silver commented on DIRMINA-596:
--------------------------------
**********************************************************************************
package sample;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.executor.ExecutorFilter;
import org.apache.mina.transport.socket.nio.NioSocketConnector;
public class MinaTest
{
private MyHandler handler;
private NioSocketConnector connector;
private InetSocketAddress address;
private class MyHandler extends IoHandlerAdapter
{
/**
* @param session
* @param cause
* @throws Exception
*/
public void exceptionCaught(IoSession session, Throwable cause) throws
Exception
{
System.out.println(session + " : an exception occurred.");
cause.printStackTrace();
}
/**
* @param session
* @param message
* @throws Exception
*/
public void messageReceived(IoSession session, Object message) throws
Exception
{
System.out.println(session + " received: " + ((IoBuffer)
message).getString(Charset.forName("UTF-8")
.newDecoder()));
session.close();
}
/**
* @param session
* @throws Exception
*/
public void sessionClosed(IoSession session) throws Exception
{
System.out.println(session + " closed.");
}
/**
* @param session
* @throws Exception
*/
@Override
public void sessionCreated(IoSession session) throws Exception
{
System.out.println(session + " created.");
session.write(IoBuffer.wrap(";".getBytes()));
}
}
public void initialize()
{
address = new InetSocketAddress("127.0.0.1", 2361);
handler = new MyHandler();
connector = new NioSocketConnector();
connector.setHandler(handler);
connector.setDefaultRemoteAddress(address);
connector.setConnectTimeoutMillis(5000);
connector.getFilterChain().addLast( "executor", new ExecutorFilter(100)
);
}
public void run()
{
for(int i=0; i<10; i++)
{
connector.connect();
}
}
public static void main(String[] args)
{
MinaTest tester = new MinaTest();
tester.initialize();
tester.run();
System.out.println("MinaTest is running now...");
}
}
************************************************************************************
To Emmanuel Lecharny :
The attached code has the problem under MINA 2.0 M1/M2, but it's OK under
M3.
I don't know what has changed, but thank you very much all the same.
> Sessions generated by NioSocketConnector cannot be closed in time (within
> MINA2.0 M1,M2)
> ----------------------------------------------------------------------------------------
>
> Key: DIRMINA-596
> URL: https://issues.apache.org/jira/browse/DIRMINA-596
> Project: MINA
> Issue Type: Bug
> Components: Core, Transport
> Affects Versions: 2.0.0-M1, 2.0.0-M2
> Environment: MINA:mina-core-2.0.0-M2-20080427.091119-1.jar
> JDK: java version "1.5.0_05"
> Plat: Windows XP
> Reporter: Silver
>
> I use MINA 2.0.0 M1 and M2 to build my application.
> When I use one NioSocketConnector to generate 10 sessions and then close them
> in the messageReceived event of each session, only 5 or 6 sessions(that is to
> say, not of all sessions) can be closed correctly, others cannot, but I can
> receive the sessionClosed event. The number of the closed sessions varies
> from 2-6 during my experiments.
> Another intersting event will occur:
> Since the rest sessions cannot be closed, I tried to generate a new
> session by the same NioSocketConnector, then all of the 10 "old" sessions
> were closed as one might expect, except the last new session.
> the main method:
> public static void main(String[] args)
> {
> NioSocketConnector acceptor = new NioSocketConnector();
> acceptor.setDefaultRemoteAddress(new InetSocketAddress("127.0.0.1",
> 2361));
> acceptor.getFilterChain().addLast( "executor", new
> ExecutorFilter(100) );
> acceptor.setHandler( new TimeServerHandler() );
> for(int i=0; i<10; i++)
> acceptor.connect();
> }
> the messageReceived method in TimeServerHandler class:
> public void messageReceived(IoSession session, Object message)
> throws Exception
> {
> System.out.println(((IoBuffer)
> message).getString(Charset.forName("UTF-8")
> .newDecoder()));
> session.close();
> }
> the log of the test server:
> 2008-5-27 17:09:32 Connected ++++++++++++++++++++++++127.0.0.1 / 3211>
> 2008-5-27 17:09:32 Connected ++++++++++++++++++++++++127.0.0.1 / 3212>
> 2008-5-27 17:09:32 Connected ++++++++++++++++++++++++127.0.0.1 / 3213>
> 2008-5-27 17:09:32 Connected ++++++++++++++++++++++++127.0.0.1 / 3214>
> 2008-5-27 17:09:32 Connected ++++++++++++++++++++++++127.0.0.1 / 3215>
> 2008-5-27 17:09:32 Connected ++++++++++++++++++++++++127.0.0.1 / 3216>
> 2008-5-27 17:09:32 Connected ++++++++++++++++++++++++127.0.0.1 / 3217>
> 2008-5-27 17:09:32 Connected ++++++++++++++++++++++++127.0.0.1 / 3218>
> 2008-5-27 17:09:32 Connected ++++++++++++++++++++++++127.0.0.1 / 3219>
> 2008-5-27 17:09:32 Connected ++++++++++++++++++++++++127.0.0.1 / 3220>
> 2008-5-27 17:09:32 Disconnected -----------------------127.0.0.1 / 3211>
> 2008-5-27 17:09:32 Disconnected -----------------------127.0.0.1 / 3213>
> 2008-5-27 17:09:32 Disconnected -----------------------127.0.0.1 / 3214>
> 2008-5-27 17:09:32 Disconnected -----------------------127.0.0.1 / 3212>
> 2008-5-27 17:09:32 Disconnected -----------------------127.0.0.1 / 3216>
> 2008-5-27 17:09:32 Disconnected -----------------------127.0.0.1 / 3215>
> 2008-5-27 17:09:37 Connected ++++++++++++++++++++++++127.0.0.1 / 3221>
> 2008-5-27 17:09:37 Disconnected -----------------------127.0.0.1 / 3217>
> 2008-5-27 17:09:37 Disconnected -----------------------127.0.0.1 / 3218>
> 2008-5-27 17:09:37 Disconnected -----------------------127.0.0.1 / 3219>
> 2008-5-27 17:09:37 Disconnected -----------------------127.0.0.1 / 3220>
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.