org.opcfoundation.ua.utils.asyncsocket
Class ListenableServerSocketChannel

java.lang.Object
  extended by org.opcfoundation.ua.utils.asyncsocket.ListenableServerSocketChannel

public class ListenableServerSocketChannel
extends Object

ListenableServerSocketChannel adds convenient listening mechanism over non-blocking ServerSocketChannel.

Author:
Toni Kalajainen (toni.kalajainen@vtt.fi)

Nested Class Summary
static interface ListenableServerSocketChannel.ServerSocketAcceptable
           
 
Constructor Summary
ListenableServerSocketChannel(ServerSocketChannel channel, Executor eventExecutor)
          Wrap AsyncServerSocket over given ServerSocketChannel using given event worker thread and a new selector thread.
ListenableServerSocketChannel(ServerSocketChannel channel, Executor eventExecutor, AsyncSelector t)
          Wrap AsyncServerSocket over given ServerSocketChannel using given event worker thread and selector thread.
 
Method Summary
 void bind(SocketAddress addr, int backlog)
          Binds the ServerSocket to a specific address (IP address and port number).
 void close()
          close.
 ListenableServerSocketChannel.ServerSocketAcceptable getAcceptableListener()
          Getter for the field acceptableListener.
 ServerSocketChannel getChannel()
          Getter for the field channel.
 AsyncSelector getSelectorThread()
          getSelectorThread.
 void setAcceptableListener(ListenableServerSocketChannel.ServerSocketAcceptable listener)
          Setter for the field acceptableListener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListenableServerSocketChannel

public ListenableServerSocketChannel(ServerSocketChannel channel,
                                     Executor eventExecutor,
                                     AsyncSelector t)
                              throws ClosedChannelException
Wrap AsyncServerSocket over given ServerSocketChannel using given event worker thread and selector thread.

Parameters:
channel - a ServerSocketChannel object.
eventExecutor - event executor or null for selector thread
t - selector thread
Throws:
ClosedChannelException - if any.

ListenableServerSocketChannel

public ListenableServerSocketChannel(ServerSocketChannel channel,
                                     Executor eventExecutor)
                              throws IOException
Wrap AsyncServerSocket over given ServerSocketChannel using given event worker thread and a new selector thread.

Parameters:
channel - a ServerSocketChannel object.
eventExecutor - event executor or null for selector thread
Throws:
ClosedChannelException - if any.
IOException - if any.
Method Detail

setAcceptableListener

public void setAcceptableListener(ListenableServerSocketChannel.ServerSocketAcceptable listener)

Setter for the field acceptableListener.

Parameters:
listener - a ListenableServerSocketChannel.ServerSocketAcceptable object.

getAcceptableListener

public ListenableServerSocketChannel.ServerSocketAcceptable getAcceptableListener()

Getter for the field acceptableListener.

Returns:
a ListenableServerSocketChannel.ServerSocketAcceptable object.

getChannel

public ServerSocketChannel getChannel()

Getter for the field channel.

Returns:
a ServerSocketChannel object.

getSelectorThread

public AsyncSelector getSelectorThread()

getSelectorThread.

Returns:
a AsyncSelector object.

close

public void close()
           throws IOException

close.

Throws:
IOException - if any.

bind

public void bind(SocketAddress addr,
                 int backlog)
          throws IOException
Binds the ServerSocket to a specific address (IP address and port number).

If the address is null, then the system will pick up an ephemeral port and a valid local address to bind the socket.

The backlog argument must be a positive value greater than 0. If the value passed if equal or less than 0, then the default value will be assumed.

Parameters:
addr - address
backlog - backlog
Throws:
IllegalArgumentException - if endpoint is a SocketAddress subclass not supported by this socket
IOException - if error


Copyright © 2018. All rights reserved.