Package edu.jas.util
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 java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BlockingQueue
<SocketChannel> BoundedBuffer for sockets.private static final boolean
static final int
default port of socket.private static final org.apache.logging.log4j.Logger
private final int
port of socket.private ServerSocket
local server socket.private boolean
is local server up and running.private boolean
is thread started.Fields inherited from class java.lang.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.void
init()
thread initialization and start.void
run()
Run the servers accept() in an infinite loop.void
Terminate the Channel FactorytoString()
toString.Methods inherited from class java.lang.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
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
public void run()Run the servers accept() in an infinite loop. -
terminate
public void terminate()Terminate the Channel Factory
-