Console: Fix stopping of webapps when console stops (ticket #1893)

i2psnark: Only rewrite torrent config file if changed (ticket #1893)
Util: Don't sync config writes on Android/ARM (ticket #1893)
This commit is contained in:
zzz
2017-04-01 14:15:06 +00:00
parent 5eefb8b222
commit f390831835
6 changed files with 68 additions and 10 deletions

View File

@ -238,7 +238,7 @@ public class Snark
private volatile boolean _autoStoppable;
// String indicating main activity
private volatile String activity = "Not started";
private final long savedUploaded;
private long savedUploaded;
private long _startedTime;
private static final AtomicInteger __RPCID = new AtomicInteger();
private final int _rpcID = __RPCID.incrementAndGet();
@ -637,16 +637,17 @@ public class Snark
if (st != null) {
// TODO: Cache the config-in-mem to compare vs config-on-disk
// (needed for auto-save to not double-save in some cases)
//boolean changed = storage.isChanged() || getUploaded() != savedUploaded;
boolean changed = true;
if (changed && completeListener != null)
completeListener.updateStatus(this);
long nowUploaded = getUploaded();
boolean changed = storage.isChanged() || nowUploaded != savedUploaded;
try {
storage.close();
} catch (IOException ioe) {
System.out.println("Error closing " + torrent);
ioe.printStackTrace();
}
savedUploaded = nowUploaded;
if (changed && completeListener != null)
completeListener.updateStatus(this);
}
if (fast)
// HACK: See above if(!fast)
@ -1289,8 +1290,12 @@ public class Snark
allChecked = true;
checking = false;
if (storage.isChanged() && completeListener != null)
if (storage.isChanged() && completeListener != null) {
completeListener.updateStatus(this);
// this saved the status, so reset the variables
storage.clearChanged();
savedUploaded = getUploaded();
}
}
public void storageCompleted(Storage storage)
@ -1299,8 +1304,12 @@ public class Snark
_log.info("Completely received " + torrent);
//storage.close();
//System.out.println("Completely received: " + torrent);
if (completeListener != null)
if (completeListener != null) {
completeListener.torrentComplete(this);
// this saved the status, so reset the variables
savedUploaded = getUploaded();
storage.clearChanged();
}
}
public void setWantedPieces(Storage storage)

View File

@ -305,6 +305,14 @@ public class Storage implements Closeable
return changed;
}
/**
* Clear the storage changed variable
* @since 0.9.30
*/
void clearChanged() {
changed = false;
}
/**
* File checking in progress.
* @since 0.9.3

View File

@ -17,6 +17,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.SortedSet;
import java.util.StringTokenizer;
import java.util.concurrent.LinkedBlockingQueue;
@ -233,6 +234,7 @@ public class RouterConsoleRunner implements RouterApp {
changeState(STOPPING);
if (PluginStarter.pluginsEnabled(_context))
(new I2PAppThread(new PluginStopper(_context), "PluginStopper")).start();
stopAllWebApps();
try {
_server.stop();
} catch (Exception ie) {}
@ -1040,6 +1042,32 @@ public class RouterConsoleRunner implements RouterApp {
}
}
/**
* Stops all but the root webapp (routerconsole.war)
* In Jetty 9, stopping the server doesn't stop the non-root webapps,
* so we must do it here.
* There should be a better way to do this, possibly by
* making the webapps "managed".
* @since 0.9.30
*/
private void stopAllWebApps() {
Properties props = webAppProperties(_context);
Set<String> keys = props.stringPropertyNames();
for (String name : keys) {
if (name.startsWith(PREFIX) && name.endsWith(ENABLED)) {
String app = name.substring(PREFIX.length(), name.lastIndexOf(ENABLED));
if (ROUTERCONSOLE.equals(app))
continue;
if (WebAppStarter.isWebAppRunning(app)) {
try {
WebAppStarter.stopWebApp(app);
} catch (Throwable t) { t.printStackTrace(); }
}
}
}
}
static class WarFilenameFilter implements FilenameFilter {
private static final WarFilenameFilter _filter = new WarFilenameFilter();
public static WarFilenameFilter instance() { return _filter; }

View File

@ -46,6 +46,7 @@ import net.i2p.util.OrderedProperties;
import net.i2p.util.ReusableGZIPInputStream;
import net.i2p.util.ReusableGZIPOutputStream;
import net.i2p.util.SecureFileOutputStream;
import net.i2p.util.SystemVersion;
import net.i2p.util.Translate;
/**
@ -55,6 +56,9 @@ import net.i2p.util.Translate;
*/
public class DataHelper {
/** See storeProps(). 600-750 ms on RPi. */
private static final boolean SHOULD_SYNC = !(SystemVersion.isAndroid() || SystemVersion.isARM());
/**
* Map of String to itself to cache common
* keys in RouterInfo, RouterAddress, and BlockfileNamingService properties.
@ -514,8 +518,10 @@ public class DataHelper {
}
out.println(name + "=" + val);
}
out.flush();
fos.getFD().sync();
if (SHOULD_SYNC) {
out.flush();
fos.getFD().sync();
}
out.close();
if (out.checkError()) {
out = null;

View File

@ -1,3 +1,9 @@
2017-04-01 zzz
* Console: Fix stopping of webapps when console stops (ticket #1893)
* i2psnark: Only rewrite torrent config file if changed (ticket #1893)
* KeyStoreUtil: Reduce log level of expired cert error
* Util: Don't sync config writes on Android/ARM (ticket #1893)
2017-03-31 zzz
* SSU:
- When a IPv6 peer connects, trigger a IPv6 peer test, not a IPv4 one
@ -77,6 +83,7 @@ Prop from i2p.i2p.zzz.jetty9:
* Jetty:
- Update to Jetty 9.2.21.v20170120 and Tomcat 8.0.33 (tickets #1512, #1935)
Fixes jsp compilation on Java 9 (ticket #1870)
Fixes InstanceManager warning (ticket #1818)
We now support servlet API 3.1, JSP API 2.3, and EL API 3.0.
Breaks the following plugins: bwschedule, i2pbote, i2pcontrol, zzzot
* Startup: Add migration code for eepsite Jetty 8 configuration files

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 13;
public final static long BUILD = 14;
/** for example "-test" */
public final static String EXTRA = "";