/** * Sets the destroyed flag to true. The very first time this method is called, it cleans up all its dependencies. * Even if you retain a reference to this object, all of its content is allowed to be garbage collected. * * @return True if content existed and was destroyed. */ public boolean destroy() { if (!destroyed.getAndSet(true)) { synchronized (this) { for (Queue<Message> queue : seqMap.values()) { if (queue != null) { for (Message msg : queue) { msg.discard(); } } } seqMap.clear(); } return true; } return false; }
/** * <p>Convenience method to post a {@link Task} that delivers a {@link * Message} to a {@link MessageHandler} to the queue of tasks to be * executed.</p> * * @param msg The message to send. * @param handler The handler to send to. */ public void deliverMessage(final Message msg, final MessageHandler handler) { if (destroyed.get()) { msg.discard(); return; } try { sendExecutor.execute(new MessageTask(msg, handler)); } catch (RejectedExecutionException e) { msg.discard(); log.warning("Execution rejected " + e.getMessage()); } }
/** * <p>Sets the destroyed flag to true. The very first time this method is * called, it cleans up all its dependencies. Even if you retain a * reference to this object, all of its content is allowed to be garbage * collected.</p> * * @return True if content existed and was destroyed. */ public boolean destroy() { boolean done = false; enqueue(Terminate.INSTANCE); if (!destroyed.getAndSet(true)) { sendExecutor.shutdownNow().forEach((Runnable task) -> {((MessageTask) task).msg.discard();}); try { synchronized (this) { while (!queue.isEmpty()) { wait(); } } thread.join(); } catch (final InterruptedException e) { // ignore } done = true; } return done; }
/** * All messages pass through this handler when being sent by the owning source session. In case the message has no * sequencing-id, it is simply passed through to the next handler in the chain. Sequenced messages are sent only if * there is no queue for their id, otherwise they are queued. * * @param msg the message to send. */ @Override public void handleMessage(Message msg) { if (destroyed.get()) { msg.discard(); return; } if (msg.hasSequenceId()) { if (filter(msg)) { sequencedSend(msg); } } else { sender.handleMessage(msg); // unsequenced } }
public void handleReply(Reply reply) { if (reply == null) { msg.discard(); } else { Trace trace = msg.getTrace();