[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting/callback ...
Ron Sigal
ron_sigal at yahoo.com
Sat Jan 20 20:16:22 EST 2007
User: rsigal
Date: 07/01/20 20:16:22
Modified: src/main/org/jboss/remoting/callback Tag: remoting_2_x
CallbackPoller.java
Log:
JBREM-657: Added parameter "local" to stop() so that, optionally, it can execute without attempting to contact the server.
Revision Changes Path
No revision
No revision
1.5.2.5 +29 -10 JBossRemoting/src/main/org/jboss/remoting/callback/CallbackPoller.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CallbackPoller.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/callback/CallbackPoller.java,v
retrieving revision 1.5.2.4
retrieving revision 1.5.2.5
diff -u -b -r1.5.2.4 -r1.5.2.5
--- CallbackPoller.java 16 Nov 2006 16:54:18 -0000 1.5.2.4
+++ CallbackPoller.java 21 Jan 2007 01:16:22 -0000 1.5.2.5
@@ -212,8 +212,9 @@
* stop() will not return until all received callbacks have been processed
* by the CallbackHandler and acknowledgements have been sent for all callbacks for
* which acknowledgements have been requested.
+ * @param local indicates that no attempt should be made to contact server
*/
- public synchronized void stop()
+ public synchronized void stop(boolean local)
{
// run() and stop() are synchronized so that stop() will wait until run() has finished
// adding any callbacks it has received to toHandleList. Therefore, once cancel()
@@ -232,7 +233,7 @@
// for all callbacks for which acknowledgements have been requested.
if (acknowledgeThread != null)
{
- acknowledgeThread.shutdown();
+ acknowledgeThread.shutdown(local);
acknowledgeThread = null;
}
@@ -346,6 +347,7 @@
{
boolean running = true;
boolean done;
+ boolean localShutdown;
ArrayList toAcknowledgeListCopy = new ArrayList();
AcknowledgeThread(String name)
@@ -358,7 +360,7 @@
{
synchronized (toAcknowledgeList)
{
- if (toAcknowledgeList.isEmpty() && running)
+ while (toAcknowledgeList.isEmpty() && running)
{
try
{
@@ -371,9 +373,11 @@
}
}
- // If toAcknowledgeList is empty, then running must be false. We return
- // only when both conditions are true.
- if (toAcknowledgeList.isEmpty())
+ // If toAcknowledgeList is empty, then running must be false.
+ // We return only when running is false and either
+ // 1. toAcknowledgeList is empty, or
+ // 2. the local flag has been set by shutdown()
+ if (toAcknowledgeList.isEmpty() || localShutdown)
{
done = true;
toAcknowledgeList.notify();
@@ -396,7 +400,13 @@
log.trace("acknowledging: " + map.get(ServerInvokerCallbackHandler.CALLBACK_ID));
}
}
+
+ // This is an attempt to stop AcknowledgeThread from contacting the server
+ // if localShutdown has been set. There's no guarantee, though.
+ if (!localShutdown)
+ {
client.acknowledgeCallbacks(callbackHandler, toAcknowledgeListCopy);
+ }
toAcknowledgeListCopy.clear();
}
catch (Throwable t)
@@ -409,8 +419,9 @@
/**
* Once CallbackPoller.stop() has called AcknowledgeThread.shutdown(), HandleThread
* has terminated and no additional callbacks will be added to toAcknowledgeList.
- * shutdown() will not return until AcknowledgeThread has acknowledged all callbacks
- * in toAcknowledgeList.
+ * if local is false, shutdown() will not return until AcknowledgeThread has
+ * acknowledged all callbacks in toAcknowledgeList. If local is true, shutdown()
+ * will return without waiting.
*
* Either run() or shutdown() will enter its own synchronized block first.
*
@@ -426,13 +437,21 @@
* synchronized block. After shutdown() reaches toAcknowledgeList.wait(), run()
* will enter its synchronized block, find running == false and toAcknowledgeList
* empty, and it will exit.
+ *
+ * @param local if true, don't try to contact server
*/
- public void shutdown()
+ public void shutdown(boolean local)
{
+ localShutdown = local;
+
synchronized (toAcknowledgeList)
{
running = false;
toAcknowledgeList.notify();
+
+ if (localShutdown)
+ return;
+
while (!done)
{
try
More information about the jboss-cvs-commits
mailing list