Class ChannelFactoryNioBuffer

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

public class ChannelFactoryNioBuffer
extends java.lang.Thread

ChannelFactoryNioBuffer. Channel factory using java.nio and no Thread. Deliveres ObjectChannels based on nio ByteBuffers. Usage: ChannelFactoryNioBuffer(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
(package private)  int capacity
          Capacity for ByteBuffer.
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
ChannelFactoryNioBuffer()
          Constructs a ChannelFactory using Nio and ByteBuffer.
ChannelFactoryNioBuffer(int p)
          Constructs a ChannelFactory using Nio and ByteBuffer.
ChannelFactoryNioBuffer(int p, int cap)
          Constructs a ChannelFactory using Nio and ByteBuffer.
 
Method Summary
 void close()
          Close the Channel Factory.
 ObjectBufferChannel getChannel()
          Get a new socket channel from a server socket.
 ObjectBufferChannel 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.


capacity

final int capacity
Capacity for ByteBuffer.


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

ChannelFactoryNioBuffer

public ChannelFactoryNioBuffer(int p,
                               int cap)
Constructs a ChannelFactory using Nio and ByteBuffer.

Parameters:
p - port.
cap - capacity of ByteBuffer.

ChannelFactoryNioBuffer

public ChannelFactoryNioBuffer()
Constructs a ChannelFactory using Nio and ByteBuffer. On the DEFAULT_PORT with DEFAULT_CAPACITY.


ChannelFactoryNioBuffer

public ChannelFactoryNioBuffer(int p)
Constructs a ChannelFactory using Nio and ByteBuffer. With DEFAULT_CAPACITY.

Parameters:
p - port.
Method Detail

getChannel

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

Throws:
java.io.IOException

getChannel

public ObjectBufferChannel 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.