Class TaggedSocketChannel
java.lang.Object
java.lang.Thread
edu.jas.util.TaggedSocketChannel
- All Implemented Interfaces:
Runnable
TaggedSocketChannel provides a communication channel with message tags for
Java objects using TCP/IP sockets.
-
Nested Class Summary
Nested classes/interfaces inherited from class Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicIntegerBlocked threads count.private static final booleanprivate static final StringEnd message.private booleanFlag if receiver is running.private static final org.apache.logging.log4j.Loggerprotected final Map<Integer, BlockingQueue> Queues for each message tag.protected final SocketChannelUnderlying socket channel.Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a tagged socket channel on the given socket channel s. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the channel.Get the SocketChannelvoidinit()thread initialization and start.intmessages()Number of messages.Receive an object.voidrun()Run receive() in an infinite loop.voidSends an object.inttagSize()Number of tags.voidTerminate the TaggedSocketChannel.toString()To string.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 -
isRunning
private volatile boolean isRunningFlag if receiver is running. -
DONE
-
blockedCount
Blocked threads count. -
sc
Underlying socket channel. -
queues
Queues for each message tag.
-
-
Constructor Details
-
TaggedSocketChannel
Constructs a tagged socket channel on the given socket channel s.- Parameters:
s- A socket channel object.
-
-
Method Details
-
init
public void init()thread initialization and start. -
getSocket
Get the SocketChannel -
send
Sends an object.- Parameters:
tag- message tagv- object to send- Throws:
IOException
-
receive
Receive an object.- Parameters:
tag- message tag- Returns:
- object received
- Throws:
InterruptedExceptionIOExceptionClassNotFoundException
-
close
public void close()Closes the channel. -
toString
-
tagSize
public int tagSize()Number of tags.- Returns:
- size of key set.
-
messages
public int messages()Number of messages.- Returns:
- sum of all messages in queues.
-
run
-
terminate
public void terminate()Terminate the TaggedSocketChannel.
-