/*
Set the Guaranteed Delivery Value RequestedOnly value in the message.

Javadoc description supplied by JsMessage interface.
769063
public final void setGuaranteedValueRequestedOnly(boolean value) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setGuaranteedValueRequestedOnly", Boolean.valueOf(value));
        getHdr2().setBooleanField(JsHdr2Access.GUARANTEEDVALUE_SET_REQUESTEDONLY, value);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setGuaranteedValueRequestedOnly");
    }
910047
public final void setGuaranteedRemoteGetWaitTime(long value) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setGuaranteedRemoteGetWaitTime", Long.valueOf(value));
        getHdr2().setLongField(JsHdr2Access.GUARANTEEDREMOTEGET_SET_WAITTIME, value);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setGuaranteedRemoteGetWaitTime");
    }
1074604
public void setDeliveryMode(Integer deliveryMode) {
        if (deliveryMode == null) {
            _properties.remove(AMQP_PROP_DELIVERY_MODE);
            return;
        }
        
        // Perhaps, we could do an enum for deliveryMode. But, it will require
        // some major changes in encoding and decoding and we don't have much
        // time to do it across all the clients.
        int value = deliveryMode.intValue();
        if ((value != 1) && (value != 2)) {
            String s = "AMQP 0-9-1 spec mandates 'deliveryMode' value to be " +
                       "either 1(for non-persistent) or 2(for persistent)";
            throw new IllegalStateException(s);
        }
        
        _properties.put(AMQP_PROP_DELIVERY_MODE, deliveryMode);
    }
814383
final JsMessage setPropertiesInMessage(LMEMessage theMessage)
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "setPropertiesInMessage", theMessage);

    boolean copyMade = false;

    //  If this is pubsub we share this message with other subscribers so we have
    //  to make a copy prior to any updates. If this is pt-to-pt then any changes
    //  we make here can be done before the copy, the copy is still required to
    //  prevent a consumer from rolling back after modifying the message but
    //  anything we set here will be reset the next time round so there's no harm
    //  done. It is best to defer the 'copy' until after we've changed it so there
    //  is less likelyhood of a real copy being required.
    JsMessageWrapper jsMessageWrapper = (JsMessageWrapper) theMessage.message;
    JsMessage jsMsg = jsMessageWrapper.getMessage();

    try
    {
      //set the redeliveredCount if required
      if (jsMessageWrapper.guessRedeliveredCount() != 0)
      {
        if(isPubsub)
        {
          jsMsg = jsMsg.getReceived();
          copyMade = true;
        }

        jsMsg.setRedeliveredCount(jsMessageWrapper.guessRedeliveredCount());
      }

      long waitTime = jsMessageWrapper.updateStatisticsMessageWaitTime();

      //Only store wait time in message where explicitly
      // asked
      if (setWaitTime )
      {
        //defect 256701: we only set the message wait time if it is
        //a significant value.
        boolean waitTimeIsSignificant =
          waitTime > messageProcessor.getCustomProperties().get_message_wait_time_granularity();

        if(waitTimeIsSignificant)
        {
          if(isPubsub && !copyMade)
          {
            jsMsg = jsMsg.getReceived();
            copyMade = true;
          }

          jsMsg.setMessageWaitTime(waitTime);
        }
      }

      // If we deferred the copy till now we need to see if one is
      // needed. This will be the case either if the consumer has indicated that
      // it may change the message (not a comms client) and the message is still
      // on an itemStream (i.e. they could rollback the message with their changes).
      // Otherwise we can just give them our copy as we'll never want it back or
      // give it to anyone else.
      if(!copyMade && ((theMessage.isStored && copyMsg) || isPubsub))
        jsMsg = jsMsg.getReceived();
    }
    catch (MessageCopyFailedException e)
    {
      FFDCFilter.processException(
        e,
        "com.ibm.ws.sib.processor.impl.AbstractLockedMessageEnumeration.setPropertiesInMessage",
        "1:2086: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:2093:1.154.3.1",
          e });

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

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


    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "setPropertiesInMessage", jsMsg);
    return jsMsg;
  }
1298826
public final void setMediated(boolean value) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setMediated", Boolean.valueOf(value));
        setFlagValue(MEDIATED_FLAG, value);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setMediated");
    }
905601
private void validateDeliveryDelayTime(long deliveryDelayTime) throws JMSException {
        if ((deliveryDelayTime < 0) || (deliveryDelayTime > MfpConstants.MAX_DELIVERY_DELAY)) {
            throw (JMSException) JmsErrorUtils.newThrowable(
                                                            JMSException.class,
                                                            "INVALID_VALUE_CWSIA0068",
                                                            new Object[] { "deliveryDelay", "" + deliveryDelayTime },
                                                            tc
                            );
        }

    }
982556
public void setSystemMessageValue(long value) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setSystemMessageValue", Long.valueOf(value));
        // Clear the cached MessageHandle
        cachedMessageHandle = null;
        // Set the value into the message itself
        jmo.setLongField(JsHdrAccess.SYSTEMMESSAGEVALUE, value);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setSystemMessageValue");
    }
1275089
public void setRequired(String value) {
	value = value.toLowerCase().trim();
	required = (value.equals("yes") || value.equals("true"));
    }
604356
@Override
    public final void setJmsDestination(byte[] value) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setJmsDestination", value);
        /* There is no need to take a copy because the JMS API layer will never */
        /* change the byte array passed in. */
        getHdr2().setField(JsHdr2Access.JMSDESTINATION_DATA, value);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setJmsDestination");
    }
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");
    }
629783
@Override
    public void setValue(org.openprovenance.prov.model.LangString value) {
        this.value = value;
    }
639025
final void setJsMessageType(MessageType value) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setJsMessageType", value);
        /* Get the int value of the MessageType and set that into the field */
        jmo.setField(JsHdrAccess.MESSAGETYPE, value.toByte());
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setJsMessageType");
    }
312662
public final void setGuaranteedRemoteBrowseID(long value) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setGuaranteedRemoteBrowseID", Long.valueOf(value));
        getHdr2().setLongField(JsHdr2Access.GUARANTEEDREMOTEBROWSE_SET_BROWSEID, value);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setGuaranteedRemoteBrowseID");
    }
1062294
@Override
    public final void setJmsReplyTo(byte[] value) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setJmsReplyTo", value);
        /* There is no need to take a copy because the JMS API layer will never */
        /* change the byte array passed in. */
        getHdr2().setField(JsHdr2Access.JMSREPLYTO_DATA, value);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setJmsReplyTo");
    }
438056
@Override
	public boolean putLocked( AbstractMessage srcMessage, LocalSession session , MessageLockSet locks ) throws JMSException
    {
    	checkNotClosed();
    	checkTransactionLock();
    
    	// Check delivery mode
    	if (!topicDef.supportDeliveryMode(srcMessage.getJMSDeliveryMode()))
    		throw new FFMQException("Topic does not support this delivery mode : "+
    				(srcMessage.getJMSDeliveryMode() == DeliveryMode.NON_PERSISTENT ? 
                    "DeliveryMode.NON_PERSISTENT" : "DeliveryMode.PERSISTENT"),
                    "INVALID_DELIVERY_MODE");
    	
    	sentToTopicCount.incrementAndGet();
    	
        boolean commitRequired = false;
        
        subscriptionsLock.readLock().lock();
        try
        {
        	// Pass 1 - Indexed subscriptions
        	if (!indexedSubscriptionMap.isEmpty())
        	{
        		srcMessage.ensureDeserializationLevel(MessageSerializationLevel.ALL_HEADERS);
        		for(Entry<String,Map<Object,List<LocalTopicSubscription>>> entry : indexedSubscriptionMap.entrySet())
        		{
        			String headerName = entry.getKey();
        			Object value;
        			if (headerName.equals("JMSCorrelationID")) // Intercept special headers
        				value = srcMessage.getJMSCorrelationID();
        			else
        				value = srcMessage.getObjectProperty(headerName);
        			
        			if (value != null)
        			{
        				value = normalizeLiteralValue(value);
        				List<LocalTopicSubscription> subscriptions = entry.getValue().get(value);
        				if (subscriptions != null)
        				{
        					if (pushToSubscriptions(srcMessage, session, locks, subscriptions))
        						commitRequired = true;
        				}
        			}
        		}
        	}
        	
        	// Pass 2 - Non indexed subscriptions
            if (!flatSubscriptions.isEmpty())
            	if (pushToSubscriptions(srcMessage, session, locks, flatSubscriptions))
            		commitRequired = true;
        }
        finally
        {
        	subscriptionsLock.readLock().unlock();
        }
        
        return commitRequired;
    }
1086444
private void validateTTLAndDD(long timeToLive) throws JMSException {
        // There is no point continuting when expiry/timetolive time is earlier than the deliveryDelay
        if (getDeliveryDelay() > 0 && timeToLive > 0) {//only if its non default value
            if (timeToLive <= getDeliveryDelay()) {
                throw (JMSException) JmsErrorUtils.newThrowable(
                                                                JMSException.class,
                                                                "INVALID_VALUE_CWSIA0070",
                                                                new Object[] { getDeliveryDelay(), timeToLive },
                                                                tc
                                );
            }
        }
    }
1145223
public final void setGuaranteedRemoteGetPrevTick(long value) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setGuaranteedRemoteGetPrevTick", Long.valueOf(value));
        getHdr2().setLongField(JsHdr2Access.GUARANTEEDREMOTEGET_SET_PREVTICK, value);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setGuaranteedRemoteGetPrevTick");
    }