Class TcpConnection
- java.lang.Object
-
- org.objectweb.joram.mom.proxies.tcp.TcpConnection
-
- All Implemented Interfaces:
ProxyMessageSender,TcpConnectionMBean
public class TcpConnection extends Object implements TcpConnectionMBean, ProxyMessageSender
Handles the TCP connection. Starts the reader and writer threads responsible for reading the requests and writing the replies. Calls theUserConnectionin order to invoke the user's proxy and get its replies.- See Also:
TcpProxyService,TcpConnectionListener
-
-
Field Summary
Fields Modifier and Type Field Description private booleancloseConnectionprivate DatecreationDateprivate ReliableConnectionContextctxprivate static booleanDEBUGprivate Identityidentityprivate IOControlioctrlprivate static Loggerloggerloggerprivate AgentIdproxyIdprivate TcpProxyServiceproxyServiceThe TCP proxy service used to register and unregister this connection.private TcpReadertcpReaderThe reader thread responsible for reading the requests (input).private TcpWritertcpWriterThe writer thread responsible for writing the replies (output).
-
Constructor Summary
Constructors Constructor Description TcpConnection(IOControl ioctrl, ReliableConnectionContext ctx, AgentId proxyId, TcpProxyService proxyService, Identity identity)Creates a new TCP connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Stops the connection reader and writer threads.voidexecute(Runnable runnable)Executes a task.intgetAckedQueueSize()Gets the AckedQueue size.StringgetAddress()Gets the socket address used by the connection.DategetCreationDate()Gets connection creation date.intgetKey()private StringgetMBeanName()AgentIdgetProxyId()intgetQueueWorkerSize()Gets the QueueWorker size.intgetReaderQueueSize()Gets the ReaderQueue size.longgetReceivedCount()Gets the number of replies received on the connection.longgetSentCount()Gets the number of requests sent on the connection.StringgetUserName()Gets connected user's name.booleanisExecutor()States whether executing a task is allowed.voidsend(ProxyMessage msg)Sends a message to the client.(package private) voidstart()Starts the connection reader and writer threads.
-
-
-
Field Detail
-
logger
private static final Logger logger
logger
-
DEBUG
private static final boolean DEBUG
-
ioctrl
private IOControl ioctrl
-
proxyId
private AgentId proxyId
-
ctx
private ReliableConnectionContext ctx
-
tcpReader
private TcpReader tcpReader
The reader thread responsible for reading the requests (input).
-
tcpWriter
private TcpWriter tcpWriter
The writer thread responsible for writing the replies (output).
-
proxyService
private TcpProxyService proxyService
The TCP proxy service used to register and unregister this connection.
-
closeConnection
private boolean closeConnection
-
identity
private Identity identity
-
creationDate
private Date creationDate
-
-
Constructor Detail
-
TcpConnection
public TcpConnection(IOControl ioctrl, ReliableConnectionContext ctx, AgentId proxyId, TcpProxyService proxyService, Identity identity)
Creates a new TCP connection.- Parameters:
ioctrl-ctx-proxyId-proxyService- the TCP proxy serviceidentity-
-
-
Method Detail
-
getMBeanName
private String getMBeanName()
-
getProxyId
public final AgentId getProxyId()
-
getKey
public final int getKey()
-
start
void start() throws ExceptionStarts the connection reader and writer threads.- Throws:
Exception
-
close
public void close()
Stops the connection reader and writer threads. Closes the socket.- Specified by:
closein interfaceProxyMessageSender- Specified by:
closein interfaceTcpConnectionMBean
-
getUserName
public String getUserName()
Description copied from interface:TcpConnectionMBeanGets connected user's name.- Specified by:
getUserNamein interfaceTcpConnectionMBean- Returns:
- the name of the connected user.
-
getAddress
public String getAddress()
Description copied from interface:TcpConnectionMBeanGets the socket address used by the connection.- Specified by:
getAddressin interfaceTcpConnectionMBean- Returns:
- the connection's socket address.
-
getCreationDate
public Date getCreationDate()
Description copied from interface:TcpConnectionMBeanGets connection creation date.- Specified by:
getCreationDatein interfaceTcpConnectionMBean- Returns:
- the date of creation of the connection.
-
getReceivedCount
public long getReceivedCount()
Description copied from interface:TcpConnectionMBeanGets the number of replies received on the connection.- Specified by:
getReceivedCountin interfaceTcpConnectionMBean- Returns:
- the number of replies received on the connection.
-
getSentCount
public long getSentCount()
Description copied from interface:TcpConnectionMBeanGets the number of requests sent on the connection.- Specified by:
getSentCountin interfaceTcpConnectionMBean- Returns:
- the number of requests sent on the connection.
-
getAckedQueueSize
public int getAckedQueueSize()
Description copied from interface:TcpConnectionMBeanGets the AckedQueue size.- Specified by:
getAckedQueueSizein interfaceTcpConnectionMBean- Returns:
- the size of AckedQueue.
-
getQueueWorkerSize
public int getQueueWorkerSize()
Description copied from interface:TcpConnectionMBeanGets the QueueWorker size.- Specified by:
getQueueWorkerSizein interfaceTcpConnectionMBean- Returns:
- the size of QueueWorker.
-
getReaderQueueSize
public int getReaderQueueSize()
Description copied from interface:TcpConnectionMBeanGets the ReaderQueue size.- Specified by:
getReaderQueueSizein interfaceTcpConnectionMBean- Returns:
- the size of ReaderQueue.
-
send
public void send(ProxyMessage msg) throws Exception
Description copied from interface:ProxyMessageSenderSends a message to the client.- Specified by:
sendin interfaceProxyMessageSender- Parameters:
msg- the message to be sent- Throws:
Exception- if an error occurs
-
isExecutor
public boolean isExecutor()
Description copied from interface:ProxyMessageSenderStates whether executing a task is allowed.- Specified by:
isExecutorin interfaceProxyMessageSender- Returns:
trueif executing a task is allowed;falseotherwise.
-
execute
public void execute(Runnable runnable)
Description copied from interface:ProxyMessageSenderExecutes a task.- Specified by:
executein interfaceProxyMessageSender- Parameters:
runnable- task to be executed
-
-