{
// This code path handles poll messages sent by Consumer.receive().
// This API should not trigger server side waits, so we invoke poll
// and if there are no queued messages for this Consumer instance we
// return an empty acknowledgement immediately.
MessageClient client = null;
try
{
client = subscriptionManager.getMessageClient(clientId, endpointId);
if (client != null)
{
if (adapter.handlesSubscriptions())
{
List missedMessages = (List)adapter.manage(command);
if (missedMessages != null && !missedMessages.isEmpty())
{
MessageBroker broker = getMessageBroker();
for (Iterator iter = missedMessages.iterator(); iter.hasNext();)
broker.routeMessageToMessageClient((Message)iter.next(), client);
}
}
FlushResult flushResult = client.getFlexClient().poll(client);
List messagesToReturn = (flushResult != null) ? flushResult.getMessages() : null;
if (messagesToReturn != null && !messagesToReturn.isEmpty())
{
replyMessage = new CommandMessage(CommandMessage.CLIENT_SYNC_OPERATION);
replyMessage.setBody(messagesToReturn.toArray());