* Instantiate new RemoteArchiveBean for each archive fetched by the updater, to prevent weirdness if the index fetch for archive n+1 fails.
* Add a blocking fetch to EepGetScheduler and RemoteArchiveBean and use them from the updater, to prevent race conditions with multiple archive fetches.
This commit is contained in:
@ -20,9 +20,9 @@ public class Updater {
|
||||
_lastUpdate = System.currentTimeMillis();
|
||||
_log.debug("Update started.");
|
||||
User user = new User();
|
||||
RemoteArchiveBean rab = new RemoteArchiveBean();
|
||||
String[] archives = bm.getUpdateArchives();
|
||||
for (int i = 0; i < archives.length; i++) {
|
||||
RemoteArchiveBean rab = new RemoteArchiveBean();
|
||||
_log.debug("Fetching " + archives[i]);
|
||||
rab.fetchIndex(user, "web", archives[i], bm.getDefaultProxyHost(), bm.getDefaultProxyPort());
|
||||
if (rab.getRemoteIndex() != null) {
|
||||
|
@ -134,6 +134,10 @@ public class RemoteArchiveBean {
|
||||
}
|
||||
|
||||
public void fetchSelectedBulk(User user, Map parameters) {
|
||||
fetchSelectedBulk(user, parameters, false);
|
||||
}
|
||||
|
||||
public void fetchSelectedBulk(User user, Map parameters, boolean shouldBlock) {
|
||||
String entries[] = ArchiveViewerBean.getStrings(parameters, "entry");
|
||||
String action = ArchiveViewerBean.getString(parameters, "action");
|
||||
if ("Fetch all new entries".equals(action)) {
|
||||
@ -206,7 +210,7 @@ public class RemoteArchiveBean {
|
||||
File t = File.createTempFile("fetchBulk", ".dat", BlogManager.instance().getTempDir());
|
||||
tmpFiles.add(t);
|
||||
}
|
||||
fetch(urls, tmpFiles, user, new BlogStatusListener());
|
||||
fetch(urls, tmpFiles, user, new BlogStatusListener(), shouldBlock);
|
||||
} catch (IOException ioe) {
|
||||
_statusMessages.add("Internal error creating temporary file to fetch posts: " + HTMLRenderer.sanitizeString(urls.toString()));
|
||||
}
|
||||
@ -258,8 +262,12 @@ public class RemoteArchiveBean {
|
||||
}
|
||||
|
||||
private void fetch(List urls, List tmpFiles, User user, EepGet.StatusListener lsnr) {
|
||||
fetch(urls, tmpFiles, user, lsnr, false);
|
||||
}
|
||||
|
||||
private void fetch(List urls, List tmpFiles, User user, EepGet.StatusListener lsnr, boolean shouldBlock) {
|
||||
EepGetScheduler scheduler = new EepGetScheduler(I2PAppContext.getGlobalContext(), urls, tmpFiles, _proxyHost, _proxyPort, lsnr);
|
||||
scheduler.fetch();
|
||||
scheduler.fetch(shouldBlock);
|
||||
}
|
||||
|
||||
public void fetchIndex(User user, String schema, String location, String proxyHost, String proxyPort) {
|
||||
|
@ -33,6 +33,15 @@ public class EepGetScheduler implements EepGet.StatusListener {
|
||||
t.start();
|
||||
}
|
||||
|
||||
public void fetch(boolean shouldBlock) {
|
||||
//Checking for a valid index is done in fetchNext, so we don't have to worry about it.
|
||||
if (shouldBlock) {
|
||||
fetchNext();
|
||||
} else {
|
||||
fetch();
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchNext() {
|
||||
_curURL++;
|
||||
if (_curURL >= _urls.size()) return;
|
||||
|
Reference in New Issue
Block a user