All Downloads are FREE. Search and download functionalities are using the official Maven repository.

flex.messaging.messages.MessagePerformanceUtils Maven / Gradle / Ivy

There is a newer version: 4.8.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package flex.messaging.messages;

import flex.messaging.FlexContext;
import flex.messaging.endpoints.AbstractEndpoint;
import flex.messaging.io.amf.ActionContext;
import flex.messaging.log.Log;
import flex.messaging.log.LogCategories;

/**
 * @exclude
 *
 * Utility class for populating  MessagePerformanceInformation objects at various stages of
 * server processing.  A given message may have three MPI headers populated (naming convention
 * of these headers is from the perspective of the server):
 *
 * DSMPII - incoming message, message sent from client to server
 * DSMPIO - outgoing message, response/acknowledgement message sent from server back to client
 * DSMPIP - only populated for a pushed message, this is information for the incoming message
 * that caused the pushed message
 */
public class MessagePerformanceUtils
{

    static final String LOG_CATEGORY = LogCategories.MESSAGE_GENERAL;

    public static final String MPI_HEADER_IN = "DSMPII";
    public static final String MPI_HEADER_OUT = "DSMPIO";
    public static final String MPI_HEADER_PUSH = "DSMPIP";

    public static int MPI_NONE = 0;
    public static int MPI_TIMING = 1;
    public static int MPI_TIMING_AND_SIZING = 2;

    /**
     * @exclude
     *
     * Clones the MPI object for the incoming message from client to server
     * from the batch wrapper to all messages included in it, keeping track of
     * overhead time spent doing this.
     *
     * @param message The message whose MPI should be propogated
     */
    public static void propogateMPIDownBatch(Message message)
    {
        long overhead = System.currentTimeMillis();
        if(message instanceof BatchableMessage)
        {
            BatchableMessage dm = (BatchableMessage)message;
            if(dm.isBatched())
            {
                 Object[] batchedMessages = (Object[])message.getBody();
                 int batchedLength = batchedMessages.length;
                 for(int a=0;amarkServerPostAdapterExternalTime to mark the amount of time spent when your
     * adapter must make a call to an external component.  If record-message-times is
     * true for the communication channel, the server processing time external to the
     * adapter may be retrieved via MessagePerformanceUtils.serverAdapterExternalTime on the client
     * once it receives the message.
     *
     * If record-message-times is false for the communication channel,
     * calling this method will have no effect.
     *
     * @param message The message being processed
     */
    public static void markServerPreAdapterExternalTime(Message message)
    {
        // If the message does not have an MPI header then we are not recording message times
        // and we have nothing to do here
        if (getMPII(message) == null || getMPII(message).sendTime == 0)
            return;

        MessagePerformanceInfo mpi = getMPII(message);
        mpi.serverPreAdapterExternalTime = System.currentTimeMillis();
    }

    /**
     *
     * Method may be called from a custom adapter to mark the end of processing that occurs
     * outside of the adapter for a particular message.  Use this method in conjunction with
     * markServerPreAdapterExternalTime to mark the amount of time spent when your
     * adapter must make a call to an external component.  If record-message-times is
     * true for the communication channel, the server processing time external to the
     * adapter may be retrieved via MessagePerformanceUtils.serverAdapterExternalTime on the client
     * once it receives the message.
     *
     * If record-message-times is false for the communication channel,
     * calling this method will have no effect.
     *
     * @param message The message being processed
     */
    public static void markServerPostAdapterExternalTime(Message message)
    {
        // If the message does not have an MPI header then we are not recording message times
        // and we have nothing to do here
        if (getMPII(message) == null || getMPII(message).sendTime == 0 || getMPII(message).serverPostAdapterExternalTime != 0)
            return;

        MessagePerformanceInfo mpi = getMPII(message);
        mpi.serverPostAdapterExternalTime = System.currentTimeMillis();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy