target = endpoint.getQueue() + "/t=" + endpoint.getConfiguration().getWaitTimeMs();
} else {
target = endpoint.getQueue();
}
@SuppressWarnings("rawtypes")
Exchanger exchanger = null;
while (isRunAllowed() && !shutdownPending) {
if (concurrent) {
// Wait until an exchanger is available, indicating that a
// handler thread is ready to handle the next request.
// Don't read from kestrel until we know a handler is ready.
try {
exchanger = exchangerQueue.take();
} catch (InterruptedException e) {
if (log.isDebugEnabled()) {
log.debug("Interrupted, are we stopping? {}", isStopping() || isStopped());
}
continue;
}
// We have the exchanger, so there's a handler thread ready
// to handle whatever we may read...so read the next object
// from the queue.
}
// Poll kestrel until we get an object back
Object value = null;
while (isRunAllowed() && !shutdownPending) {
log.trace("Polling {}", target);
try {
value = memcachedClient.get(target);
if (value != null) {
break;
}
} catch (Exception e) {
if (isRunAllowed() && !shutdownPending) {
getExceptionHandler().handleException("Failed to get object from kestrel", e);
}
}
// We didn't get a value back from kestrel
if (isRunAllowed() && !shutdownPending) {
if (endpoint.getConfiguration().getWaitTimeMs() > 0) {
// Kestrel did the blocking for us
} else {
// We're doing non-blocking get, so in between we
// should at least sleep some short period of time
// so this loop doesn't go nuts so tightly.
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
}
}
}
log.trace("Got object from {}", target);
if (concurrent) {
// Pass the object to the handler thread via the exchanger.
// The handler will take it from there.
try {
exchanger.exchange(value);
} catch (InterruptedException e) {
if (log.isDebugEnabled()) {
log.debug("Interrupted, are we stopping? {}", isStopping() || isStopped());
}
continue;