Index Changes
ESB Console Home

Test Performance Measurement Service In Java

package org.glassfish.extended.management.sample.impl.performance;

import com.sun.esb.management.common.ManagementRemoteException;
import com.sun.esb.management.common.data.ComponentStatisticsData;
import com.sun.esb.management.common.data.helper.ComponentStatisticsDataReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.openmbean.CompositeData;
import javax.xml.parsers.ParserConfigurationException;
import org.glassfish.openesb.extended.management.api.administration.ExtendedAdministrationService;
import org.glassfish.openesb.extended.management.api.performance.PerformanceData;
import org.glassfish.openesb.extended.management.api.performance.ExtendedPerformanceMeasurementService;
import org.glassfish.openesb.extended.management.client.ExtendedManagementClient;
import org.glassfish.openesb.extended.management.client.ExtendedManagementClientFactory;
import javax.management.openmbean.TabularData;
import org.glassfish.openesb.extended.management.api.runtime.ExtendedRuntimeManagementService;
import org.glassfish.openesb.extended.management.common.ExtendedManagementRemoteException;
import org.glassfish.openesb.extended.management.common.jbi.JBIComponentInfo;
import org.glassfish.openesb.extended.management.common.jbi.ServiceAssemblyInfo;
import org.glassfish.openesb.extended.management.common.jbi.ServiceUnitInfo;
import org.glassfish.openesb.management.ServerConnectionFactory;
import org.xml.sax.SAXException;

/**
 * @author graj
 *
 */
public class TestPerformanceMeasurementServiceImpl {

    /**
     * 
     */
    public TestPerformanceMeasurementServiceImpl() {
        // TODO Auto-generated constructor stub
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        String hostName = ServerConnectionFactory.LOCALHOST,
                userName = ServerConnectionFactory.ADMIN_USERNAME,
                password = ServerConnectionFactory.ADMINADMIN_PASSWORD;
        int portNumber = ServerConnectionFactory.RMI_ADMIN_PORT;
        String targetName = ServerConnectionFactory.SERVER_TARGET;

        String engine = null;
        String binding = null;
        String library = null;
        String serviceAssemblyName = null;
        String unit = null;
        String targetInstanceName = null;

        engine = "sun-bpel-engine";
        binding = "sun-file-binding";
//        binding = "sun-http-binding";
        library = "sun-wsdl-library";
//        serviceAssemblyName = "SynchronousSampleApplication";
        unit = "SynchronousSampleApplication-SynchronousSample";
        serviceAssemblyName = "m2app";

        String anEndpoint = "Service{{http://www.sun.com/jbi/qos/redelivery}sun-http-binding}Endpoint{redeliveryLoopback}";
        ExtendedManagementClient client = null;
        boolean isJBIRuntimeEnabled = false;
        String[] consumingEndpoints = null;
        String[] provisioningEndpoints = null;
        ExtendedAdministrationService administrationService = null;
        ExtendedPerformanceMeasurementService profilingService = null;
        ExtendedRuntimeManagementService runtimeManagementService = null;
        List<ServiceAssemblyInfo> assemblyList = null;
        String performanceMap = null;
        Map<String /* Category */, PerformanceData> profilingDataMap = null;
        TabularData tabData = null;
        Map<String /* instanceName */, ComponentStatisticsData> instanceToComponentStatisticsMap = null;
        String listXML = "";
        List<JBIComponentInfo> componentList = null;
        String statisticsXML = "";
        try {
            client = ExtendedManagementClientFactory.getInstance(hostName, portNumber, userName, password);
        } catch (ExtendedManagementRemoteException ex) {
            Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        administrationService = client.getService(ExtendedAdministrationService.class);
        try {
            isJBIRuntimeEnabled = administrationService.isJBIRuntimeEnabled();
        } catch (ManagementRemoteException ex) {
            Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (true == isJBIRuntimeEnabled) {
            System.out.println("The JBI Framework is Enabled");

            System.out.println("List of Consuming Endpoints");
            try {
                consumingEndpoints = administrationService.getConsumingEndpoints(binding, targetName);
            } catch (ManagementRemoteException ex) {
                Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            }
            if (consumingEndpoints != null) {
                for (String endpoint : consumingEndpoints) {
                    System.out.println("  " + endpoint);
                }
            }

            System.out.println("List of Provisioning Endpoints");
            try {
                provisioningEndpoints = administrationService.getProvisioningEndpoints(binding, targetName);
            } catch (ManagementRemoteException ex) {
                Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            }
            if (provisioningEndpoints != null) {
                for (String endpoint : provisioningEndpoints) {
                    System.out.println("  " + endpoint);
                }
            }

            profilingService = client.getService(ExtendedPerformanceMeasurementService.class);
            runtimeManagementService = client.getService(ExtendedRuntimeManagementService.class);

            if ((runtimeManagementService != null) && (profilingService != null)) {
                try {
                    System.out.println("======== LIST BINDING COMPONENTS ============ ");
                    listXML = runtimeManagementService.listBindingComponents(targetName);
                    componentList = JBIComponentInfo.readFromXmlText(listXML);
                    for (JBIComponentInfo element : componentList) {
                        System.out.println("Component Name: " + element.getName());
                        System.out.println("Component Description: " + element.getDescription());
                        System.out.println("Component Type: " + element.getType());
                        System.out.println("Component State: " + element.getState());
                        System.out.println("");
                        try {
                            statisticsXML = profilingService.getComponentStatistics(element.getName(), targetName);
                            try {
                                instanceToComponentStatisticsMap = ComponentStatisticsDataReader.parseFromXMLData(statisticsXML);
                                if (instanceToComponentStatisticsMap != null) {
                                    for (String instanceName : instanceToComponentStatisticsMap.keySet()) {
                                        System.out.println(instanceToComponentStatisticsMap.get(instanceName).getDisplayString());
                                    }
                                }
                            } catch (MalformedURLException ex) {
                                Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (ParserConfigurationException ex) {
                                Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (SAXException ex) {
                                Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (URISyntaxException ex) {
                                Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (IOException ex) {
                                Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        } catch (ManagementRemoteException ex) {
                            Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        if (consumingEndpoints == null) {
                            try {
                                tabData = profilingService.getConsumingEndpointsForComponentAsTabularData(element.getName(), targetName);
                                if (tabData != null) {
                                    Collection<CompositeData> data = (Collection<CompositeData>) tabData.values();
                                    if (data != null) {
                                        for (CompositeData datum : data) {
                                            if (datum != null) {
                                                String instanceName = (String) datum.get("InstanceName");
                                                String[] endpoints = (String[]) datum.get("Endpoints");
                                                if (endpoints != null) {
                                                    consumingEndpoints = endpoints;
                                                    System.out.println("Instance: " + instanceName);
                                                    for (String theEndpoint : endpoints) {
                                                        System.out.println("========== Consuming ===============>" + theEndpoint);

                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            } catch (ManagementRemoteException ex) {
                                Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                        if (consumingEndpoints != null) {
                            for (String endpoint : consumingEndpoints) {
                                System.out.println("  Statistics for: " + endpoint);
                                try {
                                    //profilingDataMap = profilingService.getPerformanceInstrumentationMeasurement(binding, endpoint, targetName, targetInstanceName);
                                    performanceMap = profilingService.getPerformanceInstrumentationMeasurement(element.getName(), endpoint, targetName, targetInstanceName);
                                } catch (ManagementRemoteException ex) {
                                    Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                                }
                            }
                        } else {
                            System.out.println("  Statistics for: " + anEndpoint);
                            try {
                                //profilingDataMap = profilingService.getPerformanceInstrumentationMeasurement(binding, endpoint, targetName, targetInstanceName);
                                performanceMap = profilingService.getPerformanceInstrumentationMeasurement(element.getName(), anEndpoint, targetName, targetInstanceName);
                            } catch (ManagementRemoteException ex) {
                                Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }


                        if (provisioningEndpoints == null) {
                            try {
                                tabData = profilingService.getProvidingEndpointsForComponentAsTabularData(element.getName(), targetName);
                                if (tabData != null) {
                                    Collection<CompositeData> data = (Collection<CompositeData>) tabData.values();
                                    if (data != null) {
                                        for (CompositeData datum : data) {
                                            if (datum != null) {
                                                String instanceName = (String) datum.get("InstanceName");
                                                String[] endpoints = (String[]) datum.get("Endpoints");
                                                if (endpoints != null) {
                                                    provisioningEndpoints = endpoints;
                                                    System.out.println("Instance: " + instanceName);
                                                    for (String theEndpoint : endpoints) {
                                                        System.out.println("============ Provisioning =============>" + theEndpoint);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            } catch (ManagementRemoteException ex) {
                                Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                        if (provisioningEndpoints != null) {
                            for (String endpoint : provisioningEndpoints) {
                                System.out.println("  Statistics for: " + endpoint);
                                try {
                                    performanceMap = profilingService.getPerformanceInstrumentationMeasurement(element.getName(), endpoint, targetName, targetInstanceName);
                                } catch (ManagementRemoteException ex) {
                                    Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                                }
                            }
                        }
                        provisioningEndpoints = null;
                        consumingEndpoints = null;

                    }
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    System.out.println("======== LIST SERVICE ENGINES ============ ");
                    listXML = runtimeManagementService.listServiceEngines(targetName);
                    componentList = JBIComponentInfo.readFromXmlText(listXML);
                    for (JBIComponentInfo element : componentList) {
                        System.out.println("Component Name: " + element.getName());
                        System.out.println("Component Description: " + element.getDescription());
                        System.out.println("Component Type: " + element.getType());
                        System.out.println("Component State: " + element.getState());
                        System.out.println("");
                        statisticsXML = profilingService.getComponentStatistics(element.getName(), targetName);
                        try {
                            instanceToComponentStatisticsMap = ComponentStatisticsDataReader.parseFromXMLData(statisticsXML);
                            if (instanceToComponentStatisticsMap != null) {
                                for (String instanceName : instanceToComponentStatisticsMap.keySet()) {
                                    System.out.println(instanceToComponentStatisticsMap.get(instanceName).getDisplayString());
                                }
                            }
                        } catch (MalformedURLException ex) {
                            Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (ParserConfigurationException ex) {
                            Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (SAXException ex) {
                            Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (URISyntaxException ex) {
                            Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (IOException ex) {
                            Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        if (consumingEndpoints == null) {
                            try {
                                tabData = profilingService.getConsumingEndpointsForComponentAsTabularData(element.getName(), targetName);
                                if (tabData != null) {
                                    Collection<CompositeData> data = (Collection<CompositeData>) tabData.values();
                                    if (data != null) {
                                        for (CompositeData datum : data) {
                                            if (datum != null) {
                                                String instanceName = (String) datum.get("InstanceName");
                                                String[] endpoints = (String[]) datum.get("Endpoints");
                                                if (endpoints != null) {
                                                    consumingEndpoints = endpoints;
                                                    System.out.println("Instance: " + instanceName);
                                                    for (String theEndpoint : endpoints) {
                                                        System.out.println("========== Consuming ===============>" + theEndpoint);

                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            } catch (ManagementRemoteException ex) {
                                Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                        if (consumingEndpoints != null) {
                            for (String endpoint : consumingEndpoints) {
                                System.out.println("  Statistics for: " + endpoint);
                                try {
                                    performanceMap = profilingService.getPerformanceInstrumentationMeasurement(element.getName(), endpoint, targetName, targetInstanceName);
                                } catch (ManagementRemoteException ex) {
                                    Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                                }
                            }
                        } else {
                            System.out.println("  Statistics for: " + anEndpoint);
                            try {
                                //profilingDataMap = profilingService.getPerformanceInstrumentationMeasurement(binding, endpoint, targetName, targetInstanceName);
                                performanceMap = profilingService.getPerformanceInstrumentationMeasurement(element.getName(), anEndpoint, targetName, targetInstanceName);
                            } catch (ManagementRemoteException ex) {
                                Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }


                        if (provisioningEndpoints == null) {
                            try {
                                tabData = profilingService.getProvidingEndpointsForComponentAsTabularData(element.getName(), targetName);
                                if (tabData != null) {
                                    Collection<CompositeData> data = (Collection<CompositeData>) tabData.values();
                                    if (data != null) {
                                        for (CompositeData datum : data) {
                                            if (datum != null) {
                                                String instanceName = (String) datum.get("InstanceName");
                                                String[] endpoints = (String[]) datum.get("Endpoints");
                                                if (endpoints != null) {
                                                    provisioningEndpoints = endpoints;
                                                    System.out.println("Instance: " + instanceName);
                                                    for (String theEndpoint : endpoints) {
                                                        System.out.println("============ Provisioning =============>" + theEndpoint);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            } catch (ManagementRemoteException ex) {
                                Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                        if (provisioningEndpoints != null) {
                            for (String endpoint : provisioningEndpoints) {
                                System.out.println("  Statistics for: " + endpoint);
                                try {
                                    performanceMap = profilingService.getPerformanceInstrumentationMeasurement(element.getName(), endpoint, targetName, targetInstanceName);
                                } catch (ManagementRemoteException ex) {
                                    Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                                }
                            }
                        }
                        provisioningEndpoints = null;
                        consumingEndpoints = null;
                    }
                } catch (ManagementRemoteException ex) {
                    Logger.getLogger(TestPerformanceMeasurementServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {
                System.out.println("The JBI Framework is NOT Enabled");
            }
        }
    }
}
///





Number of visits: 2

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This page (revision-1) was last changed on 05-Oct-09 07:15 AM, -0700 by Gopalan Suresh Raj