OSDN Git Service

BUGFIX: [ #10834 ] After abnormal Reciver Port number setteing, the service is disabl...
authorTakuya Ono <takuya-o@users.sourceforge.jp>
Thu, 9 Aug 2007 17:00:30 +0000 (17:00 +0000)
committerTakuya Ono <takuya-o@users.sourceforge.jp>
Thu, 9 Aug 2007 17:00:30 +0000 (17:00 +0000)
deploy/mdc.zip
src/org/jent/checksmtp/SMTPclient.java

index 000571d..d41e9c9 100644 (file)
Binary files a/deploy/mdc.zip and b/deploy/mdc.zip differ
index 4bb6fb6..1cac6d2 100644 (file)
@@ -11,16 +11,31 @@ import java.net.SocketTimeoutException;
 public class SMTPclient implements Runnable {
   private boolean isConfigChange = false;
   private boolean fatalError = false;
+  private Thread serviceThread = null;
     
     public SMTPclient() {
-        Thread thread = new Thread(this);
-        thread.start();
+    startServiceThread();
     }
 
+  private void startServiceThread() {
+    if ( serviceThread !=null && serviceThread.isAlive() ) {
+      //Still service thread was working.
+      return;
+    }
+    //Reset flags and start service thread.
+    isConfigChange = false;
+    fatalError = false;
+    serviceThread = new Thread(this);
+    serviceThread.start();
+  }
+
   public void configChangeNotify() {
     isConfigChange = true;
+     if ( serviceThread !=null && !serviceThread.isAlive() ) {
+      startServiceThread();
+    }
   }
-    
+      
     public void run() {
          while (!fatalError) {
             ServerSocket server = null;
@@ -44,8 +59,16 @@ public class SMTPclient implements Runnable {
                     System.err.println("Fatal Error Occurred. Stop service.");
                     //TODO: Display error dialog.
                     e.printStackTrace(); //Unexpected!!
+                    break;
+                } catch (IllegalArgumentException iaEx) {
+                    //Port value out of range
+                    fatalError = true;
+                    System.err.println("Faital Error Occurted(" + iaEx.getMessage() + "). Stop service." );
+                    //TODO: Display error dialog.
+                    iaEx.printStackTrace();
+                    break;
                 }
-
+                
                 acceptWait:
                 while (true) {
                     // Wait connect from mail client
@@ -77,7 +100,18 @@ public class SMTPclient implements Runnable {
                 } catch (IOException ioe) {
                     //IGNORE close Exception
                 }
+            } catch (RuntimeException rEx) {
+              fatalError = true;
+              System.err.println("Runtime Exception was occurred.");
+              rEx.printStackTrace();
+              //TODO: Display error dialog.
+              break;
             }
         }
+        if ( !fatalError ) {
+          //Servce stop by non fatal error. Unexpected.
+          //TODO: Display stop service dialog.
+          System.err.println("Stoped service.");
+        }
     }
 }