I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit ee9ac31c authored by ragnarok's avatar ragnarok Committed by zzz
Browse files

* Instantiate new RemoteArchiveBean for each archive fetched by the updater,...

* 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.
parent 78899830
No related branches found
No related tags found
No related merge requests found
...@@ -20,9 +20,9 @@ public class Updater { ...@@ -20,9 +20,9 @@ public class Updater {
_lastUpdate = System.currentTimeMillis(); _lastUpdate = System.currentTimeMillis();
_log.debug("Update started."); _log.debug("Update started.");
User user = new User(); User user = new User();
RemoteArchiveBean rab = new RemoteArchiveBean();
String[] archives = bm.getUpdateArchives(); String[] archives = bm.getUpdateArchives();
for (int i = 0; i < archives.length; i++) { for (int i = 0; i < archives.length; i++) {
RemoteArchiveBean rab = new RemoteArchiveBean();
_log.debug("Fetching " + archives[i]); _log.debug("Fetching " + archives[i]);
rab.fetchIndex(user, "web", archives[i], bm.getDefaultProxyHost(), bm.getDefaultProxyPort()); rab.fetchIndex(user, "web", archives[i], bm.getDefaultProxyHost(), bm.getDefaultProxyPort());
if (rab.getRemoteIndex() != null) { if (rab.getRemoteIndex() != null) {
......
...@@ -134,6 +134,10 @@ public class RemoteArchiveBean { ...@@ -134,6 +134,10 @@ public class RemoteArchiveBean {
} }
public void fetchSelectedBulk(User user, Map parameters) { 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 entries[] = ArchiveViewerBean.getStrings(parameters, "entry");
String action = ArchiveViewerBean.getString(parameters, "action"); String action = ArchiveViewerBean.getString(parameters, "action");
if ("Fetch all new entries".equals(action)) { if ("Fetch all new entries".equals(action)) {
...@@ -206,7 +210,7 @@ public class RemoteArchiveBean { ...@@ -206,7 +210,7 @@ public class RemoteArchiveBean {
File t = File.createTempFile("fetchBulk", ".dat", BlogManager.instance().getTempDir()); File t = File.createTempFile("fetchBulk", ".dat", BlogManager.instance().getTempDir());
tmpFiles.add(t); tmpFiles.add(t);
} }
fetch(urls, tmpFiles, user, new BlogStatusListener()); fetch(urls, tmpFiles, user, new BlogStatusListener(), shouldBlock);
} catch (IOException ioe) { } catch (IOException ioe) {
_statusMessages.add("Internal error creating temporary file to fetch posts: " + HTMLRenderer.sanitizeString(urls.toString())); _statusMessages.add("Internal error creating temporary file to fetch posts: " + HTMLRenderer.sanitizeString(urls.toString()));
} }
...@@ -258,8 +262,12 @@ public class RemoteArchiveBean { ...@@ -258,8 +262,12 @@ public class RemoteArchiveBean {
} }
private void fetch(List urls, List tmpFiles, User user, EepGet.StatusListener lsnr) { 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); 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) { public void fetchIndex(User user, String schema, String location, String proxyHost, String proxyPort) {
......
...@@ -33,6 +33,15 @@ public class EepGetScheduler implements EepGet.StatusListener { ...@@ -33,6 +33,15 @@ public class EepGetScheduler implements EepGet.StatusListener {
t.start(); 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() { private void fetchNext() {
_curURL++; _curURL++;
if (_curURL >= _urls.size()) return; if (_curURL >= _urls.size()) return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment