You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Meeraj Kunnumpurath <mk...@googlemail.com> on 2009/07/14 20:15:59 UTC

NIOSocketAcceptor unbind and dispose

Hi,

I have a server written using Mina with the NIO socket acceptor. When I
shutdown the server I call unbind and dispose on the acceptor as follows,

    @Destroy
    public void stop() throws InterruptedException {
        for (IoSession session : acceptor.getManagedSessions().values()) {
            session.close(false).await();
        }
        acceptor.unbind();
        acceptor.dispose();
    }

However, on OSX if I immediately try to restart the server, it throws a bind
exception stating address is already in use. On Solaris, I am unable to
restart the server at all without bouncing the box. Below is the code I use
to start the server,

    @Init
    public void start() throws IOException {
        ExecutorService filterExecutor = new
SCA4JExecutorService(workScheduler);
        InetSocketAddress socketAddress;
        if (listenAddress == null) {
            socketAddress = new
InetSocketAddress(InetAddress.getLocalHost(), commandPort);
        } else {
            socketAddress = new InetSocketAddress(listenAddress,
commandPort);
        }
        acceptor = new NioSocketAcceptor();
        SocketSessionConfig config = acceptor.getSessionConfig();
        config.setIdleTime(IdleStatus.READER_IDLE, idleTimeout);
        acceptor.getFilterChain().addLast("threadPool", new
ExecutorFilter(filterExecutor));
        acceptor.getFilterChain().addLast("codec", new
ProtocolCodecFilter(codecFactory));
        acceptor.setHandler(ftpHandler);
        monitor.extensionStarted();
        acceptor.setCloseOnDeactivation(true);
        acceptor.bind(socketAddress);
        monitor.startFtpListener(commandPort);
    }

Any pointers would be highly useful.

Kind regards
Meeraj

Re: NIOSocketAcceptor unbind and dispose

Posted by Meeraj Kunnumpurath <mk...@googlemail.com>.
Thanks, that works like a dream.

On Tue, Jul 14, 2009 at 7:35 PM, Chowdhury, Shubhankar [WHQKA] <
Shubhankar.Chowdhury@united.com> wrote:

> Did you try setting the "reuseAddress" property on acceptor to true?
> That solved my problem in Linux.
>
> Thanks,
> Shubhankar
> 847-700-4452
>
> -----Original Message-----
> From: Meeraj Kunnumpurath [mailto:mkunnumpurath@googlemail.com]
> Sent: Tuesday, July 14, 2009 1:16 PM
> To: users@mina.apache.org
> Subject: NIOSocketAcceptor unbind and dispose
>
> Hi,
>
> I have a server written using Mina with the NIO socket acceptor. When I
> shutdown the server I call unbind and dispose on the acceptor as
> follows,
>
>    @Destroy
>    public void stop() throws InterruptedException {
>        for (IoSession session : acceptor.getManagedSessions().values())
> {
>            session.close(false).await();
>        }
>        acceptor.unbind();
>        acceptor.dispose();
>    }
>
> However, on OSX if I immediately try to restart the server, it throws a
> bind
> exception stating address is already in use. On Solaris, I am unable to
> restart the server at all without bouncing the box. Below is the code I
> use
> to start the server,
>
>    @Init
>    public void start() throws IOException {
>        ExecutorService filterExecutor = new
> SCA4JExecutorService(workScheduler);
>        InetSocketAddress socketAddress;
>        if (listenAddress == null) {
>            socketAddress = new
> InetSocketAddress(InetAddress.getLocalHost(), commandPort);
>        } else {
>            socketAddress = new InetSocketAddress(listenAddress,
> commandPort);
>        }
>        acceptor = new NioSocketAcceptor();
>        SocketSessionConfig config = acceptor.getSessionConfig();
>        config.setIdleTime(IdleStatus.READER_IDLE, idleTimeout);
>        acceptor.getFilterChain().addLast("threadPool", new
> ExecutorFilter(filterExecutor));
>        acceptor.getFilterChain().addLast("codec", new
> ProtocolCodecFilter(codecFactory));
>        acceptor.setHandler(ftpHandler);
>        monitor.extensionStarted();
>        acceptor.setCloseOnDeactivation(true);
>        acceptor.bind(socketAddress);
>        monitor.startFtpListener(commandPort);
>    }
>
> Any pointers would be highly useful.
>
> Kind regards
> Meeraj
>
>
>
>

RE: NIOSocketAcceptor unbind and dispose

Posted by "Chowdhury, Shubhankar [WHQKA]" <Sh...@united.com>.
Did you try setting the "reuseAddress" property on acceptor to true?
That solved my problem in Linux.

Thanks,
Shubhankar
847-700-4452

-----Original Message-----
From: Meeraj Kunnumpurath [mailto:mkunnumpurath@googlemail.com] 
Sent: Tuesday, July 14, 2009 1:16 PM
To: users@mina.apache.org
Subject: NIOSocketAcceptor unbind and dispose

Hi,

I have a server written using Mina with the NIO socket acceptor. When I
shutdown the server I call unbind and dispose on the acceptor as
follows,

    @Destroy
    public void stop() throws InterruptedException {
        for (IoSession session : acceptor.getManagedSessions().values())
{
            session.close(false).await();
        }
        acceptor.unbind();
        acceptor.dispose();
    }

However, on OSX if I immediately try to restart the server, it throws a
bind
exception stating address is already in use. On Solaris, I am unable to
restart the server at all without bouncing the box. Below is the code I
use
to start the server,

    @Init
    public void start() throws IOException {
        ExecutorService filterExecutor = new
SCA4JExecutorService(workScheduler);
        InetSocketAddress socketAddress;
        if (listenAddress == null) {
            socketAddress = new
InetSocketAddress(InetAddress.getLocalHost(), commandPort);
        } else {
            socketAddress = new InetSocketAddress(listenAddress,
commandPort);
        }
        acceptor = new NioSocketAcceptor();
        SocketSessionConfig config = acceptor.getSessionConfig();
        config.setIdleTime(IdleStatus.READER_IDLE, idleTimeout);
        acceptor.getFilterChain().addLast("threadPool", new
ExecutorFilter(filterExecutor));
        acceptor.getFilterChain().addLast("codec", new
ProtocolCodecFilter(codecFactory));
        acceptor.setHandler(ftpHandler);
        monitor.extensionStarted();
        acceptor.setCloseOnDeactivation(true);
        acceptor.bind(socketAddress);
        monitor.startFtpListener(commandPort);
    }

Any pointers would be highly useful.

Kind regards
Meeraj