return null;
}
if ((!remote) && ref.getMessage().isExpired())
{
SimpleDelivery delivery = new SimpleDelivery(observer, ref, true, false);
try
{
sessionEndpoint.expireDelivery(delivery, expiryQueue);
}
catch (Throwable t)
{
log.error("Failed to expire delivery: " + delivery, t);
}
return delivery;
}
if (preserveOrdering && remote)
{
//If the header exists it means the message has already been sucked once - so reject.
if (ref.getMessage().getHeader(Message.CLUSTER_SUCKED) != null)
{
if (trace) { log.trace("Message has already been sucked once - not sucking again"); }
return null;
}
}
synchronized (startStopLock)
{
// If the consumer is stopped then we don't accept the message, it should go back into the
// queue for delivery later.
if (!started)
{
if (trace) { log.trace(this + " NOT started!"); }
return null;
}
if (trace) { log.trace(this + " has startStopLock lock, preparing the message for delivery"); }
Message message = ref.getMessage();
boolean selectorRejected = !this.accept(message);
SimpleDelivery delivery = new SimpleDelivery(observer, ref, !selectorRejected, false);
if (selectorRejected)
{
return delivery;
}
if (noLocal)
{
String conId = ((JBossMessage) message).getConnectionID();
if (trace) { log.trace("message connection id: " + conId + " current connection connection id: " + sessionEndpoint.getConnectionEndpoint().getConnectionID()); }
if (sessionEndpoint.getConnectionEndpoint().getConnectionID().equals(conId))
{
if (trace) { log.trace("Message from local connection so rejecting"); }
try
{
delivery.acknowledge(null);
}
catch (Throwable t)
{
log.error("Failed to acknowledge delivery", t);
return null;
}
return delivery;
}
}
sendCount++;
int num = prefetchSize;
if (firstTime)
{
//We make sure we have a little extra buffer on the client side
num = num + num / 3 ;
}
if (sendCount == num)
{
clientAccepting = false;
firstTime = false;
}
//now for a remote sucker, we need to update the messages status
if (remote)
{
PersistenceManager pm = sessionEndpoint.getPersistenceManager();
if (ref.getMessage().isReliable() && messageQueue.isRecoverable())
{
try
{
pm.updateMessageState(messageQueue.getChannelID(), ref, "S");
}
catch (Exception e)
{
//we need to stop the sucking process. the message should be re-delivered.
log.error("Failed to update state for message: " + ref, e);
return null;
}
}
delivery.setSucked(true);
}
try
{
sessionEndpoint.handleDelivery(delivery, this);