void clearMessagesInProgress(AtomicInteger transportInterruptionProcessingComplete) { clearRequestsCounter.incrementAndGet(); executor.clearMessagesInProgress();
void execute(MessageDispatch message) throws InterruptedException { if (!startedOrWarnedThatNotStarted) { ActiveMQConnection connection = session.connection; long aboutUnstartedConnectionTimeout = connection.getWarnAboutUnstartedConnectionTimeout(); if (connection.isStarted() || aboutUnstartedConnectionTimeout < 0L) { startedOrWarnedThatNotStarted = true; } else { long elapsedTime = System.currentTimeMillis() - connection.getTimeCreated(); // lets only warn when a significant amount of time has passed // just in case its normal operation if (elapsedTime > aboutUnstartedConnectionTimeout) { LOG.warn("Received a message on a connection which is not yet started. Have you forgotten to call Connection.start()? Connection: " + connection + " Received: " + message); startedOrWarnedThatNotStarted = true; } } } if (!session.isSessionAsyncDispatch() && !dispatchedBySessionPool) { dispatch(message); } else { messageQueue.enqueue(message); wakeup(); } }
@Override public void dispatch(MessageDispatch messageDispatch) { try { executor.execute(messageDispatch); } catch (InterruptedException e) { Thread.currentThread().interrupt(); connection.onClientInternalException(e); } }
synchronized void start() { if (!messageQueue.isRunning()) { messageQueue.start(); if (hasUncomsumedMessages()) { wakeup(); } } }
public void wakeup() { if (!dispatchedBySessionPool) { if (session.isSessionAsyncDispatch()) { try { TaskRunner taskRunner = this.taskRunner; if (taskRunner == null) { synchronized (this) { if (this.taskRunner == null) { if (!isRunning()) { // stop has been called return; } this.taskRunner = session.connection.getSessionTaskRunner().createTaskRunner(this, "ActiveMQ Session: " + session.getSessionId()); } taskRunner = this.taskRunner; } } taskRunner.wakeup(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } else { while (iterate()) { } } } }
public void run() { MessageDispatch messageDispatch; while ((messageDispatch = executor.dequeueNoWait()) != null) { final MessageDispatch md = messageDispatch; final ActiveMQMessage message = (ActiveMQMessage)md.getMessage(); executor.waitForQueueRestart(); } catch (InterruptedException ex) { connection.onClientInternalException(ex);
/** * Checks whether the session has unconsumed messages. * * @return true - if there are unconsumed messages. */ public boolean hasUncomsumedMessages() { return executor.hasUncomsumedMessages(); }
public void redispatch(ActiveMQDispatcher dispatcher, MessageDispatchChannel unconsumedMessages) throws JMSException { List<MessageDispatch> c = unconsumedMessages.removeAll(); for (MessageDispatch md : c) { this.connection.rollbackDuplicate(dispatcher, md.getMessage()); } Collections.reverse(c); for (Iterator<MessageDispatch> iter = c.iterator(); iter.hasNext();) { MessageDispatch md = iter.next(); executor.executeFirst(md); } }
public List<MessageDispatch> getUnconsumedMessages() { return executor.getUnconsumedMessages(); }
public boolean iterate() { // Deliver any messages queued on the consumer to their listeners. for (ActiveMQMessageConsumer consumer : this.session.consumers) { if (consumer.iterate()) { return true; } } // No messages left queued on the listeners.. so now dispatch messages // queued on the session MessageDispatch message = messageQueue.dequeueNoWait(); if (message == null) { return false; } else { dispatch(message); return !messageQueue.isEmpty(); } }
/** * Construct the Session * * @param connection * @param sessionId * @param acknowledgeMode n.b if transacted - the acknowledgeMode == * Session.SESSION_TRANSACTED * @param asyncDispatch * @param sessionAsyncDispatch * @throws JMSException on internal error */ protected ActiveMQSession(ActiveMQConnection connection, SessionId sessionId, int acknowledgeMode, boolean asyncDispatch, boolean sessionAsyncDispatch) throws JMSException { this.debug = LOG.isDebugEnabled(); this.connection = connection; this.acknowledgementMode = acknowledgeMode; this.asyncDispatch = asyncDispatch; this.sessionAsyncDispatch = sessionAsyncDispatch; this.info = new SessionInfo(connection.getConnectionInfo(), sessionId.getValue()); setTransactionContext(new TransactionContext(connection)); stats = new JMSSessionStatsImpl(producers, consumers); this.connection.asyncSendPacket(info); setTransformer(connection.getTransformer()); setBlobTransferPolicy(connection.getBlobTransferPolicy()); this.connectionExecutor=connection.getExecutor(); this.executor = new ActiveMQSessionExecutor(this); connection.addSession(this); if (connection.isStarted()) { start(); } }
while ((messageDispatch = executor.dequeueNoWait()) != null) { final MessageDispatch md = messageDispatch; ActiveMQMessage message = (ActiveMQMessage)md.getMessage();
synchronized void start() { if (!messageQueue.isRunning()) { messageQueue.start(); if (hasUncomsumedMessages()) { wakeup(); } } }
public void wakeup() { if (!dispatchedBySessionPool) { if (session.isSessionAsyncDispatch()) { try { TaskRunner taskRunner = this.taskRunner; if (taskRunner == null) { synchronized (this) { if (this.taskRunner == null) { if (!isRunning()) { // stop has been called return; } this.taskRunner = session.connection.getSessionTaskRunner().createTaskRunner(this, "ActiveMQ Session: " + session.getSessionId()); } taskRunner = this.taskRunner; } } taskRunner.wakeup(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } else { while (iterate()) { } } } }
public void run() { MessageDispatch messageDispatch; while ((messageDispatch = executor.dequeueNoWait()) != null) { final MessageDispatch md = messageDispatch; final ActiveMQMessage message = (ActiveMQMessage)md.getMessage(); executor.waitForQueueRestart(); } catch (InterruptedException ex) { connection.onClientInternalException(ex);
/** * Checks whether the session has unconsumed messages. * * @return true - if there are unconsumed messages. */ public boolean hasUncomsumedMessages() { return executor.hasUncomsumedMessages(); }
public void redispatch(ActiveMQDispatcher dispatcher, MessageDispatchChannel unconsumedMessages) throws JMSException { List<MessageDispatch> c = unconsumedMessages.removeAll(); for (MessageDispatch md : c) { this.connection.rollbackDuplicate(dispatcher, md.getMessage()); } Collections.reverse(c); for (Iterator<MessageDispatch> iter = c.iterator(); iter.hasNext();) { MessageDispatch md = iter.next(); executor.executeFirst(md); } }
public List<MessageDispatch> getUnconsumedMessages() { return executor.getUnconsumedMessages(); }
public boolean iterate() { // Deliver any messages queued on the consumer to their listeners. for (ActiveMQMessageConsumer consumer : this.session.consumers) { if (consumer.iterate()) { return true; } } // No messages left queued on the listeners.. so now dispatch messages // queued on the session MessageDispatch message = messageQueue.dequeueNoWait(); if (message == null) { return false; } else { dispatch(message); return !messageQueue.isEmpty(); } }
/** * Construct the Session * * @param connection * @param sessionId * @param acknowledgeMode n.b if transacted - the acknowledgeMode == * Session.SESSION_TRANSACTED * @param asyncDispatch * @param sessionAsyncDispatch * @throws JMSException on internal error */ protected ActiveMQSession(ActiveMQConnection connection, SessionId sessionId, int acknowledgeMode, boolean asyncDispatch, boolean sessionAsyncDispatch) throws JMSException { this.debug = LOG.isDebugEnabled(); this.connection = connection; this.acknowledgementMode = acknowledgeMode; this.asyncDispatch = asyncDispatch; this.sessionAsyncDispatch = sessionAsyncDispatch; this.info = new SessionInfo(connection.getConnectionInfo(), sessionId.getValue()); setTransactionContext(new TransactionContext(connection)); stats = new JMSSessionStatsImpl(producers, consumers); this.connection.asyncSendPacket(info); setTransformer(connection.getTransformer()); setBlobTransferPolicy(connection.getBlobTransferPolicy()); this.connectionExecutor=connection.getExecutor(); this.executor = new ActiveMQSessionExecutor(this); connection.addSession(this); if (connection.isStarted()) { start(); } }