class NetAccessManager extends Object implements ErrorHandler
Modifier and Type | Field and Description |
---|---|
private ConcurrentHashMap.KeySetView<MessageProcessingTask,Boolean> |
activeTasks
The set of
MessageProcessingTask 's which are not yet finished
it's, processing, tracking of active tasks is necessary to properly
cancel pending tasks in case stop() is called. |
private ChannelDataEventHandler |
channelDataEventHandler
The instance that should be notified when an incoming ChannelData message
has been processed and ready for delivery
|
private AtomicBoolean |
isStopped
Indicates if this NetAccessManager is stopped
|
private static Logger |
logger
Our class logger
|
private MessageEventHandler |
messageEventHandler
The instance that should be notified when an incoming message has been
processed and ready for delivery
|
private static ExecutorService |
messageProcessingExecutor
Thread pool to execute
MessageProcessingTask s across all
NetAccessManager s. |
private Consumer<MessageProcessingTask> |
onRawMessageProcessed
Callback to be called when scheduled MessageProcessingTask
completes processing it's RawMessage.
|
private PeerUdpMessageEventHandler |
peerUdpMessageEventHandler
The instance that should be notified when an incoming UDP message has
been processed and ready for delivery
|
private QueueStatistics |
queueStatistics
Optionally enabled QueueStatistics to keep track throughput
of processing
MessageProcessingTask |
private StunStack |
stunStack
The StunStack which has created this instance, is its owner and
is the handler that incoming message requests should be passed to.
|
private static int |
TASK_POOL_SIZE
Maximum number of
MessageProcessingTask to keep in object pool. |
private ArrayBlockingQueue<MessageProcessingTask> |
taskPool
Pool of MessageProcessingTask objects to avoid extra-allocations
of processor object per RawMessage needed to process.
|
private Map<TransportAddress,Map<TransportAddress,Connector>> |
tcpConnectors
All Connectors currently in use with TCP.
|
private Map<TransportAddress,Map<TransportAddress,Connector>> |
udpConnectors
All Connectors currently in use with UDP.
|
Constructor and Description |
---|
NetAccessManager(StunStack stunStack)
Constructs a NetAccessManager.
|
NetAccessManager(StunStack stunStack,
PeerUdpMessageEventHandler peerUdpMessageEventHandler,
ChannelDataEventHandler channelDataEventHandler)
Constructs a NetAccessManager with given peerUdpMessageEventHandler and
channelDataEventHandler.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addSocket(IceSocketWrapper socket)
Creates and starts a new access point based on the specified socket.
|
protected void |
addSocket(IceSocketWrapper socket,
TransportAddress remoteAddress)
Creates and starts a new access point based on the specified socket.
|
ChannelDataEventHandler |
getChannelDataMessageEventHandler()
Gets the ChannelDataEventHandler of this
NetAccessManager which is to be notified when incoming
ChannelData messages have been processed and are ready for delivery.
|
private Connector |
getConnector(TransportAddress localAddress,
TransportAddress remoteAddress)
Returns the Connector responsible for a particular source
address and a particular destination address.
|
(package private) MessageEventHandler |
getMessageEventHandler()
Gets the MessageEventHandler of this NetAccessManager
which is to be notified when incoming messages have been processed and
are ready for delivery.
|
(package private) StunStack |
getStunStack()
Gets the StunStack which has created this instance and is its
owner.
|
PeerUdpMessageEventHandler |
getUdpMessageEventHandler()
Gets the PeerUdpMessageEventHandler of this
NetAccessManager which is to be notified when incoming UDP
messages have been processed and are ready for delivery.
|
void |
handleError(String message,
Throwable error)
A civilized way of not caring!
|
void |
handleFatalError(Runnable callingThread,
String message,
Throwable error)
Clears the faulty thread and reports the problem.
|
private void |
onIncomingRawMessage(RawMessage message)
Enqueues incoming
RawMessage for asynchronous
processing by messageProcessingExecutor |
protected void |
removeSocket(TransportAddress localAddress,
TransportAddress remoteAddress)
Stops and deletes the specified access point.
|
(package private) void |
sendMessage(byte[] bytes,
TransportAddress srcAddr,
TransportAddress remoteAddr)
Sends the specified bytes through the specified access point.
|
(package private) void |
sendMessage(ChannelData channelData,
TransportAddress srcAddr,
TransportAddress remoteAddr)
Sends the specified stun message through the specified access point.
|
(package private) void |
sendMessage(Message stunMessage,
TransportAddress srcAddr,
TransportAddress remoteAddr)
Sends the specified stun message through the specified access point.
|
void |
stop()
Stops NetAccessManager and all of its active
MessageProcessingTask.
|
private static final Logger logger
private static ExecutorService messageProcessingExecutor
MessageProcessingTask
s across all
NetAccessManager
s.private static final int TASK_POOL_SIZE
MessageProcessingTask
to keep in object pool.
Each NetAccessManager
has it's own pool, small pool size is
enough to save allocations.private final ArrayBlockingQueue<MessageProcessingTask> taskPool
private final ConcurrentHashMap.KeySetView<MessageProcessingTask,Boolean> activeTasks
MessageProcessingTask
's which are not yet finished
it's, processing, tracking of active tasks is necessary to properly
cancel pending tasks in case stop()
is called.private final Map<TransportAddress,Map<TransportAddress,Connector>> udpConnectors
private final Map<TransportAddress,Map<TransportAddress,Connector>> tcpConnectors
private final MessageEventHandler messageEventHandler
private final PeerUdpMessageEventHandler peerUdpMessageEventHandler
private final ChannelDataEventHandler channelDataEventHandler
private final StunStack stunStack
private final AtomicBoolean isStopped
private final QueueStatistics queueStatistics
MessageProcessingTask
private final Consumer<MessageProcessingTask> onRawMessageProcessed
NetAccessManager(StunStack stunStack)
stunStack
- the StunStack which is creating the new
instance, is going to be its owner and is the handler that incoming
message requests should be passed toNetAccessManager(StunStack stunStack, PeerUdpMessageEventHandler peerUdpMessageEventHandler, ChannelDataEventHandler channelDataEventHandler)
stunStack
- the StunStack which is creating the new
instance, is going to be its owner and is the handler that
incoming message requests should be passed topeerUdpMessageEventHandler
- the PeerUdpMessageEventHandler
that will handle incoming UDP messages which are not STUN
messages and ChannelData messages.channelDataEventHandler
- the ChannelDataEventHandler that
will handle incoming UDP messages which are ChannelData
messages.MessageEventHandler getMessageEventHandler()
public PeerUdpMessageEventHandler getUdpMessageEventHandler()
public ChannelDataEventHandler getChannelDataMessageEventHandler()
StunStack getStunStack()
public void handleError(String message, Throwable error)
handleError
in interface ErrorHandler
message
- a description of the errorerror
- the error that has occurredpublic void handleFatalError(Runnable callingThread, String message, Throwable error)
handleFatalError
in interface ErrorHandler
callingThread
- the thread where the error occurred.message
- A description of the errorerror
- The error itselfprotected void addSocket(IceSocketWrapper socket)
socket
- the socket that the access point should use.protected void addSocket(IceSocketWrapper socket, TransportAddress remoteAddress)
socket
- the socket that the access point should use.remoteAddress
- the remote address of the socket of the
Connector
to be created if it is a TCP socket, or null if it
is UDP.protected void removeSocket(TransportAddress localAddress, TransportAddress remoteAddress)
localAddress
- the local address of the connector to remove.remoteAddress
- the remote address of the connector to remote. Use
null to match the Connector with no specified remote
address.public void stop()
private Connector getConnector(TransportAddress localAddress, TransportAddress remoteAddress)
localAddress
- the source address.remoteAddress
- the destination address.
Returns the Connector responsible for a particular source
address and a particular destination address, or null if there's
none.private void onIncomingRawMessage(RawMessage message)
RawMessage
for asynchronous
processing by messageProcessingExecutor
message
- RawMessage to processvoid sendMessage(Message stunMessage, TransportAddress srcAddr, TransportAddress remoteAddr) throws IllegalArgumentException, IOException
stunMessage
- the message to sendsrcAddr
- the access point to use to send the messageremoteAddr
- the destination of the message.IllegalArgumentException
- if the apDescriptor references an
access point that had not been installed,IOException
- if an error occurs while sending message bytes
through the network socket.void sendMessage(ChannelData channelData, TransportAddress srcAddr, TransportAddress remoteAddr) throws IllegalArgumentException, IOException, StunException
channelData
- the message to sendsrcAddr
- the access point to use to send the messageremoteAddr
- the destination of the message.IllegalArgumentException
- if the apDescriptor references an
access point that had not been installed,IOException
- if an error occurs while sending message bytes
through the network socket.StunException
void sendMessage(byte[] bytes, TransportAddress srcAddr, TransportAddress remoteAddr) throws IllegalArgumentException, IOException
bytes
- the bytes to send.srcAddr
- the access point to use to send the bytes.remoteAddr
- the destination of the message.IllegalArgumentException
- if the apDescriptor references an
access point that had not been installed,IOException
- if an error occurs while sending message bytes
through the network socket.Copyright © 2018. All rights reserved.