Wednesday, August 31, 2011

How to get back missed 3 buttons(Maximize/Minimize/Close) in ubntu 11.04

Ubuntu 11.04 is the most annoyed Ubuntu operating system i have ever found(OS should be there to help us not for bug us). This time with 11.04 you will see  3 buttons(Maximize/Minimize/Close) vanishs after some time.That was really annoyed after searching some time i was able to found how to fix it.
Here are the steps.
Go to system> administration > Synaptic Package manager
You will see following window.

Then select  compiz-decorator and tick it and then apply it.

So now go to command line and type following command

Then you will see those buttons come back.
Then you need to add this to start up applications.To do that do followings.

Goto preferences > Startup Applications
You will see following window and type there as shown in the below image

So thats it :)

Monday, August 29, 2011

How to get simple ubuntu 10 appearnce from 11.04

Did you messed up after new Ubuntu installation. Its really annoyed(with new side menu bar). i was able to fix this and get back my lovely ubntu UI. Here are the steps.
01. Type settings on search window(from menu search)
02. Go to login screen and click on it
You will see following window
Then unlock it by giving your password. Then select Ubuntu classic.yes you have done it. now you have to logout and re login. Thats it :)

Friday, August 26, 2011

How to Create WSO2 Stratos ESB proxy service and invoke by BlackBerry Mobile Client

This is very basic usage of ESB and you can do many things inside this proxy service(Calling few actual web services, mediate message, logging, ,message reformat). I used this example to just demonstrate how we can use ESB with BlackBerry client.
WSO2 Strstos
WSO2 Stratos is the most complete, enterprise-grade, open PaaS, with support for more core services than any other available PaaS today. The open nature of WSO2 Stratos makes it the perfect environment for hosting companies, ISVs and System Integrators to build and customize Industry-specific PaaS and SaaS platforms for vertical markets; for example, creating a Mobile PaaS for telecom companies.The WSO2 StratosLive Java PaaS, hosted by WSO2, enables developers to instantly provision and pay for just the middleware services they use.
Enterprises can use the WSO2 StratosLive to host business process flows between business partners as well as implement cloud-based services that access internal systems.Developers get all the benefits of the complete WSO2 Carbon enterprise middleware platform and the multi-tenant, elastic WSO2 Stratos cloud middleware platform without the hassles of setting up machines and middleware

WSO2 ESB is unique Enterprise Service Bus from the ground up relying on innovative Carbon technology to give you a smooth start-to-finish project experience you cannot find elsewhere.
Easy configuration through an intuitive graphical interface allows you to get started – and into production – much faster.
Lean, high-performance design conserves resources through maximum efficiency.
Built on the WSO2 Carbon OSGi platform: adding new capabilities as you need them is a snap.
In this post i will describe how to deploy a simple proxy service in stratoslive and how we can invoke it by BlackBerry mobile device. First we need to setup eclipse IDE(Which use widely in enterprise level to develop BlackBerry Applications) to develop BlackBerry Apps. In my previous post i have describe this topic clearly you will find it here.
First we will see how we can deploy simple proxy service with StratosLive.
First to . you can create new account freely.Then login to the system go to ESB home page. See the figure


Figure : Services Home WSO2 StratosLive
Then click on source view to edit configurations.
Figure : Edit window for edit source of Configuration
Typically the ESB is deployed between the actual client and a backend service implementation to mediate the message flow in between. Thus WSO2 ESB can accept a message on behalf of the actual service, perform authentication, validation, transformation, logging, routing based on the content etc. and then decide the destination target endpoint for the message and direct it to an actual service implementation.We have to write configuration for those operations. These configuration are written using the Synapse configuration language which is a simple and easy to learn domain specific language based on XML. It is always recommended to use the graphical wizards and tools provided in the WSO2 ESB management console to setup the mediation configuration, thus avoiding having to write XML configurations manually. But for this simple configuration we will use XML writing method. See following configuration.
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="">
    <registry provider="org.wso2.carbon.mediation.registry.WSO2Registry"/>
    <proxy name="EchoProxy" transports="https" startOnLoad="true" trace="disable">
        <target inSequence="response"/>
        <policy key="conf:/repository/axis2/service-groups/EchoProxy/services/EchoProxy/policies/UTOverTransport"/>
    <proxy name="loginproxy" transports="https http" startOnLoad="true" trace="disable">
        <target inSequence="main"/>
    <sequence name="response">
        <script language="js">mc.setPayloadXML(
            &lt;greeting&gt;Hello World&lt;/greeting&gt;
        <header name="To" action="remove"/>
        <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
        <property name="RESPONSE" value="true"/>
        <log level="full"/>
    <sequence name="fault">
        <log level="full"/>
    <sequence name="main">
There you will see EchoProxy which is use to set set XML Payload to response message.if you need you can do some thing more inside this proxy(Do Authentication check, send request to actual web service/data service and send response back).
Yo have to copy this configuration to your configuration and update
Next go to services and you will see deployed proxy service as follows


figure : Deployed services window to view Proxy Services Deployed

Then click on the service and you will see following window. There you can edit your service/ generate WSDL/ Try service etc... Then click on try it and test your service by sending request. you will see the response with greeting message

Figure : Service home window Edit and modify the service

Now we have created our proxy service successfully now we will see how we can invoke this by BlackBerry.First setup your Eclipse IDE using this guideline document.
Then download esb_client source code for here.Unzip it and open with eclipse ide.
You have to set your proxy service url properly in the code.for me it was"

In blackBerry mobile devices before send request to some url we have to append some part to it. It must contain [deviceside=true;apn=Apnkey]. When i developed my first application in 2009 i found simple solution for this.I was able to store some known apns with relative Mobile Network Code(MNC) and Mobile Country Code (MCC).
and retrive them when will see more information on MCC/MNC here[]. I have written separate post how to use that method, click here[] to view it. I used same method for this example.
Here we will do simple http get() to that proxy service and get greeting message. you will see very basic UI for service invocation.

Then build project and run it on blackberry Device simulator.
Go to downloads for your Mobile device.You will see SendT program click on it you will see the following window


Then Click on left button and press send request.Then you will see the status and response message as shown below
clip_image002[6]                 clip_image002[8]

so you can modify ESB configuration and client source code as you need for different kind of usages. if you need to test this program with actual device copy cod,jad or jar file to your mobile device using BlackBerry Desktop Software []. And install program to your device.

Source Code for BlackBerry Client:

package senddTpkg;

//@Auther  - MALALGODA S.R.B.(
//@Date    -2009/07/04
//@Project -Blackberry Mobile application 
//@Code      - Java Blackberry application to send Http request to WSO2 Stratos ESB  
//            proxy service
import java.util.Vector;


import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.RadioInfo;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class sendTCls extends UiApplication {

    public static void main(String[] args) {
        sendTCls theApp = new sendTCls();

    public sendTCls() {
        pushScreen(new UserInterfaceScreen());

final class UserInterfaceScreen extends MainScreen {
    String words;
    String apn;
    HorizontalFieldManager _fieldManagerTop;
    VerticalFieldManager _fieldManagerMiddle;
    HorizontalFieldManager _fieldManagerBottom;
    BitmapField _bitmap;
    Bitmap _canadaImage;
    LabelField _label;
    static BasicEditField _input;
    String _canadaCapital;
    int displayed = 0;
    private static final int IMAGE_SIZE = 2430;
    private byte[] data = new byte[IMAGE_SIZE];

    RichTextField rtf = new RichTextField("");

    public UserInterfaceScreen() {
        LabelField title = new LabelField("WSO2 ESB Test Service",
                LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
        _fieldManagerTop = new HorizontalFieldManager();
        _fieldManagerMiddle = new VerticalFieldManager();
        _fieldManagerBottom = new HorizontalFieldManager();
        add(new SeparatorField());
        add(new SeparatorField());
        _label = new LabelField(
                "This is WSO2 Stratos ESB Proxy service test program."
                        + " press the left menu and click on send request buttion then you will send"
                        + " request to Hellow Service. Response will show below.");
        FieldChangeListener listenerCanada = new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                displayed = 0;

    protected void makeMenu(Menu menu, int instance) {

    private MenuItem _changeCapital = new MenuItem("Sent Request", 110, 10) {
        public void run() {
            try {
                String mcc = Integer.toHexString(RadioInfo.getMCC(RadioInfo
                String mnc = Integer.toHexString(RadioInfo.getMNC(RadioInfo
                String responseStr = getHttpResponce1(""
                        + ";deviceside=true;apn="
                        + getTag(ReadFile(), mcc + "," + mnc));
            } catch (Exception e) {
                Dialog.alert("Error In connecting=" + e.toString());

    private MenuItem _close = new MenuItem("Close", 110, 10) {
        public void run() {

    public boolean onClose() {
        return true;


    public String ReadFile() {
        try {
            Class classs = Class.forName("senddTpkg.sendTCls");
            // Source Package neme and Class name
            InputStream is = classs.getResourceAsStream("/test.txt");
            byte[] data = new byte[is.available()];
  , 0, is.available());
            String c = new String(data);
            return c;
        } catch (Exception ioe) {
            return null;

    public static String getTagFromStringXML(String XML, String TagName) {
        try {
            String returnStr = "";
            String frontTag1 = "<" + TagName;
            String backTag1 = "=";
            String front = "<" + TagName + ">";
            String back = "";
            String[] arrayGet = splitToArr(XML, frontTag1);
            if (arrayGet.length > 0) {
                String[] arrayGet1 = splitToArr(arrayGet[1], back);
                return arrayGet1[0];
            arrayGet = splitToArr(XML, front);
            if (arrayGet.length > 0) {
                String[] arrayGet1 = splitToArr(arrayGet[1], back);
                return arrayGet1[0];

            return returnStr;
        } catch (Exception e) {
            return "";


    private static String[] splitToArr(String inString, String delimeter) {

        String[] retAr = new String[0];
        try {
            Vector vec = new Vector();
            int indexA = 0;
            int indexB = inString.indexOf(delimeter);

            while (indexB != -1) {
                if (indexB > indexA)
                    vec.addElement(new String(inString
                            .substring(indexA, indexB)));
                indexA = indexB + delimeter.length();
                indexB = inString.indexOf(delimeter, indexA);
            vec.addElement(new String(inString.substring(indexA, inString
            retAr = new String[vec.size()];
            int intIteration = vec.size();
            for (int i = 0; i < intIteration; i++) {
                retAr[i] = vec.elementAt(i).toString();
        } catch (Exception e) {

        return retAr;

    public static String getTag(String XML, String TagName) {
        try {
            String ans = "error";
            String front1 = "<" + TagName;
            String arrayGet = "=";
            String[] sssnew = split(XML, front1);
            if (sssnew.length > 1) {
                String back1 = null;
                String[] sss1new = split(sssnew[1], back1);
                if ((sss1new[0]).compareTo(" i:nil") < 1) {
                    ans = "";
                    return ans;
            String front = "<" + TagName + ">";
            String back = "";
            String[] sss = {};
            sss = split(XML, front);
            if (sssnew.length > 1) {
                String[] sss1 = {};
                sss1 = split(sss[1], back);
                ans = sss1[0];

            return ans;
        } catch (Exception e) {
            return "";


    private static String[] split(String inString, String delimeter) {

        String[] retAr = new String[0];
        try {
            Vector vec = new Vector();
            int indexA = 0;
            int indexB = inString.indexOf(delimeter);

            while (indexB != -1) {
                if (indexB > indexA)
                    vec.addElement(new String(inString
                            .substring(indexA, indexB)));
                indexA = indexB + delimeter.length();
                indexB = inString.indexOf(delimeter, indexA);
            vec.addElement(new String(inString.substring(indexA, inString
            retAr = new String[vec.size()];
            int intIteration = vec.size();
            for (int i = 0; i < intIteration; i++) {
                retAr[i] = vec.elementAt(i).toString();
        } catch (Exception e) {

        return retAr;

    public static String getHttpResponce1(String URL) {

        try {
            HttpConnection httpConnection = (HttpConnection) Connector
            InputStream inputStream = httpConnection.openInputStream();

            StringBuffer sb = new StringBuffer();
            int C;

            while (-1 != (C = {
                sb.append((char) C);

            return sb.toString();

        } catch (Exception e) {
            return "-1";
 common APN keys stored in test.txt file
<310,4> verizon
<310,38>     AT&T
 Download full source code

How to develop Application Software for BlackBerry Mobile Phones using Eclipse IDE

Download Eclipse from eclipse-jee-ganymede-SR2-win32 eclipse home site

Down load eclipse Blackberry plugging eJDE-4_6_1_27_Component from

Then update eclipse IDE to develop BlackBerry Software. Use the following instructions.

Unzip eclipse source. Then run eclipse.exe

Then go to help > Software Updates you will see following window


Then Click on add site button. You will see following window


Click on archive and point to the Blackberry eclipse plugging and select it.

Then click on selected item and click install.


At the end you may need to restart the eclipse.

Congratulations now you are ready to develop BlackBerry Applications. Happy Coding :)

Wednesday, August 24, 2011

How to configure usage agent advanced configuration for data publisher in WSO2 Stratos - Cloud computing


I have discussed how to do basic configurations related to Stratos usage agent on separate post.If you need to aware more about basic configurations click here. Here in this post i will discuss how to use fine tune parameters for usage agent. As i discussed previous post usage agent is responsible for data publishing. Normally this publishing do after some data accumulation. based on applied load we may need to configure this publishing. Main cause for this configuration change is we saw some unusual CPU usage when we publish data. Because we fixed the number of records and Execution time.

Previous implementation of usage agent runs in 5 min intervals and this causes sudden CPU usage increases due to large number of records we are summarizing and persisting. To solve this issue, We use task which runs forever(until server shutdown) and persist small number of records in short intervals. Number of records and time interval can be configured via a configuration file.

The newly introduced configuration file should be copied into CARBON_HOME/repository/conf/advanced directory. configuration file should be named as usage-throttling-agent-config.xml. Default values for configuration options as follows.

- Startup delay - 60 seconds
- Execution interval - 100 milli seconds
- Records per execution - 100

If file is not available usage agent will use above default values.those values are tested optimized values for public deployment with 5000 active tenants. you will see following entries in usage-throttling-agent-config.xml file.


You can change values and analyze the results.See the following diagram for better understand of CPU Usage due to large number of records. These results may change due to the traffic to your servers and number of tenants.


Figure : Fixed time Publishing with more than 1 second delay VS Configured publishing with 100 milli second publish time and record limitation is 100

What we can Thottle in WSO2 Stratos(1.5.1 Release) Cloud Environment - Tomcat server Based throttling

What we can Throttle in WSO2 Stratos(1.5.1 Release) Cloud Environment - Tomcat server Based throttling
In wso2 stratos throttling we will be able to throttle few parameters related to service and bandwidth usages. In this post i will briefly describe the parameters that we can throttle with wso2 stratos 1.5.1 release.

01. Registry Resource Volume
    For Registry usages we will be able to throttle following parameters
     Registry incoming data actions - put/ importResource/ restore
     Registry outgoing data actions - dump/ get
02. Service Bandwidth
     Throttle the service incoming and out going message sizes to the  Web Services(Axis2 Service/  JAX-WS Service/ Jar Service/ Jar Service) hosted at wso2 Stratos
     Application Server.For each incoming and outgoing messages throttling agent check whether that tenant is exceeded incoming and outgoing bandwidths. then only that allow users to invoke services.We can use two parameters(incoming/ outgoing) related to service bandwidth for throttling rules. For this throttling agent use Handler extended from AbstractHandler and that handler act as a listener for service invocations.
     Service incoming action
     Service outgoing action
03. webApp bandwidth
     Throttle the service incoming and out going based on message sizes to the Web Application Archive (.war) files hosted in Application server.For this webApp throttling we use valve extended from CarbonTomcatValve.That valve act as a listener and check whether tenant allow it or not. Here we can use two parameters(incoming/ outgoing) related to webApp bandwidth for throttling rules.
     webApp incoming action
     webApp outgoing action
04. User Count
     Number of users per given tenant.

So all together we will be able to throttle 7 actions as follows for given tenant.
01. Registry incoming data actions - put/ importResource/ restore
02. Registry outgoing data actions - dump/ get
03. Service incoming action
04. Service outgoing action
05. webApp incoming action
06. webApp outgoing action
07. User count per tenant

Tuesday, August 23, 2011

How to configure usage in Cloud Environment using Stratos – User Guide


Here in this post i hope to discuss how to set up wso2 Stratos with usage metering. In this post i will mainly focus on how to setup and fine tuning parameters for usage metering. If you need more information on usage metering and throttling see my previous post from here. First you need to understand few terms

Usage Agent – Component which measures resource usage(use listening technology) and store it (Publish it to other server to record it).This usage metering process use some advanced listening technologies to avoid slows down or blocks entire process.

As an example let say some web service(hosted by is invoked by some client. so this invocation takes 100kb service bandwidth. So usage agent will store this entry this tenant( got service bandwidth of 100kb at this time

In order to usage metering work properly we have to do few configurations in stratos services.Usage metering is based on simple concept that is listening. There few listeners to listen the actions performed by user and those listeners  report what they heard to some other server(Business Activity Monitor). And those record will be store there in some ordered format.We will first identify those listeners.

01. Registry Listener – This listener will listen to each and every action related to registry(get, put, add, delete etc.. ) Then store them as bandwidth usage.

02. User Add Listener – This listener is there to listen user adding actions and keep updating user count of tenants

03. Service/Web App bandwidth listener – This listener is mainly listen to incoming and out going message sizes and store those data as bandwidth usages. For this listener usage agent use tomcat valve data statics.

See following Diagram for overview of usage metering process


Figure : Overview Of Usage Metering Process

Data publisher – Data publisher is available inside the usage agent.When usage agent starts Data publisher creates the connection to the end point of BAM. In order to do this we have to provide Server URL of BAM instance running on.Let see how we do this configuration.This usage metering process happens at each and every stratos service so usage agent is available in every service of stratos. You can see carbon.xml file in every service inside the repository/conf folder. In carbon.xml file you will see following entry


You have to give correct BAM server URL with /services part. you will see this URL when bam server starts up.Then only usage agent will be able to publish data to BAM.

Then these metered usage data will be available for any decision making process. Users(Tenants) can view their usage and super administrator can can view all tenants usages. Throttling manager use those records  to check whether users exceeded their allowed limits or not.

There are some other important parameters to configure for publisher.Those parameters are used configure to how we accumulate, how often we publish them to Bam kind of things. Since those configurations are developer level changes i will discuss it on separate post.

How to configure throttling in Cloud Environment using WSO2 Stratos – Users Guide


Here in this post i hope to discuss how to set up wso2 Stratos with throttling. In this post i will mainly focus on how to setup and fine tuning parameters for throttling and usage metering. If you need more information on usage metering and throttling see my previous post from here. First you need to understand few terms.If you need to understand more on throttling on Cloud environment please refer the this post on Amila Maharachchi’s Blog 

Throttling Manager – Manage, Evaluate what users can do and cannot do based on their subscription plans and their current usage.

Throttling Agent – This component detects user actions and allow them to do it or block it based on the Validation information generated by throttling manager

Usage Plan- There 4 types of usage plans available at WSO2 services. According to usage plan users will allow different volume of resources and service usage.(Demo/SMB/Professional/Enterprise). You will see more information on usage plans available at WSO2 StratosLive from here.

So we have to configure few things in order to work properly

01. How often throttling manager executes. Throttling manager periodically evaluates the tenants usage of resources(Service/webApp bandwidth, Registry usage, User count) and check it with their maximum allowed limit. After that process it store this validation data on registry. Here we can configure when start this evaluation process and how often we do this. To configure this we have to change configuration file( throttling-config.xml ). Before that you have to set up WSO2 Stratos properly(Manager/ IS/ any other services). Then go to inside of manager/repository/conf folder. There you will see throttling-config.xml file and that file has following entries.


<parameter name="interval">60</parameter>

<!--minutes = If This set to negative(-) value then throttling manager excecution will disable-->

<parameter name="delay">15</parameter>


interval parameter is there to specify the time frequency(in minutes) of executing throttling manager.According to this configuration it says execute rules after 60 minutes. With this configuration Manager will detect any excess usage of resources within one hour. after each 60 minutes It will call Data services and get current usage of each and every tenant and updating their actions(What they are allow to do or what they are not allowed)

delay parameter is there to define when to start first rule execution.According to this configuration server will run first throttling rule execution after 15 minutes time of server started.

15 minutes and 60 minutes are recommended values. But if you need much more accuracy you can reduce that interval value(But its advisable use some value more than 3 minutes otherwise it will causes to performance drop). And also remember reducing this time always causes to higher CPU Usage. If you don't need to run throttling manager you can disable it by setting negative value for  interval parameter. If you plan to run manager instance without throttling you can use this configuration.

02. How other Services allow to use Throttling manager. In order to  use throttling manager by services we have to modify configuration in each and every services that we use(Appserver/ IS/ BAM/ DSS etc..). Those services need to access throttling manager at WSO2 Stratos Manager. In that case we have to modify throttling-agent-config.xml file. That file has following content.

<throttlingAgentConfig xmlns="">



<parameter name="userName">admin</parameter>

<parameter name="password">admin</parameter>



managerServiceUrl – is the URL of manager running on. Manager services URL. you will see this URL when manager starts up at terminal. by default this will set to local host.

userName – Here we have to specify Stratos Manager server super admin user name (By default it will be admin)

password  Here we have to specify Stratos Manager server super admin password (By default this will be admin)

This configuration is used by other services except manager to run the throttling rules at manager. As an example when we try to add new user identity server will call manager throttling manager to report new user adding. Otherwise within one hour of throttling rule execution time tenant user may add any number of users. To avoid such misuses we use this technique.

03. How to write throttling rules. For each usage plans we have to specify the upper limit of resource and service usage. And then if any user try to go beyond that limit throttling agent will stop that action immediately. As example if Demo account is allow to add 1 users we have to specify it in throttling rules. You will see throttling-rules.drl file inside manager/repository/conf. At first time manager takes rules from that file and store it in registry. Only super admin user for stratos manager allow to change throttling rules. If you logged in as super Admin you will see throttling menu. by clicking it you will see throttling rules editor window where you can write rules. There is other blog post on how to write throttling rules if you are interested please refer it .

Monday, August 22, 2011

Usage metering and throttling in cloud computing - introduction for Users/Developers

Here in this post i will describe how to use usage metering and throttling in cloud environment. For this post i will use WSO2 stratos which is a complete Platform-as-a-Service for private and public clouds. Lets see how we do usage metering and throttling in stratos.

What is WSO2 Stratos ?

WSO2 Stratos is a complete SOA and developer platform offered as a self-service, multi-tenant, elastic runtime for private and public cloud infrastructures. What that means is that our complete SOA platform - now enhanced with Tomcat and Webapp support - is available as a  "cloud native" runtime that you can either use on the Web (yes - you can try it out right now), on Amazon VPC, or on your own internal private cloud based on Ubuntu Enterprise Cloud, Eucalyptus and (coming soon) vmWare vSphere. It is a complete Platform-as-a-Service for private and public clouds.

Download stratos source and more documents available at

Post on how to build stratos 1.5.1 source available at

Sign up for a free account at  stratos private cloud

What is Tenant ?

In stratos we used term tenant. What is tenant? it’s like an organization ( and it may few users (like departments within organization). There is administrator for each tenant and others are users. Administrator can allow users to use services and he is the person who governs the entire system for tenant. See following diagram for understanding tenant.


Figure: Tenant and its users

Why we need Usage and Throttling ?

WSO2 stratos throttling component is the only one tomcat server based throttling module. And WSO2 Stratos 1.5.1 provides many new features like metering throttling and billing. So with WSO2 Stratos you will be able to measure, throttle and bill the server usage. Its really important to have reliable billing/ throttling model for cooperate service providers. Stratos 1.5.1 provides complete solution for web services with pricing model. So we will look at this usage and throttling model in detail. So this process has 2 main actions.

1. Before user perform some action we will check whether he is allow to do it or not(Ex adding new service/ service invocation).

2. After performing some action we keep it record ( tenant used 100kb service Bandwidrh)

See following diagram for overview of usage and throttling.


Figure : Usage And Throttling Overview

Usage Agent

Usage agent is responsible for measure parameters and publishes them into Business Activity monitor server(Where we store data and monitor). for each and every tenants agent measure some important parameters related to their usage of bandwidth and resources(Service/webApp bandwidth, Registry usage, User count). This usage metering process use some advanced listening technologies to avoid slows down or blocks entire process.

As an example let say some web service hosted by try to invoke by some client so this invocation takes 100kb service bandwidth. So we will store this entry this tenant( got service bandwidth of 100kb at this time

Usage Summery generator

Summery generator component responsible for summarize captured data. And after collecting raw data we do sorting and summarization periodically and store those records in database. Those records are available per hourly, monthly, daily, quarterly and annually.

As example after hour we will put above 100kb entry to hourly table. Then at the end of the day it will go to daily table with corresponding day of month.

Throttling Manager

Throttling is used to avoid excess usage of resources and bandwidth. Throttling manager periodically check the usage records(The data captured by above mentioned usage agent) available and evaluate throttling rules and define set of actions for each and every tenant. These actions are contain what tenants can do what cannot do what are the error messages that we have to show them. Those rules are written in drools. Drools is a business rule management system (BRMS) with a forward chaining inference based rules engine, more correctly known as a production rule system, using an enhanced implementation of the Rete algorithm. Using a rules engine can lower an application's maintenance and extensibility costs by reducing the complexity of components that implement complex business logic. So inside WSO2 stratos throttling component is use drools for throttling configurations and provide user interface to change rules in easier way. After evaluating Throttling rules for each tenant we will store the validation information(What tenant allow to do and what should block) in registry with tenant ID

Example :Throttling manager check the monthly data available in monthly service bandwidth table and check the Drool correspond to that tenant(Drool specify the service bandwidth allow to this user and actions when limit exceeding). If that user didn’t exceed limit it will put entry to registry saying is allow to service invocation else it will put entry saying not allowed.

Throttling Agent

Throttling agent is acting as a supervising agent who check the actions taken by users. Basically this will check registry entry for given tenant (Put by throttling manager). To achieve higher performance throttling agent use in memory implementation. It will take copy of registry entries and keep it cached. So reading validation information from cache is much faster than reading registry.

As an example When some tenant/users try to invoke web service this agent check the corresponding registry entry for user weather he is allow to do this or not. If he can do agent will allow to do it otherwise it will prompt message to user saying the issue.

How to build wso2 stratos 1.5.1 from the source

WSO2 Stratos is the most complete, enterprise-grade, open PaaS, with support for more core services than any other available PaaS today.
WSO2 Stratos provides the core cloud services and essential building blocks for example federated identity and single sign-on, data-as-a-service and messaging-as-a-service and more, required for developing SaaS and cloud applications.
Here below i will describe how to build stratos 1.5.1 from source.
You will find more information on wso2 stratos main page from this Link
Download stratos source from the hosted location
$ wget

unzip content into some given location

go inside the extracted folder and start build it on line
stratos151src@sr2:~/stratos151src$mvn clean install

if it fails due to some reason(may be due to on line repo problems) follow the below guide lines.
In order to build carbon products we need to build axis2 first if that is not available at online repos

Then build dependencies
And continue build in following order with given commands
stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/dependencies$ mvn clean install

stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/orbit$ mvn clean install -Dmaven.test.skip=true

stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/service-stubs$ mvn clean install -Dmaven.test.skip=true
You must build carbon core with tests so use following command
stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/core$ mvn clean install

Before build components we have to little change for stratos pom.xml file. Due to the error in pom file location of
org.wso2.carbon.tenant.dispatcher folder.

So lets see how we can do that modification
Go to stratos folder as follows
stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/components/stratos$ vi pom.xml

Do the following change
replace line

Then build components
stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/components$mvn clean install

Then we have to build features
stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/features$mvn clean install

Then we have to build products and services
stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/products$ ls
as  bam  bps  brs  carbon  cep  css  dss  esb  greg  gs  is  lb  manager  mb  ms  pom.xml  wsf

here you will see available products inside products folder
if you need to build appserver product and service use the following command. same way you can do this for other products as well

stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/products/as/4.1.1$mvn clean install
Then built packs will be available on following location

Friday, August 19, 2011

How to get date time and device id from BlackBerry device programatically Java

These are very basic things in mobile development. but its very useful to keep them documented.First we will see how to get date time
public static String  getCurrentDateTime()
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss aaa");
    return dateFormat.format(new Date(System.currentTimeMillis()));


Then we will see how to get device id from device 

Thursday, August 18, 2011

How to download entire web site using wget command in ubuntu/Linux

If you need to download entire web site( let say some series of tutorial or doc series) you can do this easily with wget command. its easy to use this command for ubuntu/linux users.Use following command with the url that you need.

$ wget --recursive --no-clobber --page-requisites --html-extension --convert-links --restrict-file-names=windows --no-parent

How to encrypt and decrypt data using Advanced Encryption Standard(AES) Java BlackBerry Pragramming

sample code provides information on how to encrypt and decrypt data using the most common symmetric key algorithm, Advanced Encryption Standard

package com.DataStore;

import net.rim.device.api.crypto.AESDecryptorEngine;
import net.rim.device.api.crypto.AESEncryptorEngine;
import net.rim.device.api.crypto.AESKey;
import net.rim.device.api.crypto.BlockDecryptor;
import net.rim.device.api.crypto.BlockEncryptor;
import net.rim.device.api.crypto.CryptoTokenException;
import net.rim.device.api.crypto.CryptoUnsupportedOperationException;
import net.rim.device.api.crypto.PKCS5FormatterEngine;
import net.rim.device.api.crypto.PKCS5UnformatterEngine;
import net.rim.device.api.crypto.RandomSource;
import net.rim.device.api.crypto.SHA1Digest;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.util.Arrays;
import net.rim.device.api.util.DataBuffer;

public class CryptoRSA {

    private String keyMessage = "Data sent between a BlackBerry device and the BlackBerry Enterprise Server is encrypted using Triple DES (Date Encryption Standard) or AES (Advanced Encrption Standard). This is performed automatically and does not require application implementation to use it.There are cases where encrypting data can be required, such as secure communication with an external application using the BlackBerry Mobile Data Server. Communication between the BlackBerry and BlackBerry Mobile Data Server would be automatically encrypted but communication between the BlackBerry Mobile Data Server and an application server would not unless implemented in the BlackBerry application.";

    public byte[] encrypt(byte[] data ) throws CryptoException, IOException, CryptoTokenException, CryptoUnsupportedOperationException
    AESKey key = new AESKey( keyMessage.getBytes() );
    // Now, we want to encrypt the data.
    // First, create the encryptor engine that we use for the actual
    AESEncryptorEngine engine = new AESEncryptorEngine( key );

    // Since we cannot guarantee that the data will be of an equal block
    // length we want to use a padding engine (PKCS5 in this case).
    PKCS5FormatterEngine fengine = new PKCS5FormatterEngine( engine );

    // Create a BlockEncryptor to hide the engine details away.
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    BlockEncryptor encryptor = new BlockEncryptor( fengine, output );

    // Now we need to do is write our data to the output stream.
    // But before doing so, let's calculate a hash on the data as well.
    // A digest provides a one way hash function to map a large amount
    // of data to a unique 20 byte value (in the case of SHA1).
    SHA1Digest digest = new SHA1Digest();
    digest.update( data );
    byte[] hash = digest.getDigest();
    // Now, write out all of the data and the hash to ensure that the
    // data was not modified in transit.
    encryptor.write( data );
    encryptor.write( hash );

    // Now, the encrypted data is sitting in the ByteArrayOutputStream.
    // We simply want to retrieve it.
    return output.toByteArray();

    public byte[] decrypt(byte[] ciphertext ) throws CryptoException, IOException, CryptoTokenException, CryptoUnsupportedOperationException
    // First, create the AESKey again.
    AESKey key = new AESKey( keyMessage.getBytes() );

    // Now, create the decryptor engine.
    AESDecryptorEngine engine = new AESDecryptorEngine( key );
    // Since we cannot guarantee that the data will be of an equal block length
    // we want to use a padding engine (PKCS5 in this case).
    PKCS5UnformatterEngine uengine = new PKCS5UnformatterEngine( engine );

    // Create the BlockDecryptor to hide the decryption details away.
    ByteArrayInputStream input = new ByteArrayInputStream( ciphertext );
    BlockDecryptor decryptor = new BlockDecryptor( uengine, input );

    // Now, read in the data. Remember that the last bytes represent
    // the SHA1 hash of the decrypted data.
    byte[] temp = new byte[ 100 ];
    DataBuffer buffer = new DataBuffer();

    for( ;; ) {
        int bytesRead = temp );
        buffer.write( temp, 0, bytesRead );

        if( bytesRead < 100 ) {
        // We ran out of data.

    byte[] plaintextAndHash = buffer.getArray();
    int plaintextLength = plaintextAndHash.length - SHA1Digest.DIGEST_LENGTH;
    byte[] plaintext = new byte[ plaintextLength ];

    System.arraycopy( plaintextAndHash, 0, plaintext, 0, plaintextLength );
    return plaintext;

Tuesday, August 16, 2011

How to use PersistentStore to store objects in BlackBerry Java programming

Here in this post we will see how to store customer data using PersistentStore.
In my DataObject class used to store customer data. it has 2 parameters customer ID and some string property it may be name address or any other parameter. Also you can change those parameters according to your requirements. we are suing vector to store those pairs in runtime. Hope this will useful for you
package com.DataStore;

import java.util.Vector;
import net.rim.device.api.util.Persistable;

public final class DataObject implements Persistable

    private Vector elements;
    public static final int CLIENT_ID = 0;

    public DataObject()
    elements = new Vector(1);
    int capacity = elements.capacity();
    for (int i = 0; i < capacity; ++i)
        elements.addElement(new String(""));

     * @param id
     * @return String
     * String getElement(int id)
    public String getElement(int id)
    return (String) elements.elementAt(id);

    public void setElement(int id, String value)
    elements.setElementAt(value, id);

package com.DataStore;

import java.util.Vector;

import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
public class DataHandler {

    private static Vector data;
    private static PersistentObject store;

    store =    PersistentStore.getPersistentObject(1);

    synchronized (store) {
        if (store.getContents() == null) {
        store.setContents(new Vector());

    data = (Vector) store.getContents();


     * @param info
     * static void saveObject(DataObject info)
    public static void saveObject(DataObject info)
    synchronized (store) {

     * @return String
     * static String getClient()
    public static String getClient() {

    synchronized (store) {
        data = (Vector) store.getContents();
        if (!data.isEmpty()) {
        DataObject info = (DataObject) data.lastElement();
        return info.getElement(DataObject.CLIENT_ID);
        //If data is empty here we return empty string
        return "";

Wednesday, August 10, 2011

Simplest way to Display Pregressing bar - BlackBerry Java programming

You can create the instance of the  ProgressBar and you can pass the time out and display messages to progressing bar.

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.GaugeField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.DialogFieldManager;
import net.rim.device.api.ui.container.PopupScreen;

public class ProgressBar extends Thread 
    private int maximum, timeout;
    private boolean useful;
    private PopupScreen popup;
    private GaugeField gaugeField;
    public ProgressBar(String title, int maximum, int timeout)
        this.maximum = maximum;
        this.timeout = timeout;
        DialogFieldManager manager = new DialogFieldManager();
        popup = new PopupScreen(manager);
        gaugeField = new GaugeField(null, 1, maximum, 1, GaugeField.NO_TEXT);
        manager.addCustomField(new LabelField(title));

    public void run() 
        useful = true;
        UiApplication.getUiApplication().invokeLater(new Runnable() 
            public void run() 

        int iterations = 0;
        while (useful)
            catch (Exception e) 
            if (++iterations > maximum)
                useful =false;
                UiApplication.getUiApplication().invokeLater(new Runnable() 
                    public void run() 
                        Dialog.alert("Successfully  Completed");
                iterations = 1;

        if (popup.isDisplayed()) 
            UiApplication.getUiApplication().invokeLater(new Runnable() 
                public void run() 

    public synchronized void remove() 
        useful = false;

How to do POSTRequest (in a secured way) in BlackBerry Mobile device

If you need to do a secured post operation with server we can use Authentication token from the server side that obtained when we log into system. And do the server side implementation to check the authentication token per each request coming from the user(client). Its better if we can delete that token periodically. And ask user to re login if that key is expired.Here in this post i will show how to send request with the authentication token. Remember that we need to set APN unless we configured device properly. Here is the separate post on how to Get APN key without worrying about the service provider that we used(Which contains most of service providers in united states and Canada). If you operator not available there add it following format. Later i will add server side code also.

Here is the example

Here is the code for process post request to server

     * @param serviceUrl
     * @param authToken
     * @param requestData
     * @return String
     * @throws IOException
     * @throws ServerException
     * static String processPOSTRequest(String serviceUrl,String authToken, String requestData)
    public static String processPOSTRequest(String serviceUrl,String authToken, String requestData) throws IOException,ServerException {

    HttpConnection httpConnection = null;
    OutputStream streamOutput = null;
    InputStream inputStream = null;
    StringBuffer strBuffer = new StringBuffer();
    String response = "";

    try {
 //Here getAPN() method gives you APN key for particular network operator
 //I have written separate blog post on getting APN key for any operator
        httpConnection = (HttpConnection), Connector.READ_WRITE);
        httpConnection.setRequestProperty("Content-Length", Integer.toString(requestData.length()));
        httpConnection.setRequestProperty("Content-Type", "text/xml");
        if (authToken.length() > 0) {
                .getBytes("UTF-8"), 0, authToken
                .getBytes("UTF-8").length, false, false));
        streamOutput = httpConnection.openOutputStream();

        streamOutput.write(requestData.getBytes(), 0, requestData

        int responseCode = httpConnection.getResponseCode();

        if (responseCode != 200) {
        ServerException getErrorExceptions = new ServerException(
            responseCode, httpConnection.getResponseMessage());
        throw getErrorExceptions;

        inputStream = httpConnection.openInputStream();

        int character;

        while (-1 != (character = {
        strBuffer.append((char) character);

        response =  strBuffer.toString();

    } finally {
        try {
        } catch (Exception e) {
        //not related to user error if this exception happens due to
        //unavailability then connection assigns to null and then implicitly removes it
        httpConnection = null;
        inputStream = null;
        streamOutput = null;

    return response;