@Override
 public final void flush() {
   AMQPConnection<?> connection = _target.getSessionModel().getAMQPConnection();
   try {
     connection.alwaysAllowMessageAssignmentInThisThreadIfItIsIOThread(true);
     _queue.flushConsumer(this);
     _target.processPending();
   } finally {
     connection.alwaysAllowMessageAssignmentInThisThreadIfItIsIOThread(false);
   }
 }
 @Override
 protected void onClose() {
   if (_closed.compareAndSet(false, true)) {
     _target.getSendLock();
     try {
       _waitingOnCreditMessageListener.remove();
       _target.consumerRemoved(this);
       _target.removeStateChangeListener(_listener);
       _queue.unregisterConsumer(this);
       deleted();
     } finally {
       _target.releaseSendLock();
     }
   }
 }
  QueueConsumerImpl(
      final AbstractQueue<?> queue,
      ConsumerTarget target,
      final String consumerName,
      final FilterManager filters,
      final Class<? extends ServerMessage> messageClass,
      EnumSet<Option> optionSet) {
    super(
        parentsMap(queue, target.getSessionModel().getModelObject()),
        createAttributeMap(consumerName, filters, optionSet));
    _messageClass = messageClass;
    _sessionReference = target.getSessionModel().getConnectionReference();
    _consumerNumber = CONSUMER_NUMBER_GENERATOR.getAndIncrement();
    _filters = filters;
    _acquires = optionSet.contains(Option.ACQUIRES);
    _seesRequeues = optionSet.contains(Option.SEES_REQUEUES);
    _isTransient = optionSet.contains(Option.TRANSIENT);
    _target = target;
    _queue = queue;

    // Access control
    authoriseCreate(this);

    open();

    setupLogging();

    _listener =
        new StateChangeListener<ConsumerTarget, ConsumerTarget.State>() {
          @Override
          public void stateChanged(
              final ConsumerTarget object,
              final ConsumerTarget.State oldState,
              final ConsumerTarget.State newState) {
            targetStateChanged(oldState, newState);
          }
        };
    _target.addStateListener(_listener);

    _suspendedConsumerLoggingTicker =
        new SuspendedConsumerLoggingTicker(
            queue.getContextValue(Long.class, Consumer.SUSPEND_NOTIFICATION_PERIOD)) {
          @Override
          protected void log(final long period) {
            getEventLogger().message(getLogSubject(), SubscriptionMessages.STATE(period));
          }
        };
  }
 public boolean resend(final QueueEntry entry) {
   boolean messageWasResent = getQueue().resend(entry, this);
   if (messageWasResent) {
     _target.processPending();
   }
   return messageWasResent;
 }
 @Override
 public void acquisitionRemoved(final QueueEntry node) {
   _target.acquisitionRemoved(node);
   _queue.decrementUnackedMsgCount(node);
 }
 public final void send(final QueueEntry entry, final boolean batch) {
   _deliveredCount.incrementAndGet();
   long size = _target.send(this, entry, batch);
   _deliveredBytes.addAndGet(size);
 }
 @Override
 public State getState() {
   return STATE_MAP.get(_target.getState());
 }
 public void queueEmpty() {
   _target.queueEmpty();
 }
 public void restoreCredit(final QueueEntry queueEntry) {
   _target.restoreCredit(queueEntry.getMessage());
 }
 public boolean wouldSuspend(final QueueEntry msg) {
   return !_target.allocateCredit(msg.getMessage());
 }
 public void queueDeleted() {
   _target.queueDeleted();
 }
 public void flushBatched() {
   _target.flushBatched();
 }
 @Override
 public boolean isSuspended() {
   return _target.isSuspended();
 }
 @Override
 public AMQSessionModel getSessionModel() {
   return _target.getSessionModel();
 }
 @Override
 public long getUnacknowledgedMessages() {
   return _target.getUnacknowledgedMessages();
 }