@Override public void run() { while (!closed) { try { dispatchReadyCondition.await(); } catch (InterruptedException ex) { // ignore } contextLock.lock(); try { if (!closed) { doDispatch(); } } finally { contextLock.unlock(); } } } }
/** * Constructs the context. The context is a child of the given HazelcastMQ * instance. * * @param transacted true to create a transacted context, false otherwise * @param hazelcastMQInstance the parent MQ instance */ public DefaultHazelcastMQContext( DefaultHazelcastMQInstance hazelcastMQInstance) { this.hazelcastMQInstance = hazelcastMQInstance; this.config = this.hazelcastMQInstance.getConfig(); this.consumerMap = new HashMap<>(); this.temporaryQueues = new HashSet<>(); this.temporaryTopics = new HashSet<>(); this.id = "hzmqcontext-" + UUID.randomUUID().toString(); this.contextLock = new ReentrantLock(); this.receiveReadyCondition = this.contextLock.newCondition(); switch (config.getContextDispatchStrategy()) { case DEDICATED_THREAD: messageDispatcher = new DedicatedThreadDispatcher(); break; case REACTOR: messageDispatcher = new ReactorThreadDispatcher(); break; default: throw new IllegalArgumentException(format( "Unknown context dispatch strategy [%s]", config. getContextDispatchStrategy())); } }