From fda00cfa8af54078577230dc3f892fe6c1027902 Mon Sep 17 00:00:00 2001
From: "lubomir.marinov"
Date: Sat, 13 Feb 2010 00:13:52 +0000
Subject: [PATCH] Adds but does not use processUnreachable to
ResponseCollector.
---
src/org/ice4j/ResponseCollector.java | 17 ++++-
src/org/ice4j/stack/Connector.java | 5 +-
src/org/ice4j/stack/ErrorHandler.java | 8 +-
src/org/ice4j/stack/MessageEventHandler.java | 1 -
src/org/ice4j/stack/MessageQueue.java | 5 +-
src/org/ice4j/stack/NetAccessManager.java | 15 ++--
.../ice4j/stack/StunClientTransaction.java | 25 +++----
src/org/ice4j/stack/StunStack.java | 26 ++-----
.../stunclient/BlockingRequestSender.java | 28 ++++++-
.../ice4j/MessageEventDispatchingTest.java | 73 ++++++++++---------
test/org/ice4j/TransactionSupportTests.java | 27 +++++--
test/org/ice4j/stack/ShallowStackTest.java | 54 ++++++++------
12 files changed, 158 insertions(+), 126 deletions(-)
diff --git a/src/org/ice4j/ResponseCollector.java b/src/org/ice4j/ResponseCollector.java
index 76cbbd8..e3c31fd 100644
--- a/src/org/ice4j/ResponseCollector.java
+++ b/src/org/ice4j/ResponseCollector.java
@@ -6,18 +6,17 @@
*/
package org.ice4j;
-import org.ice4j.*;
+import java.net.*;
/**
* The interface is used as a callback when sending a request. The response
* collector is then used as a means of dispatching the response.
*
- *
Organisation:
Louis Pasteur University, Strasbourg, France
- *
Network Research Team (http://www-r2.u-strasbg.fr)
+ *
Organization: Louis Pasteur University, Strasbourg, France
+ *
Network Research Team (http://www-r2.u-strasbg.fr)
* @author Emil Ivov
* @version 0.1
*/
-
public interface ResponseCollector
{
/**
@@ -32,4 +31,14 @@ public interface ResponseCollector
* by rfc3489) and that the request should be considered unanswered.
*/
public void processTimeout();
+
+ /**
+ * Notifies this collector that the destination of the request has been
+ * determined to be unreachable and that the request should be considered
+ * unanswered.
+ *
+ * @param exception the PortUnreachableException which signaled
+ * that the destination of the request was found to be unreachable
+ */
+ public void processUnreachable(PortUnreachableException exception);
}
diff --git a/src/org/ice4j/stack/Connector.java b/src/org/ice4j/stack/Connector.java
index 29fd940..55e0331 100644
--- a/src/org/ice4j/stack/Connector.java
+++ b/src/org/ice4j/stack/Connector.java
@@ -33,7 +33,7 @@ class Connector
/**
* The message queue is where incoming messages are added.
*/
- private MessageQueue messageQueue = null;
+ private final MessageQueue messageQueue;
/**
* The socket object that used by this access point to access the network.
@@ -55,7 +55,7 @@ class Connector
* The instance to be notified if errors occur in the network listening
* thread.
*/
- private ErrorHandler errorHandler = null;
+ private final ErrorHandler errorHandler;
/**
* The address that we are listening to.
@@ -160,6 +160,7 @@ class Connector
+ "receive a message.",
ex);
}
+ else
{
//The exception was most probably caused by calling
//this.stop() ....
diff --git a/src/org/ice4j/stack/ErrorHandler.java b/src/org/ice4j/stack/ErrorHandler.java
index 5186b01..5dc7298 100644
--- a/src/org/ice4j/stack/ErrorHandler.java
+++ b/src/org/ice4j/stack/ErrorHandler.java
@@ -9,8 +9,8 @@ package org.ice4j.stack;
/**
* Generic Error Handler.
*
- *
Organisation:
Louis Pasteur University, Strasbourg, France.
- *
Network Research Team (http://www-r2.u-strasbg.fr)
+ *
Organization:
Louis Pasteur University, Strasbourg, France.
+ *
Network Research Team (http://www-r2.u-strasbg.fr)
* @author Emil Ivov
* @version 0.1
*/
@@ -32,5 +32,7 @@ interface ErrorHandler
* @param message a message describing the error.
* @param error the error itself.
*/
- public void handleFatalError(Runnable callingThread, String message, Throwable error);
+ public void handleFatalError(Runnable callingThread,
+ String message,
+ Throwable error);
}
diff --git a/src/org/ice4j/stack/MessageEventHandler.java b/src/org/ice4j/stack/MessageEventHandler.java
index f2ee345..12e8b73 100644
--- a/src/org/ice4j/stack/MessageEventHandler.java
+++ b/src/org/ice4j/stack/MessageEventHandler.java
@@ -15,7 +15,6 @@ import org.ice4j.*;
*
* @author Emil Ivov
*/
-
interface MessageEventHandler
{
/**
diff --git a/src/org/ice4j/stack/MessageQueue.java b/src/org/ice4j/stack/MessageQueue.java
index 8eefbd2..3cb6124 100644
--- a/src/org/ice4j/stack/MessageQueue.java
+++ b/src/org/ice4j/stack/MessageQueue.java
@@ -14,8 +14,8 @@ import java.util.logging.Logger;
* access is synchronized and message delivery ( remove() ) is blocking in the
* case of an empty queue.
*
- *
Organisation: Louis Pasteur University, Strasbourg, France
- *
Network Research Team (http://www-r2.u-strasbg.fr)
+ *
Organization: Louis Pasteur University, Strasbourg, France
+ *
Network Research Team (http://www-r2.u-strasbg.fr)
*
* @author Emil Ivov
* @version 0.1
@@ -37,7 +37,6 @@ class MessageQueue
*/
MessageQueue()
{
-
}
/**
diff --git a/src/org/ice4j/stack/NetAccessManager.java b/src/org/ice4j/stack/NetAccessManager.java
index 105f4ec..85b93ad 100644
--- a/src/org/ice4j/stack/NetAccessManager.java
+++ b/src/org/ice4j/stack/NetAccessManager.java
@@ -24,7 +24,6 @@ import org.ice4j.message.*;
*
* @author Emil Ivov
*/
-
class NetAccessManager
implements ErrorHandler
{
@@ -33,6 +32,7 @@ class NetAccessManager
*/
private static final Logger logger =
Logger.getLogger(NetAccessManager.class.getName());
+
/**
* All access points currently in use. The table maps
* TransportAddresses to Connectors
@@ -43,7 +43,7 @@ class NetAccessManager
/**
* A synchronized FIFO where incoming messages are stocked for processing.
*/
- private MessageQueue messageQueue = new MessageQueue();
+ private final MessageQueue messageQueue = new MessageQueue();
/**
* A thread pool of message processors.
@@ -52,7 +52,7 @@ class NetAccessManager
= new Vector();
/**
- * The instance that should be notified whan an incoming message has been
+ * The instance that should be notified when an incoming message has been
* processed and ready for delivery
*/
private MessageEventHandler messageEventHandler = null;
@@ -119,7 +119,7 @@ class NetAccessManager
{
MessageProcessor mp = (MessageProcessor)callingThread;
logger.log( Level.WARNING, "A message processor has unexpectedly "
- +"stopped. AP:" + mp.toString(), error);
+ +"stopped. AP:" + mp, error);
//make sure the guy's dead.
mp.stop();
@@ -144,7 +144,6 @@ class NetAccessManager
protected void addSocket(DatagramSocket socket)
throws IOException
{
-
//no null check - let it through a null pointer exception
TransportAddress localAddr = new TransportAddress(
socket.getLocalAddress(), socket.getLocalPort(), Transport.UDP);
@@ -159,7 +158,6 @@ class NetAccessManager
ap.start();
}
-
/**
* Stops and deletes the specified access point.
*
@@ -216,7 +214,6 @@ class NetAccessManager
fillUpThreadPool(initialThreadPoolSize);
}
-
/**
* Starts all message processors
*
@@ -236,13 +233,12 @@ class NetAccessManager
mp.start();
}
-
}
/**
* Starts all message processors
*
- * @param newSize the new thread poolsize
+ * @param newSize the new thread pool size
*/
private void shrinkThreadPool(int newSize)
{
@@ -281,5 +277,4 @@ class NetAccessManager
ap.sendMessage(bytes, remoteAddr);
}
-
}
diff --git a/src/org/ice4j/stack/StunClientTransaction.java b/src/org/ice4j/stack/StunClientTransaction.java
index d503b2c..8f58a6b 100644
--- a/src/org/ice4j/stack/StunClientTransaction.java
+++ b/src/org/ice4j/stack/StunClientTransaction.java
@@ -6,8 +6,9 @@
*/
package org.ice4j.stack;
-import java.util.logging.*;
import java.io.*;
+import java.net.*;
+import java.util.logging.*;
import org.ice4j.*;
import org.ice4j.message.*;
@@ -93,34 +94,34 @@ class StunClientTransaction
/**
* The StunStack that created us.
*/
- private StunStack stackCallback = null;
+ private final StunStack stackCallback;
/**
* The request that we are retransmitting.
*/
- private Request request = null;
+ private final Request request;
/**
* The destination of the request.
*/
- private TransportAddress requestDestination= null;
+ private final TransportAddress requestDestination;
/**
* The id of the transaction.
*/
- private TransactionID transactionID = null;
+ private final TransactionID transactionID;
/**
* The TransportAddress through which the original request was sent
* and that we are supposed to be retransmitting through.
*/
- private TransportAddress localAddress = null;
+ private final TransportAddress localAddress;
/**
* The instance to notify when a response has been received in the current
* transaction or when it has timed out.
*/
- private ResponseCollector responseCollector = null;
+ private final ResponseCollector responseCollector;
/**
* Determines whether the transaction is active or not.
@@ -191,8 +192,8 @@ class StunClientTransaction
retransmissionCounter ++)
{
waitFor(nextWaitInterval);
- //did someone tell us to get lost?
+ //did someone tell us to get lost?
if(cancelled)
return;
@@ -209,7 +210,7 @@ class StunClientTransaction
//has failed
logger.log(Level.WARNING,
"A client tran retransmission failed", ex);
- };
+ }
}
//before stating that a transaction has timeout-ed we should first wait
@@ -221,7 +222,6 @@ class StunClientTransaction
responseCollector.processTimeout();
stackCallback.removeClientTransaction(this);
-
}
/**
@@ -231,9 +231,8 @@ class StunClientTransaction
* @throws IOException if an error occurs while sending message bytes
* through the network socket.
* @throws IllegalArgumentException if the apDescriptor references an
- * access point that had not been installed,
- * @throws StunException if message encoding fails,
- *
+ * access point that had not been installed
+ * @throws StunException if message encoding fails
*/
void sendRequest()
throws StunException, IllegalArgumentException, IOException
diff --git a/src/org/ice4j/stack/StunStack.java b/src/org/ice4j/stack/StunStack.java
index 00cb700..9d5a988 100644
--- a/src/org/ice4j/stack/StunStack.java
+++ b/src/org/ice4j/stack/StunStack.java
@@ -46,14 +46,14 @@ public class StunStack
/**
* Stores active client transactions mapped against TransactionID-s.
*/
- private Hashtable clientTransactions
+ private final Hashtable clientTransactions
= new Hashtable();
/**
* Currently open server transactions. The vector contains transaction ids
* for transactions corresponding to all non-answered received requests.
*/
- private Hashtable serverTransactions
+ private final Hashtable serverTransactions
= new Hashtable();
/**
@@ -61,7 +61,6 @@ public class StunStack
*/
private EventDispatcher eventDispatcher = new EventDispatcher();
-
/**
* Returns a reference to the singleton StunStack instance. If the stack
* had not yet been initialized, a new instance will be created.
@@ -95,12 +94,11 @@ public class StunStack
* @param sock The socket that the new access point should represent.
* @throws IOException if we fail to setup the socket.
*/
- public void addSocket(DatagramSocket sock)
+ public void addSocket(DatagramSocket sock)
throws IOException
- {
- netAccessManager.addSocket(sock);
- }
-
+ {
+ netAccessManager.addSocket(sock);
+ }
/**
* Stops and deletes the connector listening on the specified local address.
@@ -201,8 +199,7 @@ public class StunStack
* through the network socket.
* @throws IllegalArgumentException if the apDescriptor references an
* access point that had not been installed,
- * @throws StunException if message encoding fails,
- *
+ * @throws StunException if message encoding fails
*/
public void sendRequest( Request request,
TransportAddress sendTo,
@@ -235,7 +232,7 @@ public class StunStack
* through the network socket.
* @throws IllegalArgumentException if the apDescriptor references an
* access point that had not been installed,
- * @throws StunException if message encoding fails,
+ * @throws StunException if message encoding fails
*/
public void sendResponse(byte[] transactionID,
Response response,
@@ -260,9 +257,6 @@ public class StunStack
{
sTran.sendResponse(response, sendThrough, sendTo);
}
-
-
-
}
/**
@@ -294,7 +288,6 @@ public class StunStack
* like to listen on.
* @param listener The ConfigurationChangeListener to be added
*/
-
public void addRequestListener( TransportAddress localAddress,
RequestListener listener)
{
@@ -407,7 +400,6 @@ public class StunStack
+ clientTransactions.toString());
}
}
-
}
/**
@@ -424,7 +416,6 @@ public class StunStack
StunClientTransaction tran = clientTransactions.remove(item);
if(tran != null)
tran.cancel();
-
}
tids = serverTransactions.keys();
@@ -434,7 +425,6 @@ public class StunStack
StunServerTransaction tran = serverTransactions.remove(item);
if(tran != null)
tran.expire();
-
}
}
}
diff --git a/src/org/ice4j/stunclient/BlockingRequestSender.java b/src/org/ice4j/stunclient/BlockingRequestSender.java
index 05b0201..63b0ce9 100644
--- a/src/org/ice4j/stunclient/BlockingRequestSender.java
+++ b/src/org/ice4j/stunclient/BlockingRequestSender.java
@@ -7,6 +7,7 @@
package org.ice4j.stunclient;
import java.io.*;
+import java.net.*;
import java.util.logging.*;
import org.ice4j.*;
@@ -44,12 +45,12 @@ class BlockingRequestSender
/**
* The stack that we are using to send requests through.
*/
- private StunStack stunStack = null;
+ private final StunStack stunStack;
/**
* The transport address that we are bound on.
*/
- private TransportAddress localAddress = null;
+ private final TransportAddress localAddress;
/**
* The StunMessageEvent that contains the response matching our
@@ -58,14 +59,14 @@ class BlockingRequestSender
private StunMessageEvent responseEvent = null;
/**
- * Determines whether this request sender has comleted its coarse.
+ * Determines whether this request sender has completed its course.
*/
private boolean ended = false;
/**
* A lock object that we are using to synchronize sending.
*/
- private Object sendLock = new Object();
+ private final Object sendLock = new Object();
/**
* Creates a new request sender.
@@ -107,6 +108,25 @@ class BlockingRequestSender
}
}
+ /**
+ * Notifies this collector that the destination of the request has been
+ * determined to be unreachable and that the request should be considered
+ * unanswered.
+ *
+ * @param exception the PortUnreachableException which signaled
+ * that the destination of the request was found to be unreachable
+ * @see ResponseCollector#processUnreachable(PortUnreachableException)
+ */
+ public synchronized void processUnreachable(
+ PortUnreachableException exception)
+ {
+ synchronized(sendLock)
+ {
+ ended = true;
+ notifyAll();
+ }
+ }
+
/**
* Sends the specified request and blocks until a response has been
* received or the request transaction has timed out.
diff --git a/test/org/ice4j/MessageEventDispatchingTest.java b/test/org/ice4j/MessageEventDispatchingTest.java
index 5c2b452..4aeda55 100644
--- a/test/org/ice4j/MessageEventDispatchingTest.java
+++ b/test/org/ice4j/MessageEventDispatchingTest.java
@@ -283,74 +283,75 @@ public class MessageEventDispatchingTest extends TestCase
/**
* A utility class we use to collect incoming responses.
*/
- private class PlainResponseCollector implements ResponseCollector
+ private class PlainResponseCollector
+ implements ResponseCollector
{
- /**
- *
- */
- public Vector