@Override public void run() { try { consumer.close(); } catch (ActiveMQException e) { ActiveMQClientLogger.LOGGER.unableToCloseConsumer(e); } } });
@Override public ClientMessageImpl acknowledge() throws ActiveMQException { if (consumer != null) { consumer.acknowledge(this); } return this; }
private void cleanUpChildren() throws ActiveMQException { Set<ClientConsumerInternal> consumersClone = cloneConsumers(); for (ClientConsumerInternal consumer : consumersClone) { consumer.cleanUp(); } Set<ClientProducerInternal> producersClone = cloneProducers(); for (ClientProducerInternal producer : producersClone) { producer.cleanUp(); } }
long consumerId, boolean isSessionStarted) throws ActiveMQException { ClientSession.QueueQuery queueInfo = consumerInternal.getQueueInfo(); SessionCreateConsumerMessage createConsumerRequest = new SessionCreateConsumerMessage(getConsumerID(consumerInternal), consumerInternal.getQueueName(), consumerInternal.getFilterString(), consumerInternal.isBrowseOnly(), false); int clientWindowSize = consumerInternal.getClientWindowSize(); if (isSessionStarted && consumerInternal.getForceDeliveryCount() > 0) { SessionForceConsumerDelivery forceDel = new SessionForceConsumerDelivery(consumerId, consumerInternal.getForceDeliveryCount() - 1); sendPacketWithoutLock(sessionChannel, forceDel);
consumer.clearAtFailover(); consumer.clearAtFailover(); consumer.start();
private void popPacket() { try { if (streamEnded) { // no more packets, we are over the last one already throw new IndexOutOfBoundsException(); } int sizeToAdd = currentPacket != null ? currentPacket.chunk.length : 1; currentPacket = largeMessageData.poll(readTimeout, TimeUnit.MILLISECONDS); if (currentPacket == null) { throw new IndexOutOfBoundsException(); } if (currentPacket.chunk == null) { // Empty packet as a signal to interruption currentPacket = null; streamEnded = true; throw new IndexOutOfBoundsException(); } consumerInternal.flowControl(currentPacket.getFlowControlSize(), !currentPacket.isContinues()); packetPosition += sizeToAdd; packetLastPosition = packetPosition + currentPacket.getChunk().length; } catch (IndexOutOfBoundsException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void addConsumer(final ClientConsumerInternal consumer) { synchronized (consumers) { consumers.put(consumer.getConsumerContext(), consumer); } }
public void rollback(final boolean isLastMessageAsDelivered, final boolean waitConsumers) throws ActiveMQException { if (logger.isTraceEnabled()) { logger.trace("calling rollback(isLastMessageAsDelivered=" + isLastMessageAsDelivered + ")"); } checkClosed(); // We do a "JMS style" rollback where the session is stopped, and the buffer is cancelled back // first before rolling back // This ensures messages are received in the same order after rollback w.r.t. to messages in the buffer // For core we could just do a straight rollback, it really depends if we want JMS style semantics or not... boolean wasStarted = started; if (wasStarted) { stop(); } // We need to make sure we don't get any inflight messages for (ClientConsumerInternal consumer : cloneConsumers()) { consumer.clear(waitConsumers); } // Acks must be flushed here *after connection is stopped and all onmessages finished executing flushAcks(); sessionContext.simpleRollback(isLastMessageAsDelivered); if (wasStarted) { start(); } rollbackOnly = false; }
/** * @param queueName * @param filterString * @param windowSize * @param browseOnly * @return * @throws ActiveMQException */ private ClientConsumer internalCreateConsumer(final SimpleString queueName, final SimpleString filterString, final int priority, final int windowSize, final int maxRate, final boolean browseOnly) throws ActiveMQException { checkClosed(); ClientConsumerInternal consumer = sessionContext.createConsumer(queueName, filterString, priority, windowSize, maxRate, ackBatchSize, browseOnly, executor, flowControlExecutor); addConsumer(consumer); // Now we send window size credits to start the consumption // We even send it if windowSize == -1, since we need to start the // consumer // TODO: this could semantically change on other servers. I know for instance on stomp this is just an ignore if (consumer.getClientWindowSize() != 0) { sessionContext.sendConsumerCredits(consumer, consumer.getInitialWindowSize()); } return consumer; }
private void flushAcks() throws ActiveMQException { for (ClientConsumerInternal consumer : cloneConsumers()) { consumer.flushAcks(); } }
ClientMessage msg = cons1.receive(1000); Assert.assertNotNull("expected message at i = " + i, msg); Assert.assertEquals("A slow consumer shouldn't buffer anything on the client side!", 0, cons1.getBufferSize()); ClientMessage msg = cons2.receive(1000); Assert.assertEquals("A slow consumer shouldn't buffer anything on the client side!", 0, cons2.getBufferSize()); cons1.close(); cons2.close(); ClientMessage msg = cons2.receive(1000); Assert.assertNotNull("expected message at i = " + i, msg); Assert.assertEquals("A slow consumer shouldn't buffer anything on the client side!", 0, cons2.getBufferSize()); ClientMessage msg = cons1.receive(1000); Assert.assertEquals("A slow consumer shouldn't buffer anything on the client side!", 0, cons1.getBufferSize());
long consumerId, boolean isSessionStarted) throws ActiveMQException { ClientSession.QueueQuery queueInfo = consumerInternal.getQueueInfo(); SessionCreateConsumerMessage createConsumerRequest = new SessionCreateConsumerMessage(getConsumerID(consumerInternal), consumerInternal.getQueueName(), consumerInternal.getFilterString(), consumerInternal.getPriority(), consumerInternal.isBrowseOnly(), false); int clientWindowSize = consumerInternal.getClientWindowSize(); if (isSessionStarted && consumerInternal.getForceDeliveryCount() > 0) { SessionForceConsumerDelivery forceDel = new SessionForceConsumerDelivery(consumerId, consumerInternal.getForceDeliveryCount() - 1); sendPacketWithoutLock(sessionChannel, forceDel);
consumer.clearAtFailover(); consumer.clearAtFailover(); consumer.start();
@Override public void cancel() { this.handledException = ActiveMQClientMessageBundle.BUNDLE.largeMessageInterrupted(); synchronized (this) { int totalSize = 0; LargeData polledPacket = null; while ((polledPacket = largeMessageData.poll()) != null) { totalSize += polledPacket.getFlowControlSize(); } try { consumerInternal.flowControl(totalSize, false); } catch (Exception ignored) { // what else can we do here? ActiveMQClientLogger.LOGGER.errorCallingCancel(ignored); } largeMessageData.offer(new LargeData()); streamEnded = true; streamClosed = true; notifyAll(); } }
@Override public void removeConsumer(final ClientConsumerInternal consumer) throws ActiveMQException { synchronized (consumers) { consumers.remove(consumer.getConsumerContext()); } }
consumer.clear(false);
/** * @param queueName * @param filterString * @param windowSize * @param browseOnly * @return * @throws ActiveMQException */ private ClientConsumer internalCreateConsumer(final SimpleString queueName, final SimpleString filterString, final int priority, final int windowSize, final int maxRate, final boolean browseOnly) throws ActiveMQException { checkClosed(); ClientConsumerInternal consumer = sessionContext.createConsumer(queueName, filterString, priority, windowSize, maxRate, ackBatchSize, browseOnly, executor, flowControlExecutor); addConsumer(consumer); // Now we send window size credits to start the consumption // We even send it if windowSize == -1, since we need to start the // consumer // TODO: this could semantically change on other servers. I know for instance on stomp this is just an ignore if (consumer.getClientWindowSize() != 0) { sessionContext.sendConsumerCredits(consumer, consumer.getInitialWindowSize()); } return consumer; }
private void flushAcks() throws ActiveMQException { for (ClientConsumerInternal consumer : cloneConsumers()) { consumer.flushAcks(); } }
while (consumer.getBufferSize() < 10 && timeout > System.currentTimeMillis()) { Thread.sleep(10); ClientMessage msg = consumer.receive(10000); Assert.assertNotNull(msg); consumer.close();
long consumerId, boolean isSessionStarted) throws ActiveMQException { ClientSession.QueueQuery queueInfo = consumerInternal.getQueueInfo(); SessionCreateConsumerMessage createConsumerRequest = new SessionCreateConsumerMessage(getConsumerID(consumerInternal), consumerInternal.getQueueName(), consumerInternal.getFilterString(), consumerInternal.getPriority(), consumerInternal.isBrowseOnly(), false); int clientWindowSize = consumerInternal.getClientWindowSize(); if (isSessionStarted && consumerInternal.getForceDeliveryCount() > 0) { SessionForceConsumerDelivery forceDel = new SessionForceConsumerDelivery(consumerId, consumerInternal.getForceDeliveryCount() - 1); sendPacketWithoutLock(sessionChannel, forceDel);