return consumerDelegate;
}
public Object handleClosing(Invocation invocation) throws Throwable
{
ConsumerState consumerState = getState(invocation);
try
{
// We make sure closing is called on the ServerConsumerEndpoint.
// This returns us the last delivery id sent
Long l = (Long) invocation.invokeNext();
long lastDeliveryId = l.longValue();
// First we call close on the ClientConsumer which waits for onMessage invocations
// to complete and the last delivery to arrive
consumerState.getClientConsumer().close(lastDeliveryId);
SessionState sessionState = (SessionState) consumerState.getParent();
ConnectionState connectionState = (ConnectionState) sessionState.getParent();
sessionState.removeCallbackHandler(consumerState.getClientConsumer());
CallbackManager cm = connectionState.getRemotingConnection().getCallbackManager();
cm.unregisterHandler(consumerState.getConsumerID());
//And then we cancel any messages still in the message callback handler buffer
consumerState.getClientConsumer().cancelBuffer();
return l;
}
catch (Exception proxiedException)
{
ConnectionState connectionState = (ConnectionState) (consumerState.getParent().getParent());
// if ServerPeer is shutdown or
// if there is no failover in place... we just close the consumerState as well
if (proxiedException instanceof MessagingShutdownException ||
(connectionState.getFailoverCommandCenter() == null))
{
if (!consumerState.getClientConsumer().isClosed())
{
consumerState.getClientConsumer().close(-1);
}
}
throw proxiedException;
}