Class ChannelFactory
java.lang.Object
java.lang.Thread
edu.jas.util.ChannelFactory
- All Implemented Interfaces:
Runnable
ChannelFactory implements 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. Refactored for
java.util.concurrent.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BlockingQueue<SocketChannel> BoundedBuffer for sockets.private static final booleanstatic final intdefault port of socket.private static final org.apache.logging.log4j.Loggerprivate final intport of socket.private ServerSocketlocal server socket.private booleanis local server up and running.private booleanis thread started.Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a ChannelFactory on the DEFAULT_PORT.ChannelFactory(int p) Constructs a ChannelFactory. -
Method Summary
Modifier and TypeMethodDescriptionGet a new socket channel from a server socket.getChannel(String h) Get a new socket channel to a given host.getChannel(String h, int p) Get a new socket channel to a given host.voidinit()thread initialization and start.voidrun()Run the servers accept() in an infinite loop.voidTerminate the Channel FactorytoString()toString.Methods inherited from class Thread
activeCount, checkAccess, clone, 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, yield
-
Field Details
-
logger
private static final org.apache.logging.log4j.Logger logger -
debug
private static final boolean debug -
DEFAULT_PORT
public static final int DEFAULT_PORTdefault port of socket.- See Also:
-
port
private final int portport of socket. -
buf
BoundedBuffer for sockets. -
srv
local server socket. -
srvrun
private volatile boolean srvrunis local server up and running. -
srvstart
private volatile boolean srvstartis thread started.
-
-
Constructor Details
-
ChannelFactory
public ChannelFactory()Constructs a ChannelFactory on the DEFAULT_PORT. -
ChannelFactory
public ChannelFactory(int p) Constructs a ChannelFactory.- Parameters:
p- port.
-
-
Method Details
-
toString
-
init
public void init()thread initialization and start. -
getChannel
Get a new socket channel from a server socket.- Throws:
InterruptedException
-
getChannel
Get a new socket channel to a given host.- Parameters:
h- hostname- Throws:
IOException
-
getChannel
Get a new socket channel to a given host.- Parameters:
h- hostnamep- port- Throws:
IOException
-
run
-
terminate
public void terminate()Terminate the Channel Factory
-