db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r803548 - /db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Date Wed, 12 Aug 2009 15:04:30 GMT
Author: mamta
Date: Wed Aug 12 15:04:30 2009
New Revision: 803548

URL: http://svn.apache.org/viewvc?rev=803548&view=rev
Log:
DERBY-4304

Committing changes which puts a new try catch block around all of the server shutdown code
in case if there is some exception being thrown which is not getting caught. The catch block
will log into the log file but if that fails for some reason, it will also just dump the stack
trace using ex.printStackTrace(). 



Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=803548&r1=803547&r2=803548&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
(original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Wed Aug 12 15:04:30 2009
@@ -793,132 +793,143 @@
                             NetworkServerMBean.class,
                             "type=NetworkServer");
                 			
-		// wait until we are told to shutdown or someone sends an InterruptedException
-        synchronized(shutdownSync) {
-            try {
-				shutdownSync.wait();
-            }
-            catch (InterruptedException e)
-            {
-                shutdown = true;
-            }
-        }
-        
-        try {
-            AccessController.doPrivileged(
-                    new PrivilegedAction() {
-                        public Object run()  {
-                        // Need to interrupt the memcheck thread if it is sleeping.
-                            if (mc != null)
-                                mc.interrupt();
-
-                            //interrupt client thread
-                            clientThread.interrupt();
-
-                            return null;
-                       }
-                    });
-        } catch (Exception exception) {
-        	consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
-        }
-		
- 		// Close out the sessions
- 		synchronized(sessionTable) {
- 			for (Enumeration e = sessionTable.elements(); e.hasMoreElements(); )
- 			{	
- 				Session session = (Session) e.nextElement();
- 				try {
- 					session.close();
- 				} catch (Exception exception) {
- 		        	consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
- 				}
- 			}
- 		}
-
-		synchronized (threadList)
-		{
- 			//interupt any connection threads still active
- 			for (int i = 0; i < threadList.size(); i++)
- 			{
- 				try {
- 					final DRDAConnThread threadi = (DRDAConnThread)threadList.get(i);
- 	                
- 	 				threadi.close();
- 					AccessController.doPrivileged(
- 								new PrivilegedAction() {
- 									public Object run() {
- 										threadi.interrupt();
- 										return null;
- 									}
- 								});
- 				} catch (Exception exception) {
- 		        	consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
- 				}
- 			}
- 			threadList.clear();
-		}
-	   	
-	    // close the listener socket
-	    try{
-	       serverSocket.close();
-	    }catch(IOException e){
-			consolePropertyMessage("DRDA_ListenerClose.S", true);
-	    } catch (Exception exception) {
-        	consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
-	    }
-
-		// Wake up those waiting on sessions, so
-		// they can close down
-	    try{
-			synchronized (runQueue) {
-				runQueue.notifyAll();
-			}	
-	    } catch (Exception exception) {
-        	consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
-	    }
-        
-        // And now unregister any MBeans.
-	    try {
-	        mgmtService.unregisterMBean(versionMBean);
-	        mgmtService.unregisterMBean(networkServerMBean);
-	    } catch (Exception exception) {
-        	consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
-	    }
+		try {
+			// wait until we are told to shutdown or someone sends an InterruptedException
+	        synchronized(shutdownSync) {
+	            try {
+					shutdownSync.wait();
+	            }
+	            catch (InterruptedException e)
+	            {
+	                shutdown = true;
+	            }
+	        }
+	        
+	        try {
+	            AccessController.doPrivileged(
+	                    new PrivilegedAction() {
+	                        public Object run()  {
+	                        // Need to interrupt the memcheck thread if it is sleeping.
+	                            if (mc != null)
+	                                mc.interrupt();
+
+	                            //interrupt client thread
+	                            clientThread.interrupt();
+
+	                            return null;
+	                       }
+	                    });
+	        } catch (Exception exception) {
+	        	consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
+	        }
+			
+	 		// Close out the sessions
+	 		synchronized(sessionTable) {
+	 			for (Enumeration e = sessionTable.elements(); e.hasMoreElements(); )
+	 			{	
+	 				Session session = (Session) e.nextElement();
+	 				try {
+	 					session.close();
+	 				} catch (Exception exception) {
+	 		        	consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
+	 				}
+	 			}
+	 		}
+
+			synchronized (threadList)
+			{
+	 			//interupt any connection threads still active
+	 			for (int i = 0; i < threadList.size(); i++)
+	 			{
+	 				try {
+	 					final DRDAConnThread threadi = (DRDAConnThread)threadList.get(i);
+	 	                
+	 	 				threadi.close();
+	 					AccessController.doPrivileged(
+	 								new PrivilegedAction() {
+	 									public Object run() {
+	 										threadi.interrupt();
+	 										return null;
+	 									}
+	 								});
+	 				} catch (Exception exception) {
+	 		        	consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
+	 				}
+	 			}
+	 			threadList.clear();
+			}
+		   	
+		    // close the listener socket
+		    try{
+		       serverSocket.close();
+		    }catch(IOException e){
+				consolePropertyMessage("DRDA_ListenerClose.S", true);
+		    } catch (Exception exception) {
+	        	consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
+		    }
+
+			// Wake up those waiting on sessions, so
+			// they can close down
+		    try{
+				synchronized (runQueue) {
+					runQueue.notifyAll();
+				}	
+		    } catch (Exception exception) {
+	        	consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
+		    }
+	        
+	        // And now unregister any MBeans.
+		    try {
+		        mgmtService.unregisterMBean(versionMBean);
+		        mgmtService.unregisterMBean(networkServerMBean);
+		    } catch (Exception exception) {
+	        	consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
+		    }
 
-		if (shutdownDatabasesOnShutdown) {
+			if (shutdownDatabasesOnShutdown) {
 
-			// Shutdown Derby
-			try {
-				// tell driver to shutdown the engine
-				if (cloudscapeDriver != null) {
-					// DERBY-2109: pass user credentials for driver shutdown
-					final Properties p = new Properties();
-					if (userArg != null) {
-						p.setProperty("user", userArg);
+				// Shutdown Derby
+				try {
+					// tell driver to shutdown the engine
+					if (cloudscapeDriver != null) {
+						// DERBY-2109: pass user credentials for driver shutdown
+						final Properties p = new Properties();
+						if (userArg != null) {
+							p.setProperty("user", userArg);
+						}
+						if (passwordArg != null) {
+							p.setProperty("password", passwordArg);
+						}
+						cloudscapeDriver.connect("jdbc:derby:;shutdown=true", p);
 					}
-					if (passwordArg != null) {
-						p.setProperty("password", passwordArg);
+				} catch (SQLException sqle) {
+					// If we can't shutdown Derby, perhaps, authentication has
+					// failed or System Privileges weren't granted. We will just
+					// print a message to the console and proceed.
+					String expectedState =
+						StandardException.getSQLStateFromIdentifier(
+								SQLState.CLOUDSCAPE_SYSTEM_SHUTDOWN);
+					if (!expectedState.equals(sqle.getSQLState())) {
+						consolePropertyMessage("DRDA_ShutdownWarning.I",
+											   sqle.getMessage());
 					}
-					cloudscapeDriver.connect("jdbc:derby:;shutdown=true", p);
+				} catch (Exception exception) {
+					consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
 				}
-			} catch (SQLException sqle) {
-				// If we can't shutdown Derby, perhaps, authentication has
-				// failed or System Privileges weren't granted. We will just
-				// print a message to the console and proceed.
-				String expectedState =
-					StandardException.getSQLStateFromIdentifier(
-							SQLState.CLOUDSCAPE_SYSTEM_SHUTDOWN);
-				if (!expectedState.equals(sqle.getSQLState())) {
-					consolePropertyMessage("DRDA_ShutdownWarning.I",
-										   sqle.getMessage());
-				}
-			} catch (Exception exception) {
-				consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
 			}
-		}
 
-		consolePropertyMessage("DRDA_ShutdownSuccess.I", new String [] 
-						        {att_srvclsnm, versionString});
+			consolePropertyMessage("DRDA_ShutdownSuccess.I", new String [] 
+							        {att_srvclsnm, versionString});
+			
+		} catch (Exception ex) {
+			try {
+				//If the console printing is not available,  then we have
+				//a simple stack trace print below to atleast print some
+				//exception info
+	        	consolePrintAndIgnore("DRDA_UnexpectedException.S", ex, true);				
+			} catch (Exception e) {}
+			ex.printStackTrace();
+		}
     }
 	
 	//Print the passed exception on the console and ignore it after that



Mime
View raw message