comm
Class ChannelFactory

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

public class ChannelFactory
extends java.lang.Thread

ChannelFactory. A symmetric and non blocking way of setting up sockets on the client and server side. The constructor sets up a ServerSocket and accepts and stores any Socket creation requests from clients. The created Sockets can the be retrieved from the store without blocking.

Author:
Akitoshi Yoshida, Heinz Kredel.
See Also:
SocketChannel

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  BoundedBuffer buf
          BoundedBuffer for sockets.
static int DEFAULT_PORT
          default port of socket.
private static Logger logger
           
private  int port
          port of socket.
private  java.net.ServerSocket srv
          local server socket.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ChannelFactory()
          Constructs a ChannelFactory.
ChannelFactory(int p)
          Constructs a ChannelFactory.
 
Method Summary
 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.
 void run()
           
 void terminate()
          Terminate the Channel Factory.
 
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, 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

logger

private static Logger logger

DEFAULT_PORT

public static final int DEFAULT_PORT
default port of socket.

See Also:
Constant Field Values

port

private int port
port of socket.


buf

private BoundedBuffer buf
BoundedBuffer for sockets.


srv

private java.net.ServerSocket srv
local server socket.

Constructor Detail

ChannelFactory

public ChannelFactory(int p)
Constructs a ChannelFactory.

Parameters:
p - port.

ChannelFactory

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

Method Detail

getChannel

public SocketChannel getChannel()
                         throws java.lang.InterruptedException
Get a new socket channel from a server socket.

Throws:
java.lang.InterruptedException

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

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

terminate

public void terminate()
Terminate the Channel Factory.