Class ChannelFactoryNio

java.lang.Object
  extended by java.lang.Thread
      extended by ChannelFactoryNio
All Implemented Interfaces:
java.lang.Runnable

public class ChannelFactoryNio
extends java.lang.Thread

ChannelFactoryNio. Socket channel factory using java.nio and no Thread. Usage: ChannelFactoryNio(port).

Author:
Heinz Kredel.

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int DEFAULT_PORT
          default port of socket.
private  int port
          port of socket.
private  java.nio.channels.Selector selector
          local selector.
private  java.nio.channels.ServerSocketChannel server
          local server socket channel.
private  java.nio.channels.SelectionKey serverkey
          local server key.
static int WAIT_TIME
          wait time 500ms.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ChannelFactoryNio()
          Constructs a ChannelFactory Nio.
ChannelFactoryNio(int p)
          Constructs a ChannelFactory using Nio.
 
Method Summary
 void close()
          Close the Channel Factory.
 SocketChannel getChannel()
          Get a new socket channel from a server socket.
 SocketChannel getChannel(java.lang.String h, int p)
          Get a new socket channel to a given host.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
default port of socket.

See Also:
Constant Field Values

WAIT_TIME

public static final int WAIT_TIME
wait time 500ms.

See Also:
Constant Field Values

port

private final int port
port of socket.


selector

private java.nio.channels.Selector selector
local selector.


serverkey

private java.nio.channels.SelectionKey serverkey
local server key.


server

private java.nio.channels.ServerSocketChannel server
local server socket channel.

Constructor Detail

ChannelFactoryNio

public ChannelFactoryNio(int p)
Constructs a ChannelFactory using Nio.

Parameters:
p - port.

ChannelFactoryNio

public ChannelFactoryNio()
Constructs a ChannelFactory Nio. on the DEFAULT_PORT.

Method Detail

getChannel

public SocketChannel getChannel()
                         throws java.io.IOException
Get a new socket channel from a server socket.

Throws:
java.io.IOException

getChannel

public SocketChannel getChannel(java.lang.String h,
                                int p)
                         throws java.io.IOException
Get a new socket channel to a given host.

Parameters:
h - hostname.
p - port.
Throws:
java.io.IOException

close

public void close()
Close the Channel Factory.