Takuya Ono
takuy****@users*****
2007年 8月 10日 (金) 01:58:33 JST
Index: BetaProject/src/org/jent/checksmtp/SMTPclient.java diff -u BetaProject/src/org/jent/checksmtp/SMTPclient.java:1.3 BetaProject/src/org/jent/checksmtp/SMTPclient.java:1.4 --- BetaProject/src/org/jent/checksmtp/SMTPclient.java:1.3 Sun Jul 22 16:56:15 2007 +++ BetaProject/src/org/jent/checksmtp/SMTPclient.java Fri Aug 10 01:58:33 2007 @@ -11,16 +11,31 @@ 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 @@ 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 @@ } 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."); + } } }