db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r810956 - in /db/derby/code/branches/10.3: ./ java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Date Thu, 03 Sep 2009 14:11:43 GMT
Author: mamta
Date: Thu Sep  3 14:11:43 2009
New Revision: 810956

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

Merged into 10.3 codeline


Modified:
    db/derby/code/branches/10.3/   (props changed)
    db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java

Propchange: db/derby/code/branches/10.3/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Sep  3 14:11:43 2009
@@ -1 +1 @@
-/db/derby/code/trunk:552046,788436,793588,800523
+/db/derby/code/trunk:552046,788436,793588,794303,796316,796372,798347,798742,800523,803548

Modified: db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=810956&r1=810955&r2=810956&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
(original)
+++ db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Thu Sep  3 14:11:43 2009
@@ -717,104 +717,241 @@
 							);
 		clientThread.start();
 			
-		// wait until we are told to shutdown or someone sends an InterruptedException
-        synchronized(shutdownSync) {
-            try {
-				shutdownSync.wait();
-            }
-            catch (InterruptedException e)
-            {
-                shutdown = true;
-            }
-        }
-
-        
-        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;
-                    }
-                });
+		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 out the sessions
- 		synchronized(sessionTable) {
- 			for (Enumeration e = sessionTable.elements(); e.hasMoreElements(); )
- 			{	
- 				Session session = (Session) e.nextElement();
- 				session.close();
- 			}
- 		}
-
-		synchronized (threadList)
-		{
- 			//interupt any connection threads still active
- 			for (int i = 0; i < threadList.size(); i++)
- 			{
-				final DRDAConnThread threadi = (DRDAConnThread)threadList.get(i);
-                
- 				threadi.close();
-				AccessController.doPrivileged(
-							new PrivilegedAction() {
-								public Object run() {
-									threadi.interrupt();
-									return null;
-								}
-							});
- 			}
- 			threadList.clear();
-		}
-	   
- 
+		    // close the listener socket
+		    try{
+		       serverSocket.close();
+		    }catch(IOException e){
+				consolePropertyMessage("DRDA_ListenerClose.S");
+		    } 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);
+		    }
 
+			if (shutdownDatabasesOnShutdown) {
+
+				// Shutdown Derby
+				try {
+					if (cloudscapeDriver != null)
+						cloudscapeDriver.connect("jdbc:derby:;shutdown=true",
+												 (Properties) null);
+				} catch (SQLException sqle) {
+					// If we can't shutdown Derby. Perhaps authentication is
+					// set to true or some other reason. 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});
+				
+		} 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();
+		}		
+    }
 	
-	    // close the listener socket
-	    try{
-	       serverSocket.close();
-	    }catch(IOException e){
-			consolePropertyMessage("DRDA_ListenerClose.S");
-	    }
+	//Print the passed exception on the console and ignore it after that
+	private void consolePrintAndIgnore(String msgProp, 
+			Exception e, boolean printTimeStamp) {
+		// catch the exception consolePropertyMessage will throw since we
+		// just want to print information about it and move on.
+		try {
+			consolePropertyMessage(msgProp, true);
+		} catch (Exception ce) {} 
+		consoleExceptionPrintTrace(e);		
+	}
+	/**
+	 * Put property message on console
+	 *
+	 * @param msgProp		message property key
+	 * @param printTimeStamp whether to prepend a timestamp to the message
+     *
+     * @throws Exception if an error occurs
+	 */
+	protected void consolePropertyMessage(String msgProp, boolean printTimeStamp)
+		throws Exception
+	{
+		consolePropertyMessageWork(msgProp, null, printTimeStamp);
+	}
 
+	/**
+	 * Handle console error message
+	 * 	- display on console and if it is a user error, display usage
+	 *  - if user error or severe error, throw exception with message key and message
+	 *
+	 * @param messageKey	message key
+	 * @param args			arguments to message
+	 * @param printTimeStamp whether to prepend a timestamp to the message
+     *
+     * @throws Exception if an error occurs
+	 */
+	private void consolePropertyMessageWork(String messageKey, String [] args, boolean printTimeStamp)
+		throws Exception
+	{
+		String locMsg = null;
 
-		// Wake up those waiting on sessions, so
-		// they can close down
-		synchronized (runQueue) {
-			runQueue.notifyAll();
-		}						
+		int type = getMessageType(messageKey);
 
-		if (shutdownDatabasesOnShutdown) {
+		if (type == ERRTYPE_UNKNOWN)
+			locMsg = messageKey;
+		else
+			locMsg = localizeMessage(messageKey, langUtil, args);
 
-			// Shutdown Derby
-			try {
-				if (cloudscapeDriver != null)
-					cloudscapeDriver.connect("jdbc:derby:;shutdown=true",
-											 (Properties) null);
-			} catch (SQLException sqle) {
-				// If we can't shutdown Derby. Perhaps authentication is
-				// set to true or some other reason. 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());
-				}
-			}
+		//display on the console
+		consoleMessage(locMsg, printTimeStamp);
+
+		//if it is a user error display usage
+		if (type == ERRTYPE_USER)
+			usage();
+
+		//we may want to use a different locale for throwing the exception
+		//since this can be sent to a browser with a different locale
+		if (currentSession != null && 
+				currentSession.langUtil != null &&
+				type != ERRTYPE_UNKNOWN)
+			locMsg = localizeMessage(messageKey, currentSession.langUtil, args);
+
+		// throw an exception for severe and user errors
+		if (type == ERRTYPE_SEVERE || type == ERRTYPE_USER)
+		{
+			if (messageKey.equals("DRDA_SQLException.S"))
+				throwSQLException(args[0]);
+			else if (messageKey.equals("DRDA_SQLWarning.I"))
+				throwSQLWarning(args[0]);
+			else 
+				throw new Exception(messageKey+":"+locMsg);
 		}
 
-		consolePropertyMessage("DRDA_ShutdownSuccess.I", new String [] 
-						        {att_srvclsnm, versionString, 
-								getFormattedTimestamp()});
-		
+		// throw an exception with just the message if the error type is
+		// unknown
+		if (type == ERRTYPE_UNKNOWN)
+			throw new Exception(locMsg);
 
-    }
+		return;
+
+	}
+
+	/**
+	 * Write a message to console output stream
+	 *
+	 * @param msg	message
+     * @param printTimeStamp Whether to prepend a timestamp to the message or not
+	 */
+	public void consoleMessage(String msg, boolean printTimeStamp)
+	{
+		// print to console if we have one
+		PrintWriter lw = logWriter;
+		if (lw != null)
+		{
+			synchronized(lw) {
+                if (printTimeStamp) {
+                    lw.println(getFormattedTimestamp() + " : " + msg);
+                } else {
+                    lw.println(msg);                    
+                }
+			}
+		}
+		// always print to derby.log
+		lw = cloudscapeLogWriter;
+		if (lw != null)
+			synchronized(lw)
+			{
+				if (printTimeStamp) {
+                    Monitor.logMessage(getFormattedTimestamp() + " : " + msg);
+                } else {
+                    Monitor.logMessage(msg);
+                }
+			}
+	}
 	
 	/** 
 	 * Load Derby and save driver for future use.



Mime
View raw message