mirror of https://github.com/apache/activemq.git
Updated the flow control logic for the Topic case to match what we are using for the Queue case
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@585187 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8931aac98e
commit
9da7e31a33
|
@ -38,6 +38,7 @@ import org.apache.activemq.command.DestinationInfo;
|
|||
import org.apache.activemq.command.MessageId;
|
||||
import org.apache.activemq.command.ProducerId;
|
||||
import org.apache.activemq.command.ProducerInfo;
|
||||
import org.apache.activemq.state.ProducerState;
|
||||
import org.apache.activemq.util.IdGenerator;
|
||||
import org.apache.activemq.util.LongSequenceGenerator;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -286,6 +287,7 @@ public class AdvisoryBroker extends BrokerFilter {
|
|||
final ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
|
||||
producerExchange.setConnectionContext(context);
|
||||
producerExchange.setMutable(true);
|
||||
producerExchange.setProducerState(new ProducerState(new ProducerInfo()));
|
||||
try {
|
||||
context.setProducerFlowControl(false);
|
||||
next.send(producerExchange, advisoryMessage);
|
||||
|
|
|
@ -42,6 +42,8 @@ import org.apache.activemq.command.Message;
|
|||
import org.apache.activemq.command.MessageAck;
|
||||
import org.apache.activemq.command.MessageId;
|
||||
import org.apache.activemq.command.ProducerAck;
|
||||
import org.apache.activemq.command.ProducerInfo;
|
||||
import org.apache.activemq.command.Response;
|
||||
import org.apache.activemq.command.SubscriptionInfo;
|
||||
import org.apache.activemq.filter.MessageEvaluationContext;
|
||||
import org.apache.activemq.store.MessageRecoveryListener;
|
||||
|
@ -279,13 +281,16 @@ public class Topic implements Destination {
|
|||
public void send(final ProducerBrokerExchange producerExchange, final Message message) throws Exception {
|
||||
final ConnectionContext context = producerExchange.getConnectionContext();
|
||||
|
||||
final ProducerInfo producerInfo = producerExchange.getProducerState().getInfo();
|
||||
final boolean sendProducerAck = !message.isResponseRequired() && producerInfo.getWindowSize() > 0 && !context.isInRecoveryMode();
|
||||
|
||||
// There is delay between the client sending it and it arriving at the
|
||||
// destination.. it may have expired.
|
||||
if (broker.isExpired(message)) {
|
||||
broker.messageExpired(context, message);
|
||||
destinationStatistics.getMessages().decrement();
|
||||
if ((!message.isResponseRequired() || producerExchange.getProducerState().getInfo().getWindowSize() > 0) && !context.isInRecoveryMode()) {
|
||||
ProducerAck ack = new ProducerAck(producerExchange.getProducerState().getInfo().getProducerId(), message.getSize());
|
||||
if (sendProducerAck) {
|
||||
ProducerAck ack = new ProducerAck(producerInfo.getProducerId(), message.getSize());
|
||||
context.getConnection().dispatchAsync(ack);
|
||||
}
|
||||
return;
|
||||
|
@ -299,33 +304,39 @@ public class Topic implements Destination {
|
|||
// We can avoid blocking due to low usage if the producer is sending
|
||||
// a sync message or
|
||||
// if it is using a producer window
|
||||
if (producerExchange.getProducerState().getInfo().getWindowSize() > 0 || message.isResponseRequired()) {
|
||||
if (producerInfo.getWindowSize() > 0 || message.isResponseRequired()) {
|
||||
synchronized (messagesWaitingForSpace) {
|
||||
messagesWaitingForSpace.add(new Runnable() {
|
||||
public void run() {
|
||||
|
||||
// While waiting for space to free up... the message
|
||||
// may have expired.
|
||||
if (broker.isExpired(message)) {
|
||||
broker.messageExpired(context, message);
|
||||
destinationStatistics.getMessages().decrement();
|
||||
|
||||
if (!message.isResponseRequired() && !context.isInRecoveryMode()) {
|
||||
ProducerAck ack = new ProducerAck(producerExchange.getProducerState().getInfo().getProducerId(), message.getSize());
|
||||
context.getConnection().dispatchAsync(ack);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
doMessageSend(producerExchange, message);
|
||||
|
||||
// While waiting for space to free up... the
|
||||
// message may have expired.
|
||||
if (broker.isExpired(message)) {
|
||||
broker.messageExpired(context, message);
|
||||
destinationStatistics.getMessages().decrement();
|
||||
} else {
|
||||
doMessageSend(producerExchange, message);
|
||||
}
|
||||
|
||||
if (sendProducerAck) {
|
||||
ProducerAck ack = new ProducerAck(producerInfo.getProducerId(), message.getSize());
|
||||
context.getConnection().dispatchAsync(ack);
|
||||
} else {
|
||||
Response response = new Response();
|
||||
response.setCorrelationId(message.getCommandId());
|
||||
context.getConnection().dispatchAsync(response);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
if (message.isResponseRequired() && !context.isInRecoveryMode()) {
|
||||
if (!sendProducerAck && !context.isInRecoveryMode()) {
|
||||
ExceptionResponse response = new ExceptionResponse(e);
|
||||
response.setCorrelationId(message.getCommandId());
|
||||
context.getConnection().dispatchAsync(response);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -362,6 +373,10 @@ public class Topic implements Destination {
|
|||
}
|
||||
|
||||
doMessageSend(producerExchange, message);
|
||||
if (sendProducerAck) {
|
||||
ProducerAck ack = new ProducerAck(producerInfo.getProducerId(), message.getSize());
|
||||
context.getConnection().dispatchAsync(ack);
|
||||
}
|
||||
}
|
||||
|
||||
void doMessageSend(final ProducerBrokerExchange producerExchange, final Message message) throws IOException, Exception {
|
||||
|
|
Loading…
Reference in New Issue