Package edu.jas.util
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 java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicInteger
Blocked threads count.private static final boolean
private static final String
End message.private boolean
Flag if receiver is running.private static final org.apache.logging.log4j.Logger
protected final Map
<Integer, BlockingQueue> Queues for each message tag.protected final SocketChannel
Underlying socket channel.Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a tagged socket channel on the given socket channel s. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the channel.Get the SocketChannelvoid
init()
thread initialization and start.int
messages()
Number of messages.Receive an object.void
run()
Run receive() in an infinite loop.void
Sends an object.int
tagSize()
Number of tags.void
Terminate the TaggedSocketChannel.toString()
To string.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 -
isRunning
private volatile boolean isRunningFlag if receiver is running. -
DONE
End message.- See Also:
-
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:
InterruptedException
IOException
ClassNotFoundException
-
close
public void close()Closes the channel. -
toString
To string. -
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
public void run()Run receive() in an infinite loop. -
terminate
public void terminate()Terminate the TaggedSocketChannel.
-