Obtain a Carbon from a message, if available.
<p>
Only {@link Message} instances can contain a Carbon extensions.
</p>

@param msg Message object to check for carbons

@return a Carbon if available, null otherwise.
979419
public static CarbonExtension from(Message msg) {
        CarbonExtension cc = msg.getExtension(Direction.received.name(), NAMESPACE);
        if (cc == null)
            cc = msg.getExtension(Direction.sent.name(), NAMESPACE);
        return cc;
    }
988496
protected byte[] serialize(IMessage<ID, DATA> msg) {
        return msg != null ? SerializationUtils.toByteArray(msg) : null;
    }
1071016
public Message createReplyMessage(Message message)
    {
        Object objResponseID = ((BaseMessage)message).getMessageHeader().get(TrxMessageHeader.MESSAGE_RESPONSE_ID);
        if (objResponseID == null)
            return null;    // TODO (don) FIX this - return an error.
        MessageProcessInfo recMessageProcessInfo = (MessageProcessInfo)this.getMessageProcessInfo(objResponseID.toString());
        MessageInfo recMessageInfo = (MessageInfo)((ReferenceField)recMessageProcessInfo.getField(MessageProcessInfo.MESSAGE_INFO_ID)).getReference();
        BaseMessage replyMessage = new TreeMessage(null, null);
        MessageRecordDesc messageRecordDesc = recMessageInfo.createNewMessage(replyMessage, null);
        return replyMessage;
    }
718060
public static Builder from(ServiceMessage message) {
    return ServiceMessage.builder().data(message.data()).headers(message.headers());
  }
656871
public static byte[] extractTargetInfoFromType2Message(byte[] msg,
            Integer msgFlags) {
        int flags = msgFlags == null ? extractFlagsFromType2Message(msg)
                : msgFlags;

        if (!ByteUtilities.isFlagSet(flags, FLAG_NEGOTIATE_TARGET_INFO))
            return null;

        int pos = 40; //isFlagSet(flags, FLAG_NEGOTIATE_LOCAL_CALL) ? 40 : 32;

        return readSecurityBufferTarget(msg, pos);
    }
402967
public synchronized HttpMessage pollPath(HttpMessage msg) {
        SiteNode resultNode = null;
        URI uri = msg.getRequestHeader().getURI();
        
        SiteNode parent = getRoot();
        String folder;
        
        try {
            String host = getHostName(uri);
            
            // no host yet
            parent = findChild(parent, host);
            if (parent == null) {
                return null;
        	}
            List<String> path = model.getSession().getTreePath(uri);
            if (path.size() == 0) {
            	// Its a top level node
            	resultNode = parent;
            }
            for (int i=0; i < path.size(); i++) {
            	folder = path.get(i);
                if (folder != null && !folder.equals("")) {
                    if (i == path.size()-1) {
                        String leafName = getLeafName(folder, msg);
                        resultNode = findChild(parent, leafName);
                    } else {
                        parent = findChild(parent, folder);
                        if (parent == null) {
                            return null;
                        }
                    }
                }
            }
        } catch (URIException e) {
            // ZAP: Added error
            log.error(e.getMessage(), e);
        }
        
        if (resultNode == null || resultNode.getHistoryReference() == null) {
            return null;
        }
        
        HttpMessage nodeMsg = null;
        try {
            nodeMsg = resultNode.getHistoryReference().getHttpMessage();
        } catch (Exception e) {
            // ZAP: Added error
            log.error(e.getMessage(), e);
        }
        return nodeMsg;
    }
554359
private static boolean isDataMessage(final ByteBuf msg) {
    return DcpMutationMessage.is(msg) || DcpDeletionMessage.is(msg) || DcpExpirationMessage.is(msg);
  }
957022
@SuppressWarnings("unchecked")
	public static <T extends Message> T copy(final T message) {
		return message == null ? null : (T) message.copy();
	}
494324
public BaseMessage getMessageObject()
    {
        if (m_message == null)
        {
            Map<String,Object> properties = new Hashtable<String,Object>();
            m_message = new MapMessage(new BaseMessageHeader(BACKUP_QUEUE_NAME, BACKUP_QUEUE_TYPE, this, null), properties);
        }
        return m_message;
    }
1015025
public static int extractFlagsFromType2Message(byte[] msg) {
        byte[] flagsBytes = new byte[4];

        System.arraycopy(msg, 20, flagsBytes, 0, 4);
        ByteUtilities.changeWordEndianess(flagsBytes, 0, 4);

        return ByteUtilities.makeIntFromByte4(flagsBytes);
    }
1013267
@Override
    public void sendMsg(String msg)
    {
        DbConn cnx = Helpers.getNewDbSession();
        try
        {
            Message.create(cnx, msg, ji.getId());
            cnx.commit();
        }
        finally
        {
            Helpers.closeQuietly(cnx);
        }
    }
521772
public SIMPMessage getMessageLocked() throws MessageStoreException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "getMessageLocked");
    
    SIMPMessage msg = null;
    
    if(classifyingMessages)
    {
      // Take the classifications read lock
      consumerSet.takeClassificationReadLock();

      // Classifications may change dynamically, so check the pendingReset
      // flag under this lock. If classifications have changed then we'll
      // set up the filters again
      if(pendingFlowReset)
      {
        pendingFlowReset = false;
        resetFlowProperties();
      }
        
      // Determine which cursor to use. chooseGetCursorIndex() will 
      // randomly choose an index if XD has specified weightings.
      // The method can be called more than once. This supports the situation
      // where we've looked for but not found any messages of a particular 
      // classification. 
      // 
      // If chooseGetCursorIndex() returns 0, then either no classifications were 
      // specified or we've already tried all the classifications. An index
      // of 0 leads to the use of the default (unclassified) cursor.
      int classIndex = -1;
      while(classIndex != 0)
      {
        classIndex = chooseGetCursorIndex(classIndex);
     
        // Always use the cursor straight from the key
        msg = getMessageLocked(classIndex);

        if(msg != null)
          classIndex = 0;
      }

      // Free the classifications read lock
      consumerSet.freeClassificationReadLock();
    }
    else // Not classifying
    {
      // Use the zeroth index
      msg = getMessageLocked(0);
    }

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "getMessageLocked", msg);

    return msg;
  }
744306
public Stream add(StreamFragmentBean msg) {
        Stream stream = streamCache.getUnchecked(msg.getHeader().getId());
        stream.add(msg);
        return stream;
    }
836020
private WMessages getWMessageInstance() {
		MessageContainer container = getMessageContainer(component);
		WMessages result = null;

		if (container == null) {
			LOG.warn("No MessageContainer as ancestor of " + component
					+ ". Messages will not be added");
		} else {
			result = container.getMessages();

			if (result == null) {
				LOG.warn("No messages in container of " + component
						+ ". Messages will not be added");
			}
		}

		return result;
	}
1077751
protected final String exceptionMessage(String msg) {
        if (msg == null) {
            msg = "";
        }

        StringBuilder buf = new StringBuilder(128 + msg.length())
            .append(protocol())
            .append(", ")
            .append(authScheme())
            .append(", ")
            .append(proxyAddress)
            .append(" => ")
            .append(destinationAddress);
        if (!msg.isEmpty()) {
            buf.append(", ").append(msg);
        }

        return buf.toString();
    }
1212515
static public String getString(String msg, Object[] args)
	{
		String format = msg;

		if (bundle != null)
		{
			try
			{
				format = bundle.getString(msg);
			}
			catch (MissingResourceException e)
			{
			}
		}

		return format(format, args);
	}
433241
public MessageBroker getMessageBroker() {
        if (this.messageBroker != null) {
            return this.messageBroker;
        }
        Assert.notNull(FlexContext.getMessageBroker(), "A MessageBroker was not set on the MessageTemplate "
            + "and no thread-local MessageBroker could be found in the FlexContext.");
        return FlexContext.getMessageBroker();
    }