Thursday 11 July 2013

10g BPEL retrieve statistics using custom java code

How to retrieve statistics details from the 10g BPEL Administration console by using custom java code.

Java Code :

import com.collaxa.common.util.Statistics;

import java.util.Properties;

import com.collaxa.xml.XMLHelper;

import com.oracle.bpel.client.BPELProcessId;
import com.oracle.bpel.client.IBPELDomainHandle;
import com.oracle.bpel.client.IBPELProcessHandle;
import com.oracle.bpel.client.IInstanceHandle;
import com.oracle.bpel.client.Locator;
import com.oracle.bpel.client.NormalizedMessage;
import com.oracle.bpel.client.delivery.IDeliveryService;
import com.collaxa.cube.fe.util.FormatUtils;

import com.oracle.bpel.client.util.WhereCondition;

import com.oracle.bpel.client.util.WhereConditionHelper;

import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.io.*;

public class GetBPELStats {
    public static final String DATE_FORMAT_NOW = "dd.MM.yyyy HH:mm:ss:SSS";
   
    public GetBPELStats() {
    }

    public static void main(String[] args) {

        if ((args != null) & (args.length != 0)) {
            System.out.println("Usage: GetBPELStats");
            System.exit(1);
        } else {
            try {
                // properties in the classpath
                Properties props = new java.util.Properties();

                // read the properties file
                java.net.URL url =
                    ClassLoader.getSystemResource("context.properties");
                props.load(url.openStream());
                //System.out.println(props);

                String bpeldomain = props.getProperty("bpeldomain");
                if (bpeldomain == null) {
                    System.out.println("BPEL domain not specified in context.properties, assuming 'default'");
                    bpeldomain = "default";
                }

                String bpelpassword = props.getProperty("bpelpassword");
                if (bpelpassword == null) {
                    System.out.println("BPEL password not specified in context.properties, assuming ********");
                    bpeldomain = "welcome1";
                }

                // get a connection to the server
                Locator locator = new Locator(bpeldomain, bpelpassword, props);

                IBPELDomainHandle domain = locator.lookupDomain();
               
                System.out.println("GetBPELStats for SOA10g ");
                Calendar cal = Calendar.getInstance();
                SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
                System.out.println("Date: " + sdf.format(cal.getTime()));
               
               
                System.out.println("===> Successfully connected to domain " +
                                   bpeldomain);
               
                Statistics[] asyncStats = domain.getAsyncStatistics();
               
                System.out.println("------------------------------");
                System.out.println("Async BPEL Domain Statistics:");
                for(int i = 0; i < asyncStats.length; i++)
                {
                    Statistics stat = asyncStats[i];
                    System.out.println((new StringBuilder()).append("<key name=\"").append(stat.getKey()).append("\"><stats count=\"").append(stat.getCount()).append("\" min=\"").append(stat.getMin()).append("\" max=\"").append(stat.getMax()).append("\" average=\"").append(stat.getAvg()).append("\"/></key>").toString());
                }
                if (asyncStats.length==0)
                {
                    System.out.println("There are no Async BPEL Domain Statistics:");
                }
                System.out.println("------------------------------");

               
                Statistics[] syncStats = domain.getSyncStatistics();
                System.out.println("------------------------------");
                System.out.println("Sync BPEL Domain Statistics:");
                for(int i = 0; i < syncStats.length; i++)
                {
                    Statistics stat = syncStats[i];
                    System.out.println((new StringBuilder()).append("<key name=\"").append(stat.getKey()).append("\"><stats count=\"").append(stat.getCount()).append("\" min=\"").append(stat.getMin()).append("\" max=\"").append(stat.getMax()).append("\" average=\"").append(stat.getAvg()).append("\"/></key>").toString());
               

                }
                if (syncStats.length==0)
                {
                    System.out.println("There are no Sync BPEL Domain Statistics:");
                }
                System.out.println("------------------------------");


                Statistics[] requestStats = domain.getRequestStatistics();
                System.out.println("------------------------------");
                System.out.println("BPEL Engine Requests Statistics:");
                for(int i = 0; i < requestStats.length; i++)
                {
                    Statistics stat = requestStats[i];
                    System.out.println((new StringBuilder()).append("<key name=\"").append(stat.getKey()).append("\"><stats count=\"").append(stat.getCount()).append("\" min=\"").append(stat.getMin()).append("\" max=\"").append(stat.getMax()).append("\" average=\"").append(stat.getAvg()).append("\"/></key>").toString());
                }
                if (requestStats.length==0)
                {
                    System.out.println("There are no PEL Engine Requests Statistics:");
                }
                System.out.println("------------------------------");


                //To clear the statistics from memory
                //domain.clearStatistics();


            } catch (Exception e) {
                System.out.println("Exception in GetBPELStats: " + e);
                e.printStackTrace();
            }
        }

    }

}



EXPLANATION:
------------------
The above class relies on BPELDomainHandle object and obtains the statistics using the
following API calls:
domain.getAsyncStatistics   : Async BPEL Domain Statistics
domain.getSyncStatistics    : Sync BPEL Domain Statistics
domain.getRequestStatistics : Engine Requests Statistics

The statistics are built and  stored in the memory using HashMaps.
The engine relies on the data in the HashMaps and calculates the statistics
at runtime.
When we clear the statistics , the data in the HashMaps are cleared.
To clear the statistics from memory using Java Code , we can use
-> domain.clearStatistics();

The "Statistics" page(jsp) in BPEL Administration page , uses the same API's
as GetBPELStats.java .In addition the JSP page formats the statistics are
presents them as a Tree(hierarchy) structure.

No comments:

Post a Comment