if(KILL_BLOCKS != 0)
random = new MersenneTwister();
else
random = null;
Key[] keys = null;
SendableGet getter = null;
ClientRequestScheduler sched = null;
BlockSet blocks = null;
boolean waited = false;
synchronized(this) {
while(true) {
for(short prio = 0;prio<queue.length;prio++) {
QueueItem trans;
if((trans = queue[prio].pollFirst()) != null) {
keys = trans.keys;
getter = trans.getter;
// sched assigned out of loop
blocks = trans.blockSet;
if(logMINOR)
Logger.minor(this, "Checking transient request "+getter+" prio "+prio+" of "+queue[prio].size());
break;
}
}
if(keys != null)
break;
if(logMINOR) Logger.minor(this, "Waiting for more transient requests");
waited = true;
try {
// Wait for anything.
wait(SECONDS.toMillis(100));
} catch (InterruptedException e) {
// Ok
}
}
}
sched = getter.getScheduler(context);
boolean anyValid = false;
for(Key key : keys) {
if(random != null) {
if(random.nextInt(RESET_COUNTER) < KILL_BLOCKS) {
anyValid = true;
continue;
}
}
KeyBlock block;
if(blocks != null)
block = blocks.get(key);
else
block = node.fetch(key, true, true, false, false, null);
if(block != null) {
if(logMINOR) Logger.minor(this, "Found key");
if(key instanceof NodeSSK)
sched.tripPendingKey(block);
else // CHK
sched.tripPendingKey(block);
} else {
anyValid = true;
}
// synchronized(this) {
// keysToCheck[priority].remove(key);
// }
}
if(logMINOR) Logger.minor(this, "Checked "+keys.length+" keys");
if(getter.persistent()) {
final SendableGet get = getter;
final ClientRequestScheduler scheduler = sched;
final boolean valid = anyValid;
try {
context.jobRunner.queue(new PersistentJob() {
@Override
public boolean run(ClientContext context) {
try {
scheduler.finishRegister(new SendableGet[] { get }, true, valid);
} catch (Throwable t) {
Logger.error(this, "Failed to register "+get+": "+t, t);
try {
get.onFailure(new LowLevelGetException(LowLevelGetException.INTERNAL_ERROR, "Internal error: "+t, t), null, context);
} catch (Throwable t1) {
Logger.error(this, "Failed to fail: "+t, t);
}
}
return false;