- better shutdown behavior for the GUI (waits until data is written if GUI is killed)

- release 0.97

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7135 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent 34a25856a5
commit 2c7edea35e

@ -3,7 +3,7 @@ javacSource=1.5
javacTarget=1.5 javacTarget=1.5
# Release Configuration # Release Configuration
releaseVersion=0.96 releaseVersion=0.97
stdReleaseFile=yacy_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz stdReleaseFile=yacy_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz
sourceReleaseFile=yacy_src_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz sourceReleaseFile=yacy_src_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz
releaseFileParentDir=yacy releaseFileParentDir=yacy

@ -130,15 +130,15 @@ public class YaCyApp {
// registering shutdown hook // registering shutdown hook
log.info("Registering Shutdown Hook"); log.info("Registering Shutdown Hook");
Switchboard.addShutdownHook(Thread.currentThread()); Thread t = new Thread() {
SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
app = new Application("YaCy GUI", operation, menues, new InfoPage("localhost", 8080)); app = new Application("YaCy GUI", operation, menues, new InfoPage("localhost", 8080));
app.setLocationRelativeTo(null); app.setLocationRelativeTo(null);
app.setVisible(true); app.setVisible(true);
} }
}); };
Switchboard.addShutdownHook(t, net.yacy.yacy.shutdownSemaphore);
SwingUtilities.invokeLater(t);
} }
public static void main(String[] args) { public static void main(String[] args) {

@ -29,6 +29,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.Semaphore;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
@ -64,10 +65,10 @@ public class Switchboard {
new InfoUpdater(2000).start(); new InfoUpdater(2000).start();
} }
public static void addShutdownHook(Thread mainThread) { public static void addShutdownHook(Thread mainThread, Semaphore semaphore) {
// registering shutdown hook // registering shutdown hook
final Runtime run = Runtime.getRuntime(); final Runtime run = Runtime.getRuntime();
run.addShutdownHook(new shutdownHookThread(mainThread)); run.addShutdownHook(new shutdownHookThread(mainThread, semaphore));
} }
public static JTextComponent InfoBox = null; public static JTextComponent InfoBox = null;
@ -98,14 +99,16 @@ public class Switchboard {
/** /**
* This class is a helper class whose instance is started, when the java virtual * This class is a helper class whose instance is started, when the java virtual
* machine shuts down. Signals the plasmaSwitchboard to shut down. * machine shuts down. Signals the Switchboard to shut down.
*/ */
public static class shutdownHookThread extends Thread { public static class shutdownHookThread extends Thread {
private final Thread mainThread; private final Thread mainThread;
private final Semaphore shutdownSemaphore;
public shutdownHookThread(final Thread mainThread) { public shutdownHookThread(final Thread mainThread, Semaphore semaphore) {
super(); super();
this.mainThread = mainThread; this.mainThread = mainThread;
this.shutdownSemaphore = semaphore;
} }
public void run() { public void run() {
@ -118,10 +121,18 @@ public class Switchboard {
shutdown(); shutdown();
// waiting for the main thread to finish execution // waiting for the main thread to finish execution
log.info("Waiting for main thread to finish."); log.info("Waiting for GUI thread to finish.");
this.mainThread.interrupt();
if (this.mainThread != null && this.mainThread.isAlive()) { if (this.mainThread != null && this.mainThread.isAlive()) {
this.mainThread.join(); this.mainThread.join();
} }
// wait until everything is written
log.info("Waiting for main thread to finish. shutdownSemaphore.permits = " + shutdownSemaphore.availablePermits());
shutdownSemaphore.acquireUninterruptibly();
//log.info("Aquired shutdown semaphore. remaining permits = " + shutdownSemaphore.availablePermits());
// finished
log.info("Shutdown Hook Terminated. Shutdown.");
} }
} catch (final Exception e) { } catch (final Exception e) {
log.info("Unexpected error. " + e.getClass().getName(),e); log.info("Unexpected error. " + e.getClass().getName(),e);

@ -131,24 +131,13 @@ public final class yacy {
public static final String vDATE = yacyBuildProperties.getBuildDate(); public static final String vDATE = yacyBuildProperties.getBuildDate();
public static final String copyright = "[ YaCy v" + vString + ", build " + vDATE + " by Michael Christen / www.yacy.net ]"; public static final String copyright = "[ YaCy v" + vString + ", build " + vDATE + " by Michael Christen / www.yacy.net ]";
public static final String hline = "-------------------------------------------------------------------------------"; public static final String hline = "-------------------------------------------------------------------------------";
public static final Semaphore shutdownSemaphore = new Semaphore(0);
/** /**
* a reference to the {@link Switchboard} created by the * a reference to the {@link Switchboard} created by the
* {@link yacy#startup(String, long, long)} method. * {@link yacy#startup(String, long, long)} method.
*/ */
private static Switchboard sb = null; private static Switchboard sb = null;
/**
* Semaphore needed by {@link yacy#setUpdaterCallback(serverUpdaterCallback)} to block
* until the {@link plasmaSwitchboard }object was created.
*/
//private static serverSemaphore sbSync = new serverSemaphore(0);
/**
* Semaphore needed by {@link yacy#waitForFinishedStartup()} to block
* until startup has finished
*/
private static Semaphore startupFinishedSync = new Semaphore(0);
/** /**
* Starts up the whole application. Sets up all datastructures and starts * Starts up the whole application. Sets up all datastructures and starts
@ -393,9 +382,6 @@ public final class yacy {
sb.setConfig("memoryFreeAfterInitAGC", MemoryControl.free()); sb.setConfig("memoryFreeAfterInitAGC", MemoryControl.free());
sb.setConfig("memoryTotalAfterInitAGC", MemoryControl.total()); sb.setConfig("memoryTotalAfterInitAGC", MemoryControl.total());
//} catch (ConcurrentModificationException e) {} //} catch (ConcurrentModificationException e) {}
// signal finished startup
startupFinishedSync.release();
// wait for server shutdown // wait for server shutdown
try { try {
@ -438,10 +424,10 @@ public final class yacy {
} catch (final Exception ee) { } catch (final Exception ee) {
Log.logSevere("STARTUP", "FATAL ERROR: " + ee.getMessage(),ee); Log.logSevere("STARTUP", "FATAL ERROR: " + ee.getMessage(),ee);
} finally { } finally {
startupFinishedSync.release();
} }
Log.logConfig("SHUTDOWN", "goodbye. (this is the last line)"); Log.logConfig("SHUTDOWN", "goodbye. (this is the last line)");
Log.shutdown(); Log.shutdown();
shutdownSemaphore.release(1000);
try { try {
System.exit(0); System.exit(0);
} catch (Exception e) {} // was once stopped by de.anomic.net.ftpc$sm.checkExit(ftpc.java:1790) } catch (Exception e) {} // was once stopped by de.anomic.net.ftpc$sm.checkExit(ftpc.java:1790)

Loading…
Cancel
Save