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

at.spardat.xma.rpc.RemoteCallData Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

// @(#) $Id: RemoteCallData.java 2640 2008-08-20 11:10:41Z webok $
package at.spardat.xma.rpc;

import java.io.IOException;

import at.spardat.xma.monitoring.client.ClientTimingEvent;
import at.spardat.xma.serializer.XmaInput;
import at.spardat.xma.serializer.XmaOutput;

/**
 * Acts as value object to store data transferred in remote operations between
 * XMA-client and XMA-server.
 *
 * @author YSD, 26.05.2003 10:42:37
 */
class RemoteCallData extends RemoteData {

    /**
     * Name of the server side event method.
     */
    protected String            eventName_;

    /**
     * The short name of the component.
     */
    protected String            namComponent_;

    /**
     * The id of the component that issues the remote call
     */
    protected short             idComponent_;

    /**
     * Indicates if the issuer is a page or a component
     */
    protected boolean           issuerIsPage_;

    /**
     * If the issuer is a page, this holds the id of the page
     */
    protected short             idPage_;

    /**
     * The type of the page.
     */
    protected short             idPageType_;

    /**
     * The ids of components that are already destroyed at the client but may still
     * be alive at the server side. They may be destroyed at the server.
     */
    protected short[]           deadComponents_;

    /**
     * Indicates that pageDeltas_ does not contain deltas, but
     * the complete state of the client component.
     */
    protected boolean           fullSync_;

    /**
     * Holds the last RPC-measurement done by the client.
     */
    private CallMeasurement     lastClientMeasurement_;



    /**
     * Writes this to the provided XmaOutput
     */
    protected void externalize (XmaOutput o) throws IOException {
        // important: start with the number of the runtime version, as
        // this might be required
        super.externalizeExclParameter (o);
        // the user supplied parameters
        super.externalizeParameters (o);
        // the information contained in this
        o.writeString ("evtName", eventName_);
        o.writeString ("namComp", namComponent_);
        o.writeShort ("idComp", idComponent_);
        o.writeBoolean ("isPage", issuerIsPage_);
        if (issuerIsPage_) {
            o.writeShort("idPage", idPage_);
            o.writeShort("idPageTyp", idPageType_);
        }
        o.writeShort("numDeadComps", (short)deadComponents_.length);
        for (int i=0; iexternalize
     */
    protected void internalize (XmaInput in) throws IOException, ClassNotFoundException {
        super.internalizeExclParameter(in);
        super.internalizeParameters(in);
        eventName_ = in.readString();
        namComponent_ = in.readString();
        idComponent_ = in.readShort();
        issuerIsPage_ = in.readBoolean();
        if (issuerIsPage_) {
            idPage_ = in.readShort();
            idPageType_ = in.readShort();
        }
        short numDead = in.readShort();
        deadComponents_ = new short[numDead];
        for (int i=0; iisIssuerPage() is true, i.e., the RPC is launched within a page and
     * not at the component level, this method returns the type of the page.
     */
    public short getIdPageType () {
        return idPageType_;
    }

    /**
     * Returns if the RPC is launched from a page and not from a component.
     */
    public boolean isLaunchedFromPage () {
        return issuerIsPage_;
    }

    /**
     * Returns the short name of the component from within the RPC is launched.
     */
    public String getNamComponent() {
        return namComponent_;
    }


    /**
     * On every RPC, an object of this class is created by the client and
     * sent as encoded value in the next RPC.
     */
    public static class CallMeasurement {
        // duration of the call in milliseconds
        int          durationMSecs_;
        // was the RPC successful?
        boolean      success_;

        // amount of data send from client to server;
        int client2serverSize=-1;
        // amount of data send form server to client;
        int server2clientSize=-1;

        ClientTimingEvent[] clientTimingEvents;


        void externalize (XmaOutput o) throws IOException {
            int encoded = (durationMSecs_) << 3;
            if (success_) encoded |= 1;
            if(client2serverSize==-1&&server2clientSize==-1) encoded |= 2;

            if(clientTimingEvents != null && clientTimingEvents.length > 0){
                encoded |= 4;  //client timing events will be written
            }

            o.writeInt("lastCltMsrmnt", encoded);
            if((encoded&2)==0) {
                o.writeInt("lastCltMsrCS", client2serverSize);
                o.writeInt("lastCltMsrSC", server2clientSize);
            }

            if((encoded&4)!=0){
                o.writeByte("clientTimingEventsCount", (byte)clientTimingEvents.length);
                for (int i = 0; i < clientTimingEvents.length; i++) {
                    clientTimingEvents[i].externalize(o);
                }
            }

        }

        boolean internalize (XmaInput in) throws IOException {
            boolean clientTimingAvailable = false;
            int encoded = in.readInt();
            if(encoded==-1) return false;
            success_ = ((encoded & 1) != 0);
            if((encoded&4)!=0){ //client timing events will be read
                clientTimingAvailable = true;
            }
            durationMSecs_ = encoded >> 3;
            if((encoded&2)==0) {
                client2serverSize=in.readInt();
                server2clientSize=in.readInt();
            }

            if(clientTimingAvailable){
                int length = in.readByte();
                clientTimingEvents = new ClientTimingEvent[length];
                for (int i = 0; i < length; i++) {
                    ClientTimingEvent event = new ClientTimingEvent("");
                    if (event.internalize(in)){
                        clientTimingEvents[i] = event;
                    }
                }
            }

            return true;
        }

        /**
         * Returns the amount of data send from client to server in bytes.
         * This method returns -1 if the size measurement was not enabled.
         * To enable it set the property xma.runtime.rpcMessureSize=true.
         */
        public int getClient2serverSize() {
            return client2serverSize;
        }

        /**
         * Returns the duration of the rpc in milliseconds
         */
        public int getDurationMilliSecs() {
            return durationMSecs_;
        }

        /**
         * Returns the amount of data send from the server to the client in bytes.
         * This method returns -1 if the size measurement was not enabled.
         * To enable it set the property xma.runtime.rpcMessureSize=true.
         */
        public int getServer2clientSize() {
            return server2clientSize;
        }

        /**
         * Tells if the last communication was sucessfully.
         */
        public boolean isSuccess() {
            return success_;
        }

        public ClientTimingEvent[] getClientTimingEvents() {
            return clientTimingEvents;
        }

        public void setClientTimingEvents(ClientTimingEvent[] clientTimingEvents) {
            this.clientTimingEvents = clientTimingEvents;
        }

//        public boolean isClientTimingAvailable() {
//            return clientTimingAvailable;
//        }
//
//        public void setClientTimingAvailable(boolean clientTimingAvailable) {
//            this.clientTimingAvailable = clientTimingAvailable;
//        }

    }

    /**
     * Returns the last client-measurement or null, if
     * there is no such measurement available.
     */
    public CallMeasurement getLastMeasurement () {
        return lastClientMeasurement_;
    }

    /**
     * Sets the instance variable lastClientMeasurement.
     */
    public void setLastMeasurement (CallMeasurement cm) {
        lastClientMeasurement_ = cm;
    }

//    public static void main(String[] args) {
//        CallMeasurement     cm = new CallMeasurement ();
//        cm.success_ = true;
//        cm.durationMSecs_ = 500001;
//        System.out.println (cm.getEncodedValue());
//        cm.setFromEncodedValue(cm.getEncodedValue());
//        System.out.println ("duration: " + cm.durationMSecs_);
//        System.out.println ("success: " + cm.success_);
//    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy