You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by sc...@apache.org on 2008/12/01 17:33:04 UTC

svn commit: r722116 - in /incubator/etch/trunk: binding-csharp/runtime/src/main/csharp/Etch/Transport/Filter/KeepAlive.cs binding-java/runtime/src/main/java/etch/bindings/java/transport/filters/KeepAlive.java

Author: sccomer
Date: Mon Dec  1 08:33:04 2008
New Revision: 722116

URL: http://svn.apache.org/viewvc?rev=722116&view=rev
Log:
csharp fix for ETCH-18: KeepAlive throws exception while trying to shutdown connection.

fixed both csharp and java versions to use Todo during wakeup to send request so as to not block AlarmManager if there is a problem with the connection.

Modified:
    incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Transport/Filter/KeepAlive.cs
    incubator/etch/trunk/binding-java/runtime/src/main/java/etch/bindings/java/transport/filters/KeepAlive.java

Modified: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Transport/Filter/KeepAlive.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Transport/Filter/KeepAlive.cs?rev=722116&r1=722115&r2=722116&view=diff
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Transport/Filter/KeepAlive.cs (original)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Transport/Filter/KeepAlive.cs Mon Dec  1 08:33:04 2008
@@ -118,6 +118,7 @@
         protected override bool SessionUp()
         {
             //		Log.report( "KeepAliveSessionUp", "server", server );
+            up = true;
             AlarmManager.staticAdd(this, null, delay * 1000);
             tickle();
             return true;
@@ -126,10 +127,13 @@
         protected override bool SessionDown()
         {
             //		Log.report( "KeepAliveSessionDown", "server", server );
+            up = false;
             AlarmManager.staticRemove(this);
             return true;
         }
 
+        private bool up;
+
         private void handleRequest(Message msg)
         {
             if (!server)
@@ -202,16 +206,7 @@
                 }
                 catch (Exception e)
                 {
-                    try
-                    {
-                        session.SessionNotify(e);
-                    }
-                    catch (Exception e1)
-                    {
-                        // what else can you do?
-                        //e1.PrintStackTrace();
-                        Console.WriteLine(e1.StackTrace);
-                    }
+                    reportError(e);
                 }
             }
         }
@@ -228,15 +223,7 @@
             }
             catch (Exception e)
             {
-                try
-                {
-                    session.SessionNotify(e);
-                }
-                catch (Exception e1)
-                {
-                    // what else can you do?
-                    Console.WriteLine(e1.StackTrace);
-                }
+                reportError(e);
             }
         }
 
@@ -250,15 +237,7 @@
             }
             catch (Exception e)
             {
-                try
-                {
-                    session.SessionNotify(e);
-                }
-                catch (Exception e1)
-                {
-                    // what else can you do?
-                    Console.WriteLine(e1.StackTrace);
-                }
+                reportError(e);
             }
         }
 
@@ -266,17 +245,61 @@
         {
             //		Log.report( "KeepAliveWakeup", "server", server );
 
+            if (!up)
+                return 0;
+
             if (!server)
-                sendKeepAliveReq();
+            {
+                TodoManager.AddTodo(new MyTodo(sendKeepAliveReq, reportError));
+            }
 
             checkTickle();
 
             return delay * 1000;
         }
 
+        private void reportError(Exception e)
+        {
+            try
+            {
+                session.SessionNotify(e);
+            }
+            catch (Exception e1)
+            {
+                Console.WriteLine(e1);
+            }
+        }
+
         public override string ToString()
         {
             return "KeepAlive/" + transport;
         }
     }
+
+    public class MyTodo : Todo
+    {
+        public delegate void doit();
+
+        public delegate void report(Exception e);
+
+        public MyTodo(doit d, report r)
+        {
+            this.d = d;
+            this.r = r;
+        }
+
+        private readonly doit d;
+
+        private readonly report r;
+
+        public void Doit(TodoManager mgr)
+        {
+            d();
+        }
+
+        public void Exception(TodoManager mgr, Exception e)
+        {
+            r(e);
+        }
+    }
 }

Modified: incubator/etch/trunk/binding-java/runtime/src/main/java/etch/bindings/java/transport/filters/KeepAlive.java
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-java/runtime/src/main/java/etch/bindings/java/transport/filters/KeepAlive.java?rev=722116&r1=722115&r2=722116&view=diff
==============================================================================
--- incubator/etch/trunk/binding-java/runtime/src/main/java/etch/bindings/java/transport/filters/KeepAlive.java (original)
+++ incubator/etch/trunk/binding-java/runtime/src/main/java/etch/bindings/java/transport/filters/KeepAlive.java Mon Dec  1 08:33:04 2008
@@ -27,6 +27,8 @@
 import etch.util.AlarmManager;
 import etch.util.Resources;
 import etch.util.Timer;
+import etch.util.Todo;
+import etch.util.TodoManager;
 import etch.util.URL;
 import etch.util.core.Who;
 import etch.util.core.io.Transport;
@@ -248,19 +250,24 @@
 			}
 			catch ( Exception e )
 			{
-				try
-				{
-					session.sessionNotify( e );
-				}
-				catch ( Exception e1 )
-				{
-					// what else can you do?
-					e1.printStackTrace();
-				}
+				reportError( e );
 			}
 		}
 	}
 	
+	private void reportError( Exception e )
+	{
+		try
+		{
+			session.sessionNotify( e );
+		}
+		catch ( Exception e1 )
+		{
+			// what else can you do?
+			e1.printStackTrace();
+		}
+	}
+	
 	private void sendKeepAliveReq()
 	{
 		Message msg = new Message( mt_request, vf );
@@ -273,15 +280,7 @@
 		}
 		catch ( Exception e )
 		{
-			try
-			{
-				session.sessionNotify( e );
-			}
-			catch ( Exception e1 )
-			{
-				// what else can you do?
-				e1.printStackTrace();
-			}
+			reportError( e );
 		}
 	}
 	
@@ -295,15 +294,7 @@
 		}
 		catch ( Exception e )
 		{
-			try
-			{
-				session.sessionNotify( e );
-			}
-			catch ( Exception e1 )
-			{
-				// what else can you do?
-				e1.printStackTrace();
-			}
+			reportError( e );
 		}
 	}
 
@@ -315,7 +306,21 @@
 			return 0;
 		
 		if (!server)
-			sendKeepAliveReq();
+		{
+			// use a Todo so as to not unnecessarily block AlarmManager.
+			TodoManager.addTodo( new Todo()
+			{
+				public void doit( TodoManager mgr ) throws Exception
+				{
+					sendKeepAliveReq();
+				}
+
+				public void exception( TodoManager mgr, Exception e )
+				{
+					reportError( e );
+				}
+			} );
+		}
 		
 		checkTickle();