Package edu.jas.util
Class TaggedSocketChannel
- java.lang.Object
-
- java.lang.Thread
-
- edu.jas.util.TaggedSocketChannel
-
- All Implemented Interfaces:
java.lang.Runnable
public class TaggedSocketChannel extends java.lang.ThreadTaggedSocketChannel provides a communication channel with message tags for Java objects using TCP/IP sockets.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicIntegerblockedCountBlocked threads count.private static booleandebugprivate static java.lang.StringDONEEnd message.private booleanisRunningFlag if receiver is running.private static org.apache.logging.log4j.Loggerloggerprotected java.util.Map<java.lang.Integer,java.util.concurrent.BlockingQueue>queuesQueues for each message tag.protected SocketChannelscUnderlying socket channel.
-
Constructor Summary
Constructors Constructor Description TaggedSocketChannel(SocketChannel s)Constructs a tagged socket channel on the given socket channel s.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the channel.SocketChannelgetSocket()Get the SocketChannelvoidinit()thread initialization and start.intmessages()Number of messages.java.lang.Objectreceive(java.lang.Integer tag)Receive an object.voidrun()Run receive() in an infinite loop.voidsend(java.lang.Integer tag, java.lang.Object v)Sends an object.inttagSize()Number of tags.voidterminate()Terminate the TaggedSocketChannel.java.lang.StringtoString()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 Detail
-
logger
private static final org.apache.logging.log4j.Logger logger
-
debug
private static final boolean debug
-
isRunning
private volatile boolean isRunning
Flag if receiver is running.
-
DONE
private static final java.lang.String DONE
End message.- See Also:
- Constant Field Values
-
blockedCount
private final java.util.concurrent.atomic.AtomicInteger blockedCount
Blocked threads count.
-
sc
protected final SocketChannel sc
Underlying socket channel.
-
queues
protected final java.util.Map<java.lang.Integer,java.util.concurrent.BlockingQueue> queues
Queues for each message tag.
-
-
Constructor Detail
-
TaggedSocketChannel
public TaggedSocketChannel(SocketChannel s)
Constructs a tagged socket channel on the given socket channel s.- Parameters:
s- A socket channel object.
-
-
Method Detail
-
init
public void init()
thread initialization and start.
-
getSocket
public SocketChannel getSocket()
Get the SocketChannel
-
send
public void send(java.lang.Integer tag, java.lang.Object v) throws java.io.IOExceptionSends an object.- Parameters:
tag- message tagv- object to send- Throws:
java.io.IOException
-
receive
public java.lang.Object receive(java.lang.Integer tag) throws java.lang.InterruptedException, java.io.IOException, java.lang.ClassNotFoundExceptionReceive an object.- Parameters:
tag- message tag- Returns:
- object received
- Throws:
java.lang.InterruptedExceptionjava.io.IOExceptionjava.lang.ClassNotFoundException
-
close
public void close()
Closes the channel.
-
toString
public java.lang.String toString()
To string.- Overrides:
toStringin classjava.lang.Thread- See Also:
Thread.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
public void run()
Run receive() in an infinite loop.- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread- See Also:
Thread.run()
-
terminate
public void terminate()
Terminate the TaggedSocketChannel.
-
-