/*
(non-Javadoc)
@see com.ibm.ws.sib.processor.impl.interfaces.LocalizationPoint#getUnAvailableMessageCount()
18361
public long getUnAvailableMessageCount()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "getUnAvailableMessageCount");

    long returnValue = -1;
    try
    {
      returnValue = getStatistics().getUnavailableItemCount();
    }
    catch(MessageStoreException e)
    {
      // FFDC
      FFDCFilter.processException(
          e,
          "com.ibm.ws.sib.processor.impl.store.itemstreams.PtoPMessageItemStream.getUnAvailableMessageCount",
          "1:894:1.93.1.14",
          this);  
      
      SibTr.exception(tc, e);
    } 
          
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "getUnAvailableMessageCount", new Long(returnValue));
    return returnValue;
  }
1263575
static String getCauseMessage(Throwable throwable) {
        List<Throwable> list = new ArrayList<>();
        while (throwable != null && list.contains(throwable) == false) {
            list.add(throwable);
            throwable = throwable.getCause();
        }
        return list.get(0).getMessage();
    }
626478
public UndeliverableReturnCode handleUndeliverableMessage(
                                                              SIMPMessage message,
                                                              TransactionCommon tran,
                                                              int exceptionReason,
                                                              String[] exceptionStrings,
                                                              String subscriptionID)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "handleUndeliverableMessage",
                        new Object[] { message,
                                      tran,
                                      Integer.valueOf(exceptionReason),
                                      exceptionStrings,
                                      subscriptionID });

        UndeliverableReturnCode rc =
                        handleUndeliverableMessage(message,
                                                   null, // alternateUser
                                                   tran,
                                                   exceptionReason,
                                                   exceptionStrings,
                                                   _messageProcessor.getMessagingEngineUuid(),
                                                   subscriptionID);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "handleUndeliverableMessage", rc);

        return rc;
    }
1223514
public int getTimeTillSpaceGetsAvailable() {
        long globalRatelimitResetTimestamp =
                RatelimitBucket.globalRatelimitResetTimestamp.getOrDefault(api.getToken(), 0L);
        long timestamp = System.currentTimeMillis() + (api.getTimeOffset() == null ? 0 : api.getTimeOffset());
        if (ratelimitRemaining > 0 && (globalRatelimitResetTimestamp - timestamp) <= 0) {
            return 0;
        }
        return (int) (Math.max(ratelimitResetTimestamp, globalRatelimitResetTimestamp) - timestamp);
    }
1364935
public SIBusMessage nextLocked() throws SISessionUnavailableException, SISessionDroppedException, SIConnectionUnavailableException, SIConnectionDroppedException, SIResourceException, SIConnectionLostException, SIIncorrectCallException {
    
    return _cursor >= messages.size () ? null : (SIBusMessage) messages.get(_cursor++);
    
  }
1319796
public int getMessagePriority()
  {
    if (tc.isEntryEnabled()) 
      SibTr.entry(tc, "getMessagePriority");
      
    int priority = aiValueTick.getMsgPriority();
    
    if (tc.isEntryEnabled()) 
      SibTr.exit(tc, "getMessagePriority", new Integer(priority));
    return priority;
  }
417649
public SIBusMessage nextLocked()
  throws SISessionUnavailableException, SISessionDroppedException,
         SIResourceException, SIConnectionLostException,
         SIErrorException, SIIncorrectCallException
  {
    if (TraceComponent.isAnyTracingEnabled() && CoreSPILockedMessageEnumeration.tc.isEntryEnabled())
      SibTr.entry(CoreSPILockedMessageEnumeration.tc, "nextLocked",
        new Object[] {new Integer(hashCode()), this});

    JsMessage jsMsg = null;
    JsMessageWrapper msg = null;
    LMEMessage dirtyMessage = null;
    boolean removeMsg = false;

    checkValidState("nextLocked");

    localConsumerPoint.checkNotClosed();

    // Make any list modifications under the lock
    synchronized(this)
    {
      // If we still have an unlocked message in the list remove it now
      if(currentUnlockedMessage != null)
      {
        removeMessage(currentUnlockedMessage);
        currentUnlockedMessage = null;
      }

      if(currentMsg != null)
        currentMsg = currentMsg.next;
      else if(!endReached)
        currentMsg = firstMsg;

      if(currentMsg != null)
      {
        msg = currentMsg.message;
        jsMsg = currentMsg.jsMessage;

        // Due to the slight dodgyness of setting jsMsg (see comment on dirtyMessage)
        // this tries to ensure our logic is correct
        if((jsMsg != null) && !currentMsg.wasRead)
        {
          SIErrorException e =
            new SIErrorException(nls.getFormattedMessage(
                            "INTERNAL_MESSAGING_ERROR_CWSIP0001",
                            new Object[] {
                              "com.ibm.ws.sib.processor.impl.AbstractLockedMessageEnumeration",
                              "1:1318:1.154.3.1" },
                              null));

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

          throw e;
        }

        // If the message was added to the message store but the consumer does
        // not require recovery we can delete the message before we return it.
        // We don't want to do it here under the lock, so we remember to do it
        // later but pretend we've already done it by the time we release the
        // lock - that way no-one else will think its in the message store when it
        // isn't.
        if(currentMsg.isStored && !currentMsg.isRecoverable)
        {
          removeMsg = true;
          currentMsg.isStored = false;
        }

        // We're about to release the list lock but we need to be able to set
        // the jsMessage back into the LMEMessage object later so we save a
        // pointer to it. BUT there is a slight possibility that by the time
        // we write the jsMessage into it the LMEMessage has been deleted from
        // the list (e.g. by an unlockAll() from the consumer), that's not a
        // problem in itself. BUT by deleting it from the list we actually can
        // put it into the set of pooled objects so you could be writing over
        // another message BUT we currently hold the AsynchConsumerLock and we
        // know no new messages can be added to the list unless they hold that
        // lock SO we may have moved into the pool but we couldn't have been
        // re-used SO we're safe!
        dirtyMessage = currentMsg;
        currentMsg.wasRead = true;

        //indicate that there is a message under the cursor
        messageAvailable = true;
      }
      else
      {
        messageAvailable = false;
        endReached = true;
      }
    } // synchronized

    //check it isn't null
    if((msg != null) && (jsMsg == null))
    {
      jsMsg = setPropertiesInMessage(currentMsg);


      if(removeMsg)
      {
        try
        {
          removeMessageFromStore(msg,
                                 null,
                                 false); // false = DON'T decrement active message count
                                         // (wait until the message is deleted/unlocked from the LME)
        }
        catch (SIMPMessageNotLockedException e)
        {
//        SIMPMessageNotLockedException shouldn't occur so FFDC.
          FFDCFilter.processException(
            e,
            "com.ibm.ws.sib.processor.impl.AbstractLockedMessageEnumeration.nextLocked",
            "1:1396:1.154.3.1",
            this);

          SibTr.exception(tc, e);
          SibTr.error(tc, "INTERNAL_MESSAGING_ERROR_CWSIP0002",
            new Object[] {
              "com.ibm.ws.sib.processor.impl.AbstractLockedMessageEnumeration",
              "1:1403:1.154.3.1",
              e });

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

          throw new SIResourceException(
            nls.getFormattedMessage(
              "INTERNAL_MESSAGING_ERROR_CWSIP0002",
              new Object[] {
                "com.ibm.ws.sib.processor.impl.AbstractLockedMessageEnumeration",
                "1:1414:1.154.3.1",
                e },
              null),
            e);
        }
      }

      dirtyMessage.jsMessage = jsMsg; // Read earlier comment before touching this!
    }

    if (TraceComponent.isAnyTracingEnabled() && UserTrace.tc_mt.isDebugEnabled())
      UserTrace.trace_Receive(null,
                              jsMsg,
                              consumerSession.getDestinationAddress(),
                              consumerSession.getIdInternal());

    if (TraceComponent.isAnyTracingEnabled() && CoreSPILockedMessageEnumeration.tc.isEntryEnabled())
      SibTr.exit(CoreSPILockedMessageEnumeration.tc, "nextLocked", new Object[] {jsMsg});
    //return the message or null
    return jsMsg;
  }
1133217
public function getVersion() : int
    {
        $stream = $this->loadContent(self::BASE_URI . '/version-number');

        if (!$stream->isReadable()) {
            throw new SourceUnavailableException('Source stream is not readable.', 1459162266);
        }

        return (int)$stream->getContents();
    }
790346
public function getUnreadMessageCount()
    {
        $messageMapper = ($this->container->dataMapper)('MessageMapper');
        $count = $messageMapper->findUnreadCount();

        return ($count === 0) ? null : $count;
    }
327819
public int getNumberAvailable() {
        int result = 0;
        for (int i = 0; i < data.size(); i++) {
            if (data.get(i) != null) {
                result += 1;
            }
        }
        return result;
    }
1363292
public SerialMessage getMultiChannelCapabilityGetMessage(ZWaveEndpoint endpoint) {
		logger.debug("Creating new message for application command MULTI_CHANNEL_CAPABILITY_GET for node {} and endpoint {}", this.getNode().getNodeId(), endpoint.getEndpointId());
		SerialMessage result = new SerialMessage(this.getNode().getNodeId(), SerialMessageClass.SendData, SerialMessageType.Request, SerialMessageClass.ApplicationCommandHandler, SerialMessagePriority.Get);
    	byte[] newPayload = { 	(byte) this.getNode().getNodeId(), 
    							3, 
								(byte) getCommandClass().getKey(), 
								(byte) MULTI_CHANNEL_CAPABILITY_GET,
								(byte) endpoint.getEndpointId() };
    	result.setMessagePayload(newPayload);
    	return result;
	}
827296
private int getUnSeenMessageCount() 
   {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc,"getUnseenMessageCount");
      
      int remain = 0;
      for (int x = nextIndex; x < messages.length; x++)
      {
         if (messages[x] != null) remain++;
      }
      
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc,"getUnseenMessageCount", ""+remain);
      return remain;
   }
1160603
@Override
    public UndeliverableReturnCode handleUndeliverableMessage(
                                                              SIMPMessage msg,
                                                              int exceptionReason,
                                                              String[] exceptionInserts,
                                                              TransactionCommon tran)
                    throws SIIncorrectCallException, SIResourceException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "handleUndeliverableMessage",
                        new Object[] { msg, new Integer(exceptionReason), exceptionInserts });

        UndeliverableReturnCode undeliverableReturnCode =
                        _targetDestinationHandler.handleUndeliverableMessage(msg, exceptionReason, exceptionInserts, tran);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "handleUndeliverableMessage", undeliverableReturnCode);

        return undeliverableReturnCode;
    }
1153721
public long getNumberOfQueuedMessages()
  {
    long count = 0;
    try
    {
      count = itemStream.getStatistics().getTotalItemCount();
    }
    catch (MessageStoreException e)
    {
      FFDCFilter.processException(
          e,
          "com.ibm.ws.sib.processor.runtime.LocalQueuePoint.getNumberOfQueuedMessages",
          "1:494:1.58", 
          this);
      SibTr.exception(tc, e);
    }    
    return count;
  }
77249
void checkNotClosed() throws SISessionUnavailableException
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "checkNotClosed");

    synchronized (this)
    {
      if (_closed)
      {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
          SibTr.exit(tc, "checkNotClosed", "Object closed");

        throw new SISessionUnavailableException(
          nls.getFormattedMessage("OBJECT_CLOSED_ERROR_CWSIP0081", 
                                  new Object[] { _dest.getName(),
                                                 _dest.getMessageProcessor().getMessagingEngineName() }, 
                                  null));
      }
    }

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "checkNotClosed");
  }
1177104
@Override
    public boolean isReavailable()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
        {
            SibTr.entry(tc, "isReavailable");
            SibTr.exit(tc, "isReavailable", Boolean.valueOf(reavailable));
        }
        return reavailable;
    }
836584
protected int statusCodeForException(@Nonnull Throwable exception) {
        if (exception instanceof PApplicationException) {
            PApplicationException e = (PApplicationException) exception;
            if (e.getId() == PApplicationExceptionType.INVALID_PROTOCOL ||
                e.getId() == PApplicationExceptionType.PROTOCOL_ERROR ||
                e.getId() == PApplicationExceptionType.BAD_SEQUENCE_ID ||
                e.getId() == PApplicationExceptionType.INVALID_MESSAGE_TYPE) {
                return HttpServletResponse.SC_BAD_REQUEST;
            }
            if (e.getId() == PApplicationExceptionType.UNKNOWN_METHOD) {
                return HttpServletResponse.SC_NOT_FOUND;
            }
        }
        return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    }