private void expireStalledBlockedMessages() { synchronized (lock) { Iterator<BlockedMessage> each = blockedQ.iterator(); while (each.hasNext()) { if (each.next().notifyIfExpired()) { each.remove(); } } } }
private void sendBlockedMessages() { synchronized (lock) { for (boolean success = true; success && !blockedQ.isEmpty(); ) { success = blockedQ.element().sendOrExpire(); if (success) { blockedQ.remove(); } } } }
/** * <p>This is a blocking proxy to the {@link #send(Message)} method. This * method blocks until the message is accepted by the send queue. Note that * the message timeout does not activate by calling this method. This method * will also return if this session is closed or the calling thread is * interrupted.</p> * * @param msg The message to send. * @return The result of initiating send. * @throws InterruptedException Thrown if the calling thread is interrupted. */ public Result sendBlocking(Message msg) throws InterruptedException { Result res = send(msg); if (isSendQFull(res)) { BlockedMessage blockedMessage = new BlockedMessage(msg); synchronized (lock) { blockedQ.add(blockedMessage); } res = blockedMessage.waitComplete(); } return res; }
boolean sendOrExpire() { if ( ! notifyIfExpired() ) { Result res = sendInternal(msg); if ( ! isSendQFull(res) ) { notifyComplete(res); } else { return false; } } return true; }
boolean notifyIfExpired() { if (msg.isExpired()) { Error error = new Error(ErrorCode.TIMEOUT, "Timed out in sendQ"); notifyComplete(new Result(error)); replyHandler.handleReply(createSendTimedoutReply(msg, error)); return true; } return false; }