public class StunClientTransaction extends Object
StunClientTransaction
class retransmits requests as specified by
RFC 3489.
Once formulated and sent, the client sends the Binding Request. Reliability
is accomplished through request retransmissions. The
StunClientTransaction
retransmits the request starting with an
interval of 100ms, doubling every retransmit until the interval reaches 1.6s.
Retransmissions continue with intervals of 1.6s until a response is received,
or a total of 9 requests have been sent. If no response is received by 1.6
seconds after the last request has been sent, the client SHOULD consider the
transaction to have failed. In other words, requests would be sent at times
0ms, 100ms, 300ms, 700ms, 1500ms, 3100ms, 4700ms, 6300ms, and 7900ms. At
9500ms, the client considers the transaction to have failed if no response
has been received.Modifier and Type | Class and Description |
---|---|
private class |
StunClientTransaction.Retransmitter
Implements the retransmissions algorithm.
|
Modifier and Type | Field and Description |
---|---|
private AtomicBoolean |
cancelled
Determines whether the transaction is active or not.
|
static int |
DEFAULT_MAX_RETRANSMISSIONS
The number of times to retransmit a request if no explicit value has been
specified by org.ice4j.MAX_RETRANSMISSIONS.
|
static int |
DEFAULT_MAX_WAIT_INTERVAL
The maximum number of milliseconds a client should wait between
consecutive retransmissions, after it has sent a request for the first
time.
|
static int |
DEFAULT_ORIGINAL_WAIT_INTERVAL
The number of milliseconds a client should wait before retransmitting,
after it has sent a request for the first time.
|
private TransportAddress |
localAddress
The TransportAddress through which the original request was sent
and that we are supposed to be retransmitting through.
|
private static Logger |
logger
Our class logger.
|
int |
maxRetransmissions
Maximum number of retransmissions.
|
int |
maxWaitInterval
The maximum wait interval.
|
int |
originalWaitInterval
The number of milliseconds to wait before the first retransmission of the
request.
|
private Request |
request
The request that we are retransmitting.
|
private TransportAddress |
requestDestination
The destination of the request.
|
private ResponseCollector |
responseCollector
The instance to notify when a response has been received in the current
transaction or when it has timed out.
|
private static ScheduledExecutorService |
retransmissionThreadPool
The pool of Threads which retransmit
StunClientTransactions.
|
private StunClientTransaction.Retransmitter |
retransmitter
A transaction request retransmitter
|
private StunStack |
stackCallback
The StunStack that created us.
|
private TransactionID |
transactionID
The id of the transaction.
|
Constructor and Description |
---|
StunClientTransaction(StunStack stackCallback,
Request request,
TransportAddress requestDestination,
TransportAddress localAddress,
ResponseCollector responseCollector)
Creates a client transaction.
|
StunClientTransaction(StunStack stackCallback,
Request request,
TransportAddress requestDestination,
TransportAddress localAddress,
ResponseCollector responseCollector,
TransactionID transactionID)
Creates a client transaction.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
cancel()
Cancels the transaction.
|
TransportAddress |
getLocalAddress()
Returns the local TransportAddress that this transaction is
sending requests from.
|
TransportAddress |
getRemoteAddress()
Returns the remote TransportAddress that this transaction is
sending requests to.
|
(package private) Request |
getRequest()
Returns the request that was the reason for creating this transaction.
|
(package private) TransactionID |
getTransactionID()
Returns the ID of the current transaction.
|
void |
handleResponse(StunMessageEvent evt)
Dispatches the response then cancels itself and notifies the StunStack
for its termination.
|
private void |
initTransactionConfiguration()
Init transaction duration/retransmission parameters.
|
(package private) void |
sendRequest()
Sends the request and schedules the first retransmission for after
originalWaitInterval and thus starts the retransmission
algorithm. |
private void |
sendRequest0()
Simply calls the sendMessage method of the accessmanager.
|
private static final Logger logger
public static final int DEFAULT_MAX_RETRANSMISSIONS
public static final int DEFAULT_MAX_WAIT_INTERVAL
public static final int DEFAULT_ORIGINAL_WAIT_INTERVAL
private static final ScheduledExecutorService retransmissionThreadPool
public int maxRetransmissions
maxWaitInterval
milliseconds the
request is considered unanswered.public int originalWaitInterval
public int maxWaitInterval
private final StunStack stackCallback
private final Request request
private final TransportAddress requestDestination
private final TransactionID transactionID
private final TransportAddress localAddress
private final ResponseCollector responseCollector
private final AtomicBoolean cancelled
private final StunClientTransaction.Retransmitter retransmitter
public StunClientTransaction(StunStack stackCallback, Request request, TransportAddress requestDestination, TransportAddress localAddress, ResponseCollector responseCollector)
stackCallback
- the stack that created us.request
- the request that we are living for.requestDestination
- the destination of the request.localAddress
- the local TransportAddress this transaction
will be communication through.responseCollector
- the instance that should receive this request's
response retransmit.public StunClientTransaction(StunStack stackCallback, Request request, TransportAddress requestDestination, TransportAddress localAddress, ResponseCollector responseCollector, TransactionID transactionID)
stackCallback
- the stack that created us.request
- the request that we are living for.requestDestination
- the destination of the request.localAddress
- the local TransportAddress this transaction
will be communication through.responseCollector
- the instance that should receive this request's
response retransmit.transactionID
- the ID that we'd like the new transaction to have
in case the application created it in order to use it for application
data correlation.void sendRequest() throws IllegalArgumentException, IOException
originalWaitInterval
and thus starts the retransmission
algorithm.IOException
- if an error occurs while sending message bytes
through the network socket.IllegalArgumentException
- if the apDescriptor references an
access point that had not been installedprivate void sendRequest0() throws IllegalArgumentException, IOException
IOException
- if an error occurs while sending message bytes
through the network socket.IllegalArgumentException
- if the apDescriptor references an
access point that had not been installed,Request getRequest()
void cancel()
public void handleResponse(StunMessageEvent evt)
evt
- the event that contains the newly received messageTransactionID getTransactionID()
private void initTransactionConfiguration()
public TransportAddress getLocalAddress()
public TransportAddress getRemoteAddress()
Copyright © 2018. All rights reserved.