diff --git a/src/org/ice4j/StunException.java b/src/org/ice4j/StunException.java
index a65ff1e..a11ad8d 100644
--- a/src/org/ice4j/StunException.java
+++ b/src/org/ice4j/StunException.java
@@ -7,14 +7,15 @@
package org.ice4j;
/**
- * A StunException is thrown when a general STUN exception is encountered.
+ * A StunException is thrown when a general STUN exception is
+ * encountered.
*
* @author Emil Ivov
*/
public class StunException extends Exception
{
/**
- * Serial version UID for this Serializable class.
+ * Serial version UID for this Serializable class.
*/
private static final long serialVersionUID = 35367793L;
diff --git a/src/org/ice4j/TransportAddress.java b/src/org/ice4j/TransportAddress.java
index dafd7e1..230315d 100644
--- a/src/org/ice4j/TransportAddress.java
+++ b/src/org/ice4j/TransportAddress.java
@@ -265,7 +265,7 @@ public class TransportAddress
}
}
- //may add more unreachability condition here in the future;
+ //may add more unreachability conditions here in the future;
return true;
}
diff --git a/src/org/ice4j/attribute/DataAttribute.java b/src/org/ice4j/attribute/DataAttribute.java
index 66fdda2..9be8885 100644
--- a/src/org/ice4j/attribute/DataAttribute.java
+++ b/src/org/ice4j/attribute/DataAttribute.java
@@ -101,18 +101,13 @@ public class DataAttribute
}
/**
- * Returns a (cloned) byte array containg the data value of the data
+ * Returns a (cloned) byte array containing the data value of the data
* attribute.
* @return the binary array containing the data.
*/
public byte[] getData()
{
- if (data == null)
- return null;
-
- byte[] copy = new byte[data.length];
- System.arraycopy(data, 0, copy, 0, data.length);
- return data;
+ return (data == null) ? null : data.clone();
}
/**
diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java
index 10bc1e9..c6b88ba 100644
--- a/src/org/ice4j/ice/Agent.java
+++ b/src/org/ice4j/ice/Agent.java
@@ -1341,7 +1341,7 @@ public class Agent
{
if (terminationThread == null)
{
- terminationThread = new TerminationThread(this);
+ terminationThread = new TerminationThread();
terminationThread.start();
}
}
@@ -1356,23 +1356,16 @@ public class Agent
* This TerminationThread is scheduling such a termination and
* garbage collection in three seconds.
*/
- private static class TerminationThread
+ private class TerminationThread
extends Thread
{
- /**
- * The parent agent that created us.
- */
- private final Agent parentAgent;
/**
* Creates a new termination timer.
- *
- * @param parentAgent the Agent that created us.
*/
- private TerminationThread(Agent parentAgent)
+ private TerminationThread()
{
super("TerminationThread");
- this.parentAgent = parentAgent;
}
/**
@@ -1380,6 +1373,7 @@ public class Agent
* interval the user has specified) and then moves this Agent
* into the terminated state and frees all non-nominated candidates.
*/
+ @Override
public synchronized void run()
{
long terminationDelay = Integer.getInteger(
@@ -1401,7 +1395,7 @@ public class Agent
}
}
- parentAgent.terminate(IceProcessingState.TERMINATED);
+ terminate(IceProcessingState.TERMINATED);
}
}
@@ -1417,9 +1411,7 @@ public class Agent
{
// free candidates
for(IceMediaStream stream : getStreams())
- {
removeStream(stream);
- }
// stop listening for checks
connCheckClient.stop();
diff --git a/src/org/ice4j/ice/ConnectivityCheckClient.java b/src/org/ice4j/ice/ConnectivityCheckClient.java
index 766eef8..d9e422e 100644
--- a/src/org/ice4j/ice/ConnectivityCheckClient.java
+++ b/src/org/ice4j/ice/ConnectivityCheckClient.java
@@ -106,17 +106,17 @@ class ConnectivityCheckClient
*/
private TransactionID startCheckForPair(CandidatePair candidatePair)
{
+ LocalCandidate localCandidate = candidatePair.getLocalCandidate();
//we don't need to do a canReach() verification here as it has been
//already verified during the gathering process.
- DatagramSocket stunSocket
- = candidatePair.getLocalCandidate().getStunSocket(null);
+ DatagramSocket stunSocket = localCandidate.getStunSocket(null);
Request request = MessageFactory.createBindingRequest();
//the priority we'd like the remote party to use for a peer reflexive
//candidate if one is discovered as a consequence of this check.
PriorityAttribute priority = AttributeFactory.createPriorityAttribute(
- candidatePair.getLocalCandidate().computePriorityForType(
+ localCandidate.computePriorityForType(
CandidateType.PEER_REFLEXIVE_CANDIDATE));
request.addAttribute(priority);
@@ -148,7 +148,7 @@ class ConnectivityCheckClient
request.addAttribute(unameAttr);
- //todo: also implement SASL prepare
+ // TODO Also implement SASL prepare
MessageIntegrityAttribute msgIntegrity = AttributeFactory
.createMessageIntegrityAttribute(localUserName);
@@ -159,26 +159,30 @@ class ConnectivityCheckClient
try
{
- stunStack.sendRequest(request,
- candidatePair.getRemoteCandidate().getTransportAddress(),
- candidatePair.getLocalCandidate().getTransportAddress(),
- this, tran);
-
+ tran
+ = stunStack.sendRequest(request,
+ candidatePair
+ .getRemoteCandidate().getTransportAddress(),
+ localCandidate.getTransportAddress(),
+ this,
+ tran);
if(logger.isLoggable(Level.FINEST))
- logger.finest("checking pair " + candidatePair + " with tran="
- + tran);
-
- return tran;
+ {
+ logger.finest(
+ "checking pair " + candidatePair
+ + " with tran=" + tran);
+ }
}
- catch (Exception exception)
+ catch (Exception ex)
{
- logger.log( Level.INFO,
- "Failed to send " + request + " through "
- + stunSocket.getLocalSocketAddress(),
- exception);
-
- return null;
+ logger.log(
+ Level.INFO,
+ "Failed to send " + request
+ + " through " + stunSocket.getLocalSocketAddress(),
+ ex);
+ tran = null;
}
+ return tran;
}
/**
@@ -193,7 +197,7 @@ class ConnectivityCheckClient
public void processResponse(StunResponseEvent evt)
{
CandidatePair checkedPair
- = ((CandidatePair)evt.getTransactionID().getApplicationData());
+ = (CandidatePair) evt.getTransactionID().getApplicationData();
//make sure that the response came from the right place.
if (!checkSymmetricAddresses(evt))
@@ -296,8 +300,8 @@ class ConnectivityCheckClient
Response response = evt.getResponse();
Request request = evt.getRequest();
- CandidatePair checkedPair = ((CandidatePair)evt.getTransactionID()
- .getApplicationData());
+ CandidatePair checkedPair
+ = (CandidatePair) evt.getTransactionID().getApplicationData();
if(! response.containsAttribute(Attribute.XOR_MAPPED_ADDRESS))
{
diff --git a/src/org/ice4j/message/Indication.java b/src/org/ice4j/message/Indication.java
index 983c292..257bf7c 100644
--- a/src/org/ice4j/message/Indication.java
+++ b/src/org/ice4j/message/Indication.java
@@ -14,32 +14,33 @@ package org.ice4j.message;
*
* @author Sebastien Vincent
*/
-public class Indication extends Message
+public class Indication
+ extends Message
{
/**
* Constructor.
*/
Indication()
{
-
}
/**
- * Checks whether indicationType is a valid response type and if yes sets it
- * as the type of the current instance.
+ * Checks whether indicationType is a valid indication type and if yes sets
+ * it as the type of this instance.
+ *
* @param indicationType the type to set
* @throws IllegalArgumentException if indicationType is not a valid
- * response type
+ * indication type
*/
+ @Override
public void setMessageType(char indicationType)
throws IllegalArgumentException
{
if(!isIndicationType(indicationType))
throw new IllegalArgumentException(
(int)(indicationType)
- + " - is not a valid response type.");
+ + " - is not a valid indication type.");
super.setMessageType(indicationType);
}
}
-
diff --git a/src/org/ice4j/stack/MessageEventHandler.java b/src/org/ice4j/stack/MessageEventHandler.java
index b33d7c7..1e16186 100644
--- a/src/org/ice4j/stack/MessageEventHandler.java
+++ b/src/org/ice4j/stack/MessageEventHandler.java
@@ -15,7 +15,7 @@ import org.ice4j.*;
*
* @author Emil Ivov
*/
-interface MessageEventHandler
+public interface MessageEventHandler
{
/**
* Called when an incoming message has been received, parsed and is ready
diff --git a/src/org/ice4j/stack/MessageProcessor.java b/src/org/ice4j/stack/MessageProcessor.java
index 8031caa..18b4a35 100644
--- a/src/org/ice4j/stack/MessageProcessor.java
+++ b/src/org/ice4j/stack/MessageProcessor.java
@@ -44,7 +44,7 @@ class MessageProcessor
/**
* The flag that indicates whether we are still running.
*/
- private boolean isRunning = false;
+ private boolean running = false;
/**
* A reference to the thread that we use to execute ourselves.
@@ -93,7 +93,7 @@ class MessageProcessor
//avoid having dead threads in our pools.
try
{
- while (isRunning)
+ while (running)
{
RawMessage rawMessage;
try
@@ -127,7 +127,7 @@ class MessageProcessor
}
catch (StunException ex)
{
- errorHandler.handleError("Failed to decode a stun mesage!",
+ errorHandler.handleError("Failed to decode a stun message!",
ex);
continue; //let this one go and for better luck next time.
@@ -153,20 +153,19 @@ class MessageProcessor
*/
void start()
{
- this.isRunning = true;
+ this.running = true;
runningThread = new Thread(this, "Stun4J Message Processor");
runningThread.setDaemon(true);
runningThread.start();
}
-
/**
* Shut down the message processor.
*/
void stop()
{
- this.isRunning = false;
+ this.running = false;
runningThread.interrupt();
}
@@ -178,6 +177,6 @@ class MessageProcessor
*/
boolean isRunning()
{
- return isRunning;
+ return running;
}
}
diff --git a/src/org/ice4j/stack/NetAccessManager.java b/src/org/ice4j/stack/NetAccessManager.java
index 81fd8f7..f553110 100644
--- a/src/org/ice4j/stack/NetAccessManager.java
+++ b/src/org/ice4j/stack/NetAccessManager.java
@@ -143,18 +143,20 @@ class NetAccessManager
*/
protected void addSocket(DatagramSocket socket)
{
- //no null check - let it through a null pointer exception
- TransportAddress localAddr = new TransportAddress(
- socket.getLocalAddress(), socket.getLocalPort(), Transport.UDP);
+ //no null check - let it through as a NullPointerException
+ TransportAddress localAddr
+ = new TransportAddress(
+ socket.getLocalAddress(),
+ socket.getLocalPort(),
+ Transport.UDP);
- if(netAccessPoints.containsKey(localAddr))
- return;
+ if (!netAccessPoints.containsKey(localAddr))
+ {
+ Connector ap = new Connector(socket, messageQueue, this);
- Connector ap = new Connector(socket, messageQueue, this);
-
- netAccessPoints.put(localAddr, ap);
-
- ap.start();
+ netAccessPoints.put(localAddr, ap);
+ ap.start();
+ }
}
/**
diff --git a/src/org/ice4j/stack/StunClientTransaction.java b/src/org/ice4j/stack/StunClientTransaction.java
index 7c665f9..9ba949d 100644
--- a/src/org/ice4j/stack/StunClientTransaction.java
+++ b/src/org/ice4j/stack/StunClientTransaction.java
@@ -324,7 +324,6 @@ class StunClientTransaction
}
}
-
/**
* Cancels the transaction. Once this method is called the transaction is
* considered terminated and will stop retransmissions.
diff --git a/src/org/ice4j/stack/StunServerTransaction.java b/src/org/ice4j/stack/StunServerTransaction.java
index ddb14fd..448fd2b 100644
--- a/src/org/ice4j/stack/StunServerTransaction.java
+++ b/src/org/ice4j/stack/StunServerTransaction.java
@@ -32,7 +32,6 @@ import org.ice4j.message.*;
*
* @author Emil Ivov
*/
-
class StunServerTransaction
implements Runnable
{
diff --git a/src/org/ice4j/stunclient/SimpleAddressDetector.java b/src/org/ice4j/stunclient/SimpleAddressDetector.java
index d08177b..5d8f81a 100644
--- a/src/org/ice4j/stunclient/SimpleAddressDetector.java
+++ b/src/org/ice4j/stunclient/SimpleAddressDetector.java
@@ -18,11 +18,10 @@ import org.ice4j.stack.*;
/**
* The class provides basic means of discovering a public IP address. All it
* does is send a binding request through a specified port and return the
- * mapped address it got back or null if there was no reponse.
+ * mapped address it got back or null if there was no response.
*
* @author Emil Ivov
*/
-
public class SimpleAddressDetector
{
/**