}
if (SELECTOR_REJECTING.equals(state))
{
log.trace(this + " is rejecting message since doesn't match selector");
return new SimpleDelivery(null, null, true, false);
}
if (REJECTING.equals(state))
{
log.trace(this + " is rejecting reference " + ref);
return null;
}
if (ACCEPTING_TO_MAX.equals(state))
{
//Only accept up to maxRefs references
if (messages.size() == maxRefs)
{
return null;
}
}
if (BROKEN.equals(state))
{
throw new RuntimeException("THIS IS AN EXCEPTION THAT SIMULATES "+
"THE BEHAVIOUR OF A BROKEN RECEIVER");
}
log.trace("State is:" + state);
boolean done = ACKING.equals(state);
//NOTE! it is NOT Nacking, it is keeping - don't say NACKing - it is misleading (nack means cancel)
log.trace(this + " is " + (done ? "ACKing" : "Keeping") + " message " + ref);
Message m = ref.getMessage();
SimpleDelivery delivery = new SimpleDelivery(observer, ref, done);
messages.add(new Object[] {m, done ? null : delivery});
if (immediateAsynchronousAcknowledgment)
{
log.trace("simulating an asynchronous ACK that arrives before we return the delivery to channel");
try
{
delivery.acknowledge(null);
}
catch(Throwable t)
{
log.error("Cannot acknowledge", t);
}