public class NIOHandler extends Object
Modifier and Type | Field and Description |
---|---|
protected HashMap<SocketChannel,NioTcpMessageChannel> |
channelMap |
protected SocketTimeoutAuditor |
socketTimeoutAuditor |
Modifier | Constructor and Description |
---|---|
protected |
NIOHandler(SIPTransactionStack sipStack,
NioTcpMessageProcessor messageProcessor) |
Modifier and Type | Method and Description |
---|---|
void |
closeAll()
Close all the cached connections.
|
SocketChannel |
createOrReuseSocket(InetAddress inetAddress,
int port) |
int |
getCurrentChannelSize() |
NioTcpMessageChannel |
getMessageChannel(SocketChannel socketChannel) |
protected SocketChannel |
getSocket(String key) |
protected static String |
makeKey(InetAddress addr,
int port) |
protected static String |
makeKey(String addr,
int port) |
void |
putMessageChannel(SocketChannel socketChannel,
NioTcpMessageChannel nioTcpMessageChannel) |
protected void |
putSocket(String key,
SocketChannel sock)
Thread safety delivered through keyedSemaphore.
|
void |
removeMessageChannel(SocketChannel socketChannel) |
protected void |
removeSocket(SocketChannel channel)
Searches matching socket in internal map, and then removes from internal
structures.
|
SocketChannel |
sendBytes(InetAddress senderAddress,
InetAddress receiverAddress,
int contactPort,
String transport,
byte[] bytes,
boolean retry,
NioTcpMessageChannel messageChannel)
Send an array of bytes.
|
void |
stop() |
protected SocketTimeoutAuditor socketTimeoutAuditor
protected HashMap<SocketChannel,NioTcpMessageChannel> channelMap
protected NIOHandler(SIPTransactionStack sipStack, NioTcpMessageProcessor messageProcessor)
public NioTcpMessageChannel getMessageChannel(SocketChannel socketChannel)
public void putMessageChannel(SocketChannel socketChannel, NioTcpMessageChannel nioTcpMessageChannel)
public void removeMessageChannel(SocketChannel socketChannel)
public int getCurrentChannelSize()
protected static String makeKey(InetAddress addr, int port)
protected void putSocket(String key, SocketChannel sock)
key
- sock
- protected SocketChannel getSocket(String key)
protected void removeSocket(SocketChannel channel)
channel
- public SocketChannel sendBytes(InetAddress senderAddress, InetAddress receiverAddress, int contactPort, String transport, byte[] bytes, boolean retry, NioTcpMessageChannel messageChannel) throws IOException
receiverAddress
- -- inet addresscontactPort
- -- port to connect to.transport
- -- tcp or udp.retry
- -- retry to connect if the other end closed connectionIOException
- -- if there is an IO exception sending message.public void closeAll()
public void stop()
public SocketChannel createOrReuseSocket(InetAddress inetAddress, int port) throws IOException
IOException
Copyright © 2018. All Rights Reserved.