/* (non-Javadoc)
@see com.ibm.ws.sib.processor.impl.interfaces.MessageEventListener#messageEventOccurred(int, com.ibm.ws.sib.processor.impl.interfaces.SIMPMessage, com.ibm.ws.sib.msgstore.Transaction)
197131
public void messageEventOccurred(
    int event,
    SIMPMessage msg,
    TransactionCommon tran)
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) 
      SibTr.entry(tc, "messageEventOccurred", 
        new Object[]{new Integer(event), msg, tran});
        
    InvalidOperationException e = 
      new InvalidOperationException(nls.getFormattedMessage(
        "INTERNAL_MESSAGING_ERROR_CWSIP0001",
        new Object[] {
          "com.ibm.ws.sib.processor.impl.PubSubOutputHandler",
          "1:603:1.164.1.5" },
        null));
    
    // FFDC
    FFDCFilter.processException(
      e,
      "com.ibm.ws.sib.processor.impl.PubSubOutputHandler.messageEventOccurred",
      "1:610:1.164.1.5",
      this);
    
    SibTr.error(tc, "INTERNAL_MESSAGING_ERROR_CWSIP0001",
    new Object[] {
      "com.ibm.ws.sib.processor.impl.PubSubOutputHandler",
      "1:616:1.164.1.5" } );
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "messageEventOccurred", e);
    throw e;  
  }
1234090
public void runtimeEventOccurred(RuntimeEvent event)
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) 
      SibTr.entry(tc, "runtimeEventOccurred", event);
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) 
      SibTr.exit(tc, "runtimeEventOccurred");    
  }
1068275
public final void requestUpdate(Transaction transaction) throws MessageStoreException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "requestUpdate", transaction);

        Membership membership = _getMembership();
        if (null == membership)
        {
            throw new NotInMessageStore();
        }
        else
        {
            membership.requestUpdate(transaction);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "requestUpdate");
    }
503973
@Override
	public void submitResourceModified(final ResourceModifiedMessage theMsg) {
		/*
		 * We only want to submit the message to the processing queue once the
		 * transaction is committed. We do this in order to make sure that the
		 * data is actually in the DB, in case it's the database matcher.
		 */
		if (TransactionSynchronizationManager.isSynchronizationActive()) {
			TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
				@Override
				public int getOrder() {
					return 0;
				}

				@Override
				public void afterCommit() {
					sendToProcessingChannel(theMsg);
				}
			});
		} else {
			sendToProcessingChannel(theMsg);
		}
	}
26446
public boolean rollbackInsert(MessageItem msg) throws SIResourceException
  {  
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "rollbackInsert", msg);
    boolean updated = updateSourceStream(msg, true);
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "rollbackInsert", new Boolean(updated));
    return updated;
  }
882618
@Override
    public void deliverExpressMessage(MessageItem msgItem,
                                      ExpressTargetStream expressTargetStream)

                    throws SIIncorrectCallException, SIResourceException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "deliverExpressMessage", new Object[] { msgItem });

        //Create transaction
        LocalTransaction siTran = _txManager.createLocalTransaction(false);

        try
        {
            long endTick = msgItem.getMessage().getGuaranteedValueValueTick();

            JsDestinationAddress routingDestinationAddr =
                            msgItem.getMessage().getRoutingDestination();
            if (routingDestinationAddr != null)
            {
                DestinationHandler routingDestination = null;
                try
                {
                    routingDestination =
                                    _destinationManager.getDestination(routingDestinationAddr, false, true);

                    if (_isLink)
                    {
                        LinkHandler link = (LinkHandler) _destination;

                        // If this is coming in off a link then use the link's configuration
                        // to determine if any local message points should be preferred
                        msgItem.setPreferLocal(link.preferLocalTargetQueuePoint());

                        String linkInboundUserid = ((LinkHandler) _destination).getInboundUserid();
                        if (linkInboundUserid != null)
                        {
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                                SibTr.debug(tc, "Set link inbound userid: " + linkInboundUserid + ", into message");
                            // Call SIB.security (ultimately) to set inbounduserid into msg
                            _messageProcessor.getAccessChecker().setSecurityIDInMessage(
                                                                                        linkInboundUserid,
                                                                                        msgItem.getMessage());
                        }
                    }
                    // If it's come from another ME in the bus then they're sending it
                    // to this message point because they want to so we prefer the local one.
                    // This allows the mesasge to be re-routed if absolutely necessary.
                    else
                        msgItem.setPreferLocal(true);

                    // Call the handler to deal with the message - passing null as the producer
                    // session id.
                    ProducerInputHandler inputHandler =
                                    (ProducerInputHandler) routingDestination.getInputHandler();

                    inputHandler.handleMessage(msgItem,
                                               siTran,
                                               _messageProcessor.getMessagingEngineUuid());

                } catch (SIException e)
                {
                    // No FFDC code needed

                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    {
                        SibTr.exception(tc, e);
                        SibTr.debug(tc, "Discarding the express message as it could not be from the targetStreamManager");
                    }
                }
            }
            else
            {
                ConsumerDispatcher consumerDispatcher;

                consumerDispatcher = (ConsumerDispatcher) _destination.getLocalPtoPConsumerManager();
                consumerDispatcher.put(msgItem, siTran, null, false);
            }

            // Update the completedPrefix on the stream
            // This will put all ticks before this point into Completed state
            expressTargetStream.setCompletedPrefix(endTick);

            siTran.commit();
        } catch (SIIncorrectCallException e)
        {
            // No FFDC code needed
            handleRollback(siTran);

            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(tc, "deliverExpressMessage", e);

            throw e;
        } catch (SIResourceException e)
        {
            // No FFDC code needed
            handleRollback(siTran);

            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(tc, "deliverExpressMessage", e);

            throw e;
        } catch (RuntimeException e)
        {
            // FFDC
            FFDCFilter.processException(
                                        e,
                                        "com.ibm.ws.sib.processor.impl.PtoPInputHandler.deliverExpressMessage",
                                        "1:2840:1.323",
                                        this);

            handleRollback(siTran);

            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            {
                SibTr.exception(tc, e);
                SibTr.exit(tc, "deliverExpressMessage", e);
            }

            throw e;
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "deliverExpressMessage");
    }
223893
private void eventMessageExpiryNotification(
                                                SIMPMessage msg,
                                                TransactionCommon tran) throws SIResourceException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(
                        tc,
                        "eventMessageExpiryNotification",
                        new Object[] { msg, tran });

        // If a ReportHandler object has not been created yet, then do so.
        if (_reportHandler == null)
            _reportHandler = new ReportHandler(messageProcessor);

        // Generate and send the report under the same transaction as the delete
        try
        {
            _reportHandler.handleMessage(msg, tran, SIApiConstants.REPORT_EXPIRY);
        } catch (SIException e)
        {
            FFDCFilter.processException(
                                        e,
                                        "com.ibm.ws.sib.processor.impl.BaseDestinationHandler.eventMessageExpiryNotification",
                                        "1:3778:1.700.3.45",
                                        this);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(tc, "eventMessageExpiryNotification", "SIResourceException");
            throw new SIResourceException(
                            nls.getFormattedMessage(
                                                    "REPORT_MESSAGE_ERROR_CWSIP0422",
                                                    new Object[] { messageProcessor.getMessagingEngineName(), e },
                                                    null),
                            e);
        }

        /**
         * 463584
         * If this message has been restored from msgstore but this destination has been recreated
         * in admin thus a different destination uuid and diferent BDH instance the stats object will be null.
         * It only gets initialized during the create/updateLocalisations call. This call will never happen
         * on this BDH.
         * Therefore... If a destination has been recreated, the stats on expiry will no longer be valid.
         */
        if (_protoRealization != null)
            _protoRealization.onExpiryReport();

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "eventMessageExpiryNotification");
    }
1134870
@Override
    public void unlockMsg(long lockID, Transaction transaction, boolean incrementUnlock) throws MessageStoreException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "unlockMsg", new Object[] { Long.valueOf(lockID), transaction, Boolean.valueOf(incrementUnlock) });

        if (failedInitInRestore)
        {
            initialiseNonPersistent(true);
        }

        if (incrementUnlock)
        {
            // If we do not wish to increment the count, there is no point checking
            // against redelivery threshold
            redeliveryCountReached = false;

            try
            {
                if (PRE_UNLOCKED_1 != null)
                {
                    PRE_UNLOCKED_1.messageEventOccurred(MessageEvents.PRE_UNLOCKED, this, transaction);
                }
                if (PRE_UNLOCKED_2 != null)
                {
                    PRE_UNLOCKED_2.messageEventOccurred(MessageEvents.PRE_UNLOCKED, this, transaction);
                }
            } catch (SIException e)
            {
                FFDCFilter.processException(
                                            e,
                                            "com.ibm.ws.sib.processor.impl.store.items.MessageItem.unlockMsg",
                                            "1:2955:1.244.1.40",
                                            this);

                SibTr.exception(tc, e);

                // Something went wrong so make sure we unlock the message
                redeliveryCountReached = false;
            }

        }

        // If the pre_unlocked callback redirected the message to the exc dest,
        // then unlock the message.
        if (!redeliveryCountReached)
        {
            unlock(lockID, transaction, incrementUnlock);

            SIMPItemStream itemStream = (SIMPItemStream) getItemStream();
            BaseDestinationHandler bdh = getDestinationHandler(false, itemStream);

            // proceede if and only if the redeliverycount column exists
            if (bdh.isRedeliveryCountPersisted() && bdh.getMessageProcessor().getMessageStore().isRedeliveryCountColumnAvailable()) {

                int rdl_count = guessRedeliveredCount();

                persistRedeliveredCount(rdl_count);

                //updating the value in MFP.
                if (msg != null)
                    msg.setRedeliveredCount(rdl_count);

            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "unlockMsg");
    }
131521
@Override
    public void batchCommitted()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "batchCommitted", Integer.valueOf(messagesInBatch));

        //we have succesfully completed the batch
        numberOfMessagesReceived += messagesInBatch;
        messagesInBatch = 0;
        updateCompletedPrefix();

        sendAck();

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "batchCommitted");
    }
754482
@Override
    public void afterCompletion(TransactionCommon transaction, boolean committed)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "afterCompletion", new Object[] { transaction, Boolean.valueOf(committed) });

        // Reset the current transaction now that this one has completed
        synchronized (orderLock)
        {
            // If asynch and a rollback occurred, unlock all messages
            // in the LME
            try
            {
                if (!committed && currentLME != null)
                    currentLME.unlockAll();
            } catch (SIResourceException e)
            {
                // FFDC
                FFDCFilter.processException(
                                            e,
                                            "com.ibm.ws.sib.processor.impl.ConsumerDispatcher.afterCompletion",
                                            "1:3673:1.280.5.25",
                                            this);

                SibTr.exception(tc, e);
                SibTr.error(tc, "ORDERED_MESSAGING_ERROR_CWSIP0117",
                            new Object[] {
                                          _baseDestHandler.getName(),
                                          _messageProcessor.getMessagingEngineName() });

            } catch (SISessionDroppedException e)
            {
                // FFDC
                FFDCFilter.processException(
                                            e,
                                            "com.ibm.ws.sib.processor.impl.ConsumerDispatcher.afterCompletion",
                                            "1:3689:1.280.5.25",
                                            this);

                SibTr.exception(tc, e);
                SibTr.error(tc, "ORDERED_MESSAGING_ERROR_CWSIP0117",
                            new Object[] {
                                          _baseDestHandler.getName(),
                                          _messageProcessor.getMessagingEngineName() });

            } catch (SIMPMessageNotLockedException e)
            {
                // No FFDC code needed
                // This exception has occurred beause someone has deleted the
                // message(s). Ignore this exception as it is unlocked anyway
            }

            currentTran = null;
            currentLME = null;
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "afterCompletion");
    }
318487
@Override
    public void localTransactionCommitted(ConnectionEvent event) {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(this, tc, "localTransactionCommitted");
        }

        if (event.getId() == ConnectionEvent.LOCAL_TRANSACTION_COMMITTED) {

            if (mcWrapper.involvedInTransaction()) {

                /*
                 * The ManagedConnection is associated with a transaction.
                 * Delist the ManagedConnection from the transaction and
                 * postpone release of the connection until transaction finishes.
                 */

                TranWrapper wrapper = null;
                try {
                    wrapper = mcWrapper.getCurrentTranWrapper();
                    wrapper.delist();
                } catch (ResourceException e) {
                    // Can't delist, something went wrong.
                    //  Destroy the connection(s) so it can't cause any future problems.
                    FFDCFilter.processException(e, "com.ibm.ejs.j2c.ConnectionEventListener.localTransactionCommitted", "316", "this");
                    // add datasource name to message
                    Tr.error(tc, "DELIST_FAILED_J2CA0073", "localTransactionCommitted", e, mcWrapper.gConfigProps.cfName);
                    // Moved event.getSource() inside of catch block for performance reasons
                    ManagedConnection mc = null;
                    try {
                        mc = (ManagedConnection) event.getSource();
                    } catch (ClassCastException cce) {
                        Tr.error(tc, "GET_SOURCE_CLASS_CAST_EXCP_J2CA0098", cce);
                        throw new IllegalStateException("ClassCastException occurred attempting to cast event.getSource to ManagedConnection");
                    }
                    ConnectionEvent errorEvent = new ConnectionEvent(mc, ConnectionEvent.CONNECTION_ERROR_OCCURRED);
                    this.connectionErrorOccurred(errorEvent);
                    RuntimeException rte = new IllegalStateException(e.getMessage());
                    throw rte;
                }
            } else {
                // if we are not involved in a transaction, then we are likely running with NO transaction
                //  context on the thread.  This case currently needs to be supported because
                //  servlets can spin their own threads which would not have context.
                // Note: it is very rare that users do this.  All other occurances are
                //  considered to be an error.
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
                    Tr.exit(this, tc, "localTransactionCommitted", "no transaction context, return without delisting");
                }
                return;
            }
        } else {
            // Connection Event passed in doesn't match the method called.
            // This should never happen unless there is an error in the ResourceAdapter.
            processBadEvent("localTransactionCommitted", ConnectionEvent.LOCAL_TRANSACTION_COMMITTED, event);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(this, tc, "localTransactionCommitted");
        }
        return;

    }
781636
@Override
    public void eventPostCommitAdd(Transaction transaction) throws SevereMessageStoreException
    {
        super.eventPostCommitAdd(transaction);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "eventPostCommitAdd", transaction);

        if (failedInitInRestore)
        {
            initialiseNonPersistent(true);
            setRegisterForPostEvents(true);
        }

        if (TraceComponent.isAnyTracingEnabled() && UserTrace.tc_mt.isDebugEnabled())
        {
            try
            {
                if (getJSMessage(true).isApiMessage())
                {
                    boolean foreignBus = false;
                    boolean link = false;
                    boolean mqlink = false;

                    String targetME = null;
                    if (debugName != null)
                    {
                        SIMPItemStream itemstream = (SIMPItemStream) getItemStream();

                        BaseDestinationHandler destination = getDestinationHandler(false, itemstream);

                        if (itemstream instanceof PubSubMessageItemStream)
                        {
                            targetME = destination.getMessageProcessor().getMessagingEngineName();
                        }
                        else
                        {
                            SIBUuid8 meUUID = ((PtoPMessageItemStream) itemstream).getLocalizingMEUuid();
                            if (meUUID.equals(destination.getMessageProcessor().getMessagingEngineUuid()))
                                targetME = destination.getMessageProcessor().getMessagingEngineName();
                            else
                            {
                                // If it's not the local messaging engine, then don't attempt the very
                                // expensive operation of trawling through admin for a messaging engine
                                // we may (intra-bus) or may not (inter-bus) know about - just for UserTrace.
                                // While the V7 and later interface is better than V6.1, looking up the
                                // name would be an excessive overhead in the critical path.
                                targetME = meUUID.toString();
                            }

                        }

                        foreignBus = destination.isForeignBus();
                        link = destination.isLink();
                        mqlink = destination.isMQLink();
                    }

                    String apiMsgId = null;
                    String correlationId = null;

                    if (getJSMessage(true) instanceof JsApiMessage)
                    {
                        apiMsgId = ((JsApiMessage) getJSMessage(true)).getApiMessageId();
                        correlationId = ((JsApiMessage) getJSMessage(true)).getCorrelationId();
                    }
                    else
                    {
                        if (getJSMessage(true).getApiMessageIdAsBytes() != null)
                            apiMsgId = new String(getJSMessage(true).getApiMessageIdAsBytes());

                        if (getJSMessage(true).getCorrelationIdAsBytes() != null)
                            correlationId = new String(getJSMessage(true).getCorrelationIdAsBytes());
                    }

                    String msg = "PRODUCER_SEND_COMMIT_CWSJU0003";

                    if (foreignBus)
                        msg = "PRODUCER_SEND_COMMIT_BUS_CWSJU0064";
                    else if (mqlink)
                        msg = "PRODUCER_SEND_COMMIT_MQLINK_CWSJU0066";
                    else if (link)
                        msg = "PRODUCER_SEND_COMMIT_LINK_CWSJU0065";

                    SibTr.debug(this, UserTrace.tc_mt,
                                nls_mt.getFormattedMessage(
                                                           msg,
                                                           new Object[] {
                                                                         apiMsgId,
                                                                         getJSMessage(true).getSystemMessageId(),
                                                                         correlationId,
                                                                         debugName,
                                                                         targetME },
                                                           null));
                }
            } catch (MessageStoreException e)
            {
                // No FFDC code needed

                // Log the exception
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    SibTr.exception(tc, e);

                // As the item is no longer in the store it has likely been committed already.
                // there doesn't seem any point to log the Message Trace at this point.
            }
        }

        // Remove temporary hack to delete publication with no subscribers 183715.1
        if (!transaction.isAutoCommit())
        {
            try
            {
                if (POST_COMMIT_ADD_1 != null)
                {
                    POST_COMMIT_ADD_1.messageEventOccurred(MessageEvents.POST_COMMIT_ADD, this, transaction);
                }
                if (POST_COMMIT_ADD_2 != null)
                {
                    POST_COMMIT_ADD_2.messageEventOccurred(MessageEvents.POST_COMMIT_ADD, this, transaction);
                }
            } catch (SIException e)
            {
                FFDCFilter.processException(
                                            e,
                                            "com.ibm.ws.sib.processor.impl.store.items.MessageItem.eventPostCommitAdd",
                                            "1:1313:1.244.1.40",
                                            this);

                SibTr.exception(tc, e);

                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                    SibTr.exit(this, tc, "eventPostCommitAdd", e);

                throw new SIErrorException(e);
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "eventPostCommitAdd");
    }
414379
protected void eventPostCommitAdd(SIMPMessage msg, TransactionCommon transaction)
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
    {
      SibTr.entry(tc, "eventPostCommitAdd", new Object[]{msg, transaction});
      SibTr.exit(tc, "eventPostCommitAdd");
    }
  }
129025
@Override
    public void eventUnlocked() throws SevereMessageStoreException
    {
        super.eventUnlocked();

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "eventUnlocked");

        if (failedInitInRestore)
        {
            //we can only register the listeners if we are fully initialized
            if (stream instanceof DurableSubscriptionItemStream)
            {
                stream.registerListeners(this);
            }
            failedInitInRestore = false;
        }

        reavailable = true;

        try
        {
            // 541867
            // When a message is unlocked, a registered ConsumerDispatcher will try to deliver
            // it to a ready consumer. When this happens the consumer will register for the UNLOCK
            // event. If that is added to a later slot (e.g. UNLOCKED_3) than the one that's currently
            // being processed (the ConsumerDispatcher) it is possible for us to drive the new consumer's
            // unlock event straight away (even though the message has just been locked).

            // This can also result in two (or more) consumers (or multiple instances of the same consumer)
            // being registered on the same message as we may not have deregistered the initial consumer
            // at the time that the ConsumerDispatcher delivers the to the second (or the same) consumer
            // after the unlock.

            // The solution is to proccess all the non-ConsumerDispatchers registered before going back
            // and driving the ConsumerDispatcher.
            for (int pass = 0; pass < 2; pass++)
            {
                if ((UNLOCKED_1 != null) &&
                    (((pass == 0) && !(UNLOCKED_1 instanceof ConsumerDispatcher)) ||
                    ((pass == 1) && (UNLOCKED_1 instanceof ConsumerDispatcher))))
                {
                    UNLOCKED_1.messageEventOccurred(MessageEvents.UNLOCKED, this, null);
                }
                if ((UNLOCKED_2 != null) &&
                    (((pass == 0) && !(UNLOCKED_2 instanceof ConsumerDispatcher)) ||
                    ((pass == 1) && (UNLOCKED_2 instanceof ConsumerDispatcher))))
                {
                    UNLOCKED_2.messageEventOccurred(MessageEvents.UNLOCKED, this, null);
                }
                if ((UNLOCKED_3 != null) &&
                    (((pass == 0) && !(UNLOCKED_3 instanceof ConsumerDispatcher)) ||
                    ((pass == 1) && (UNLOCKED_3 instanceof ConsumerDispatcher))))
                {
                    UNLOCKED_3.messageEventOccurred(MessageEvents.UNLOCKED, this, null);
                }
            }
        } catch (SIException e)
        {
            FFDCFilter.processException(
                                        e,
                                        "com.ibm.ws.sib.processor.impl.store.items.MessageItemReference.eventUnlocked",
                                        "1:574:1.106",
                                        this);

            SibTr.exception(tc, e);

            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(tc, "eventUnlocked", e);

            throw new SIErrorException(e);
        }
        reavailable = false;

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "eventUnlocked");
    }
663226
protected IQueueMessage<ID, DATA> takeFromRingBuffer() {
        LOCK_TAKE.lock();
        try {
            long l = consumedSeq.get() + 1;
            if (l <= knownPublishedSeq) {
                try {
                    Event<ID, DATA> eventHolder = ringBuffer.get(l);
                    try {
                        return eventHolder.get();
                    } finally {
                        eventHolder.set(null);
                    }
                } finally {
                    consumedSeq.incrementAndGet();
                }
            } else {
                knownPublishedSeq = ringBuffer.getCursor();
            }
            return null;
        } finally {
            LOCK_TAKE.unlock();
        }
    }
789158
@Override
    public void registerForMessageEvents(SIMPMessage msg)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "registerForMessageEvents", msg);

        registerForEvents(msg);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "registerForMessageEvents");
    }
418095
final protected void eventPrecommitAdd(MessageItem msg, final TransactionCommon transaction) throws SIDiscriminatorSyntaxException, SIResourceException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "eventPrecommitAdd", new Object[] { msg, transaction });

        if (!(_destination.isToBeDeleted()))
        {
            if (msg.isTransacted() && (!(msg.isToBeStoredAtSendTime())))
            {
                // LockR the destination to prevent reallocation from occurring on the chosen localisation
                LockManager reallocationLock = _destination.getReallocationLockManager();
                reallocationLock.lock();
                try
                {
                    // If we fixed the ME it'll be in the routing address in the message
                    SIBUuid8 fixedME = null;
                    JsDestinationAddress routingAddr = msg.getMessage().getRoutingDestination();
                    if (routingAddr != null)
                        fixedME = routingAddr.getME();

                    // If the sender prefers any local ME over others then we'll give it a go
                    SIBUuid8 preferredME = null;
                    if (msg.preferLocal())
                    {
                        if (_destination.hasLocal())
                            preferredME = _messageProcessor.getMessagingEngineUuid();
                    }
                    // 176658.3.5
                    OutputHandler handler = _destination.choosePtoPOutputHandler(fixedME,
                                                                                 preferredME,
                                                                                 !msg.isFromRemoteME(),
                                                                                 msg.isForcePut(),
                                                                                 null);

                    if (handler == null)
                    {
                        // We can't find a suitable localisation.
                        // Although a queue must have at least one localisation this is
                        // possible if the sender restricted the potential localisations
                        // using a fixed ME or a scoping alias (to an out-of-date set of
                        // localisation)

                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                        {
                            SibTr.debug(tc, "No suitable OutputHandler found for " + _destination.getName() + " (" + fixedME + ")");
                        }

                        //Put the message to the exception destination.
                        handleUndeliverableMessage(_destination
                                                   , null // null LinkHandler
                                                   , msg
                                                   , SIRCConstants.SIRC0026_NO_LOCALISATIONS_FOUND_ERROR
                                                   , new String[] { _destination.getName() }
                                                   , transaction);
                    }
                    else
                    {
                        //Indicate in the message if this was a guess
                        msg.setStreamIsGuess(handler.isWLMGuess());

                        // put the message to the output handler
                        handler.put(msg, transaction, null, true);
                    }
                } finally
                {
                    // unlock the reallocation lock
                    reallocationLock.unlock();
                }
            }
        }
        else
        {
            //The destination has been deleted.  Put the message to the exception destination#
            ExceptionDestinationHandlerImpl exceptionDestinationHandlerImpl =
                            (ExceptionDestinationHandlerImpl) _messageProcessor.createExceptionDestinationHandler(null);

            //Set indicator to send the message to the exception destination immediately,
            //rather than registering it for pre-prepare of the transaction, as this is
            //pre-prepare of the transaction!
            msg.setStoreAtSendTime(true);

            String destName = _destination.getName();
            if (_destination.isLink())
                destName = ((LinkHandler) _destination).getBusName();

            final UndeliverableReturnCode rc =
                            exceptionDestinationHandlerImpl.handleUndeliverableMessage(msg
                                                                                       , transaction
                                                                                       , SIRCConstants.SIRC0032_DESTINATION_DELETED_ERROR
                                                                                       , new String[] { destName,
                                                                                                       _messageProcessor.getMessagingEngineName() });
            if (rc != UndeliverableReturnCode.OK)
            {
                if (rc == UndeliverableReturnCode.DISCARD)
                {
                    //The message is to be discarded.  Do nothing and it will disappear.
                }
                else
                {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                        SibTr.exit(tc, "eventPrecommitAdd", "WsRuntimeException");
                    //We cannot put the message to the exception destination.  All we can
                    //do in this case is rollback the users transaction.  This is done by
                    //throwing an exception that is caught by the transaction manager.
                    throw new WsRuntimeException(
                                    nls.getFormattedMessage(
                                                            "DESTINATION_DELETED_ERROR_CWSIP0247",
                                                            new Object[] { _destination.getName(),
                                                                          rc },
                                                            null));
                }
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "eventPrecommitAdd");
    }