avoid illegalstateexception

This commit is contained in:
zzz
2009-02-04 14:16:36 +00:00
parent 3d8cb3b90d
commit 5946c35a88

View File

@ -61,25 +61,32 @@ public class Shitlist {
} }
private class Cleanup extends JobImpl { private class Cleanup extends JobImpl {
private List<Hash> _toUnshitlist;
public Cleanup(RouterContext ctx) { public Cleanup(RouterContext ctx) {
super(ctx); super(ctx);
_toUnshitlist = new ArrayList(4);
getTiming().setStartAfter(ctx.clock().now() + SHITLIST_CLEANER_START_DELAY); getTiming().setStartAfter(ctx.clock().now() + SHITLIST_CLEANER_START_DELAY);
} }
public String getName() { return "Cleanup shitlist"; } public String getName() { return "Cleanup shitlist"; }
public void runJob() { public void runJob() {
_toUnshitlist.clear();
long now = getContext().clock().now(); long now = getContext().clock().now();
for (Iterator iter = _entries.entrySet().iterator(); iter.hasNext(); ) { try {
Map.Entry<Hash, Entry> e = (Map.Entry) iter.next(); for (Iterator iter = _entries.entrySet().iterator(); iter.hasNext(); ) {
if (e.getValue().expireOn <= now) { Map.Entry<Hash, Entry> e = (Map.Entry) iter.next();
iter.remove(); if (e.getValue().expireOn <= now) {
Hash peer = e.getKey(); iter.remove();
PeerProfile prof = _context.profileOrganizer().getProfile(peer); _toUnshitlist.add(e.getKey());
if (prof != null) }
prof.unshitlist();
_context.messageHistory().unshitlist(peer);
if (_log.shouldLog(Log.INFO))
_log.info("Unshitlisting router (expired) " + peer.toBase64());
} }
} catch (IllegalStateException ise) {} // next time...
for (Hash peer : _toUnshitlist) {
PeerProfile prof = _context.profileOrganizer().getProfile(peer);
if (prof != null)
prof.unshitlist();
_context.messageHistory().unshitlist(peer);
if (_log.shouldLog(Log.INFO))
_log.info("Unshitlisting router (expired) " + peer.toBase64());
} }
requeue(30*1000); requeue(30*1000);