db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r540779 - in /db/derby/code/trunk/java: drda/org/apache/derby/impl/drda/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/derbynet/
Date Tue, 22 May 2007 22:34:34 GMT
Author: kmarsden
Date: Tue May 22 15:34:33 2007
New Revision: 540779

URL: http://svn.apache.org/viewvc?view=rev&rev=540779
Log:
DERBY_1465  NetworkServerControl.start() should throw an exception and not just print exceptions
if the server fails to start


Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/NSinSameJVM.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVM.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?view=diff&rev=540779&r1=540778&r2=540779
==============================================================================
--- 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
Tue May 22 15:34:33 2007
@@ -161,6 +161,7 @@
     
 	private static String buildNumber;
 	private static String versionString;
+	
 	// we will use single or mixed, not double byte to reduce traffic on the
 	// wire, this is in keeping with JCC
 	// Note we specify UTF8 for the single byte encoding even though it can
@@ -212,6 +213,7 @@
 	private InetAddress hostAddress;
 	private int sessionArg;
 	private boolean unsecureArg;
+	private Exception runtimeException = null;
 
 	// Used to debug memory in SanityManager.DEBUG mode
 	private memCheck mc;
@@ -310,6 +312,7 @@
 	private static final int SSL_PEER_AUTHENTICATION = 2;
 
 	private int sslMode = SSL_OFF;
+	private Object  serverStartComplete = new Object();
 
     /**
      * Can EUSRIDPWD security mechanism be used with 
@@ -566,19 +569,40 @@
 	 *
 	 * @param consoleWriter   PrintWriter to which server console will be 
 	 *                        output. Null will disable console output.
-	 *
+	 *                        
+	 * 
 	 *		   
 	 * @exception Exception	throws an exception if an error occurs
 	 */
-	public void start(PrintWriter consoleWriter)
+	public void start(final PrintWriter consoleWriter)
 		throws Exception
-	{
-		DRDAServerStarter starter = new DRDAServerStarter();
-		starter.setStartInfo(hostAddress,portNumber,consoleWriter);
-        this.setLogWriter(consoleWriter);
-		startNetworkServer();
-		starter.boot(false,null);
+	{		
+		 
+		   Thread t = new Thread("NetworkServerControl") {
+			   
+		        public void run() {
+		          try {
+		        	  blockingStart(consoleWriter);
+		            } catch (Exception e) {
+		            	runtimeException = e;
+		            }
+		          }
+		        };
+		    // if there was an immediate error like
+		    // another server already running, throw it here.
+		    // ping is still required to verify the server is
+		    // up.     
+		   
+		    t.start();
+		    synchronized(serverStartComplete){
+		    	serverStartComplete.wait();
+		    }
+		    
+		    if (runtimeException != null)
+		    	throw runtimeException;		   
 	}
+	
+	
 
 	/**
 	 * Create the right kind of server socket
@@ -634,8 +658,8 @@
 	public void blockingStart(PrintWriter consoleWriter)
 		throws Exception
 	{
-		startNetworkServer();
 		setLogWriter(consoleWriter);
+		startNetworkServer();
 		cloudscapeLogWriter = Monitor.getStream().getPrintWriter();
 		if (SanityManager.DEBUG && debugOutput)
 		{
@@ -643,7 +667,7 @@
 			mc = new memCheck(200000);
 			mc.start();
 		}
-		// Open a server socket listener	  
+		// Open a server socket listener
 		try{
 			serverSocket = 
 				(ServerSocket) 
@@ -676,10 +700,15 @@
 			} else {
 				throw e1;
 			}
+		
 		} catch (Exception e) {
 		// If we find other (unexpected) errors, we ultimately exit--so make
 		// sure we print the error message before doing so (Beetle 5033).
 			throwUnexpectedException(e);
+		} finally {
+			synchronized (serverStartComplete) {
+				serverStartComplete.notifyAll();
+			}
 		}
 
 		switch (getSSLMode()) {
@@ -700,7 +729,7 @@
 				 getFormattedTimestamp()});
 			break;
 		}
-		
+
 		// We accept clients on a separate thread so we don't run into a problem
 		// blocking on the accept when trying to process a shutdown
 		ClientThread clientThread =	 
@@ -714,7 +743,9 @@
 								}
 							);
 		clientThread.start();
-			
+		
+
+		
 		// wait until we are told to shutdown or someone sends an InterruptedException
         synchronized(shutdownSync) {
             try {
@@ -790,7 +821,7 @@
 				}
 			}
 		}
-
+		 
 		consolePropertyMessage("DRDA_ShutdownSuccess.I", new String [] 
 						        {att_srvclsnm, versionString, 
 								getFormattedTimestamp()});

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/NSinSameJVM.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/NSinSameJVM.out?view=diff&rev=540779&r1=540778&r2=540779
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/NSinSameJVM.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/NSinSameJVM.out
Tue May 22 15:34:33 2007
@@ -3,4 +3,3 @@
 main-NSinSameJVM: NetworkServer started
 main-NSinSameJVM: Connected to database NSinSameJVMTestDB;create=true
 getting ready to shutdown
-Apache Derby Network Server - 10.3.0.0 alpha -(EXPECTED SUBVERSION INFO)  shutdown at xxxxxxFILTERED-TIMESTAMPxxxxxGMT

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVM.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVM.java?view=diff&rev=540779&r1=540778&r2=540779
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVM.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVM.java
Tue May 22 15:34:33 2007
@@ -100,6 +100,13 @@
 			// sure the thread closes down.
 			// connection.close();
 			
+            // DERBY-1465 Make sure attempt to start another
+            // server on the same port fails.
+            try {
+            	serverControl.start(null);
+            	System.out.println("FAIL: Should have gotten exception");
+            } catch (Exception e) {// expecting exception 
+            	}
 			System.out.println("getting ready to shutdown");
 			serverControl.shutdown();
 			Thread.sleep(5000);



Mime
View raw message