Sunday, December 5, 2010

Plotting graphs for scientific papers with gnuplot

I was writing our first IEEE grade paper few days back. It was first written using MS word as my text editor. Now that it got selected to be published on the IEEE explore, we thought of preparing a latex based paper for final publication.
One of the major proplem was the image quality of some of the figures. I tackled that using the popular open source vector grphics editor - > Inkscape. With Inkscape you can prepare some high quality images.
The next problem was with the graph quality, which had been drawn using MS excel. The solution was to use GNUPlot tool. It is a nice tool especially crafted for complex scientific drawings. I used it as a simple data plotter. But it is capable of plotting scientific functions and many more things.
So here is how to plot a simple graph if have the plotting data available with you. Installing the program is pretty trivial. ;)  

Preparing the data file : plot.dat
you have to prepare a data file, that to be used by the gnuplot. Data should be delimited by a common delimiter. The default delimiter is the 'space'. Here is what a sample data file would look like.

writing gnuplot script : plot.script
it is possible to use gnuplot tool in the interactive mode. But is is often useful to store your command as a script file so that you can call the script file over and over again.

set xlabel "number of nodes" font "Times-New Roman,16"
set ylabel "speedup ratio" font "Times-New Roman,16"
set xrange [0:24]
set yrange [0:25]
set xtics out  0,3,24
set mxtics 3
set ytics in  0,5,25
set mytics 5
set key 9,22
plot 'plot.dat' using 1:2 title 'actual speedup' with linespoints , \
'plot.dat' using 1:3 title 'ideal speedup' with lines

The most of the above commands are self explanatory, such as xlabel, xrange, etc.
set xtics instruct the program to set the labeling number after each 3 units. The set mxtics instructs to place subdivisions within the each unit.
Generating the graph
open up a terminal and type gnuplot. assuming you have already installed gnuplot in your machine, you should see the interactive gnuplot terminal. Give the following command to prepare the the graph using our script file. 

gnuplot> call './plot.script'   

This should spawn up a new window containing our graph. :)


Gnuplot uses the concept of drivers to output its generated graphs. Here I have used the output of default driver in the above figure. By changing the terminal driver we can print directly to a printer, to a command shell or to a postscript file. When you are preparing the the graphs for a latex document you got to specify your output terminal as the postscript (ps). The generated .ps file, can be later converted in to ps2pdf utility in UNIX. The converted .pdf image can be inserted in to your latex document and can be compiled with pdfLatex.
I have attached the plot.dat file and the plot.script file I used to generate the above plot.  

How to consume admin services in WSO2 Carbon with your own front end.

WSO2 Carbon is a OSGI based middle ware platform which powers the WSO2 products such as WSO2 Application server, WSO2 ESB, etc. In other words, Carbon provides core functionalities such as user management, feature management, registry services, etc which are essential part of any product. Product themselves add their unique behaviour via specific features (bundles).
The Carbon platform consists of a front-end and a back-end. In its most simplest deployment scenario you can deploy any carbon based WSO2 product  in a single web container such as Apache Tomacat. But its architecture allows you to deploy its front end as a separate web-app. This facility is immensely useful if you are working multiple instances of the product. Instead of having a separate front end for each and every instance you can use only one front-end to control all the deployed back-ends. The figure below gives a high level view of the carbon platform.

During a feature development for the WSO2 Carbon, I wanted to give some customized web services calls to the back end server. Since the existing management console does not have the functionality that I'm testing I had to write some code to give my own web service calls. Nothing new; just web services calls. Here I'm documenting my effort.

Running the WSO2 carbon in Standalone mode.
Download the binary distribution of Carbon from the project home, unzip it to your local file system. Root directory of the unzipped carbon directory is the CARBON_HOME. Open up a shell and within the $CARBON_HOME/bin , run the server as,

$> ./

Log in to the system by giving the username and password (default being admin for both). You should see the bare bones carbon platform with the user manager and the feature manager.
Carbon admin services
The Carbon admin services are not visible via the Carbon management console. You can access the service description of the admin services if you know the admin service. Here I'm accessing the URL assuming that the default https port in carbon (9443).

> https://localhost:9443/services/AuthenticationAdmin?wsdl


Before accessing any other Admin services we have to get the credentials by authenticating ourselves via the Admin service. Then we can use the token to authenticate ourselves while accessing other admin services.
Generating code for the admin services
we have to generate the client stubs to access the back end web-services. You can write your own web services clients using axis2 client API, but the wsdl2java tool hides all the complexity from the user and present you with a proxy to the back end service.
The stub generation happens during the project build process within the maven pom files. It uses the maven ant run plug in to execute the wsdl2java tool.

Accessing the Admin service and authenticating ourselves
we should provide the back end server URL , client trust store details in order to log in to the back end server via a web services. We use the session cookie returned by the service to authenticate ourselves in the following service calls.

1 // setting the system properties for
2         AuthenticationAdminServiceClient.setSystemProperties(SampleConstants.CLIENT_TRUST_STORE_PATH,
3                 SampleConstants.KEY_STORE_TYPE, SampleConstants.KEY_STORE_PASSWORD );
4         AuthenticationAdminServiceClient.init(authenticationAdminURL);
5         System.out.println("retrieving the admin cookie from the logged in session....");
6         adminCookie = AuthenticationAdminServiceClient.login(SampleConstants.HOST_NAME,
7                 SampleConstants.USER_NAME, SampleConstants.PASSWORD);

Accessing the Provisioning service and getting the list of installed features.
Then during the provisioning stub invocation we have to give the retrieved admin cookie with the its service URL. View the ProvisioningAdminService service descriptor by pointing your browser to: 

> https://localhost:9443/services/ProvisioningAdminService?wsdl

1 // initializing the provisioning admin client  using the cookie we got from the authentication client.
2         ProvisioningAdminServiceClient.init(provisioningAdmingServiceURL, adminCookie);
3         FeatureWrapper[] featureWrapper = ProvisioningAdminServiceClient.getInstalledFeatures();
4         System.out.println(" the installed feature list...");
5         for(FeatureWrapper fw :featureWrapper){
6             // getting the names of installed features..
7             System.out.println(fw.getWrappedFeature().getFeatureName() + "- -" + 
8                     fw.getWrappedFeature().getFeatureDescription());
9         }

Things to note
  • we have to provide our client with Java key store files found under resources folder, inside CARBON_HOME.
  • I have saved WSDL in the local file system, for code generation.
  • The path the client trust-store is hard coded in the file
The code I used to test the behaviour is attached with this blog post. Since it uses maven it should not be hard to create a IDE specific project files from the maven pom.xml files. :)

The Carbon architecture allows you to control the server back end with your own front end. This can be a web-console, standalone java-app, etc. Carbon is the base platform for all the wso2 server products. Hence the demonstrated approach hold true for any carbon based wso2 product.

Download the code for the carbon simple front end.

Sunday, November 21, 2010

My final year project

My University life ended about two months ago soon after the final year exams. But last week we managed to present a research paper 'BISSA: Empowering Web gadgjet Communication using Tuple Space' at the  Super Computing conference (SC10), New Orleans under the workshop Gateway Computing Environments (GCE10).  

This is the first time I'm blogging about my final year project. Hence I would like to give a small overview of the project.

Project Title: BISSA: Disatrubuted & Scalable Tuple Space
Description : Our goal was to build a highly scalable distributed tuple space implementaion. We used Peer to Peer as our distributed paradigm & implementead the tuple space on top of a Distributed hash table. We used Pastry as our DHT. Further we implemented a in memory tuple space for browser applications, which exposes a JavaScript API. The in-browser tuple space was packaged as a Shindig feature, so that a browser gadjet can make use of the BISSA in browser tuple space, simply by declaring the dependency. The tight integration between the in-browser tuple space & the P2P tuple space, allows browser gadjets to co-ordinate & communicate through the  P2P space. If you find this description interesting ;) you should check out our project web site & the project blog for further details. :) 

The driving force behind this project was our two mentors Dr. Sanjiva Weerawarana & Dr. Srinath Perera. They are the most awesome mentors you can ever think of. Dr. Sanjiva planted the initial idea in our mind & mentored us through out the project. If not for Dr. Srinath Perera we would have not published our paper in an international conference. Lase but not least I would like to thank our internal mentor Dr. Gihan Dias & Our Department head Mrs. Visaka Nanayakkara for all the guidance & support given through out the project.

All in all, I had a chance of working with an amazing set of people in my project group : Charith Wickramarachchi, Udayanga Wickramasinghe, Dualanjanie Sumanasena, and I beleive that we have completed most of the milestones of our project with satisfactory results. 

Wednesday, September 15, 2010

WSO2Con 2010

WSO2 is well-known for its SOA enabling middle-ware stack. They are the only product vendor to have middle-ware stack based on a component based model (based on OSGI framework). Now they have move their products in to the cloud, enabling the users to make use of already set-up platform as a service. The best part is, all these products are open-source (Apache 2.0 license)

WSO2 organized their first ever con, today(14&15 September 2010). This is one among many events they have organized to celebrate their 5 th birthday. It was full of speeches/discussions from the pioneers in XML/web-services, such as James Clark. In summary, the conference was a great success & I'm looking forward to next years conference as well. 

Thursday, May 6, 2010

Johny Mnemonic & the PKC

Weeks ago our security professor gave us a yet another assignment. The assignment was to implement the Johny Mnemonic[1] using public-private key cryptography. I got the idea wrong & tried to simulate the Johnny Mnemonic behavior in a computer program, while the assignment was to discuss the scenario, pitfalls, etc.
So here I'm putting it as a blog post so that i feel better about my wasted time ;). In this program I simply,

  • Generate a RSA key pair using the Java key generator library & save it in a two seperate files named public.key & private.key.
  • Encrypt a plain text file using the RSA cipher using the generated public key stored in the public.key file
  • Store the cipher data in a file named JohnnyMnemonic.brain
  • Decrypt the cipher data using the private key that was saved in the private.key file and present it to the user.
Even though this is pretty much simple as you see it , this is the very essence of public key infrastructure (PKI)[2].I have provided the Java code[3] that implements the above task. The code it self is self explanatory i guess.

[1] William Gibson, Johnny Mnemonic, Harper-Collins, 1996.
[3] Java code

Wednesday, April 14, 2010

What if ???

I found this very interesting cartton by Dave Walker.  :D

cartoon from
Cartoon by Dave Walker. Find more cartoons you can freely re-use on your blog at We Blog Cartoons.

How to ignore version control meta files when grepping????

So you came across the same problem ha!!!.
When you are working with a sufficiently large project it is very essential to search through your code repository. Integrated development environments such as intellijIDEA (my favorite ;-) ) provides searching as a integrated functionality.
But if you are in to C/C++ developing on UNIIX platform your favorite editor going to be vim right? So every now & then you have to search through the repository in order to find the code snippet that you are after. 'grep' is the obvious answer. If your code repository under source control you have to make sure that you avoid those files when you are searching. To search a specific text using 'grep', you have to tell it to search recursively,ignore certain file types, etc.

Now ack-grep is the solution for this sort of situation. It is heavily customized for day to day code searching operations. By default,

  •  it searches recursively from the top level directory.
  •  identifies & ignore almost all the version control meta files.
  •  highlight the search word within the results.
  •  give the number & occurring file of the pattern.
  •  It identifies the file types (weather it is a Java source file or C++ source file) 

So you only have to do:
$>ack-grep 'pattern you want to search'

Here is a simple usage of the tool in one of my source repositories;

In order to install it in Ubuntu, just do a sudo apt-get install ack-grep. This is a very nice tool & i like it......  :) 

Wednesday, April 7, 2010

so you want to learn Maven ???

Maven is the current trend among Java community. No surprises, as maven is a full project life-cycle management tool. The beauty of maven is, it standardizes all the project related activities. Where the sources should go, where the test resources should reside, etc. 
Once you learn how to use it, you will be able to work with any Java project that uses maven. The core part of maven only deals with parsing & manipulating XML s. The core of the maven is a platform which provides services to the plugins. The plugins takes care of the specific tasks. As an example the compiler plugin knows that it has to compile the sources under src/main/Java.
I myself did not pay much attention to maven at the beginning. I used to find a way around by referring to some one else's pom.xml . But then I understood that i cant get away with this tool.
So I  learnt it. Here are some valuable resources to learn maven. 

The site has a wealth of resources for learning maven. It is easy to get lost in the site though. The quick start guides are really good.The place is the premier place to learn about different maven plugins.
  • The Maven by Example : book  

There is a book by Oreilly called Maven definitive guide. May be this book is bit outdated as well. The guys at Sonatype has divided this book in to two parts. The "Maven by Example" is a great place to learn maven(my personnel recommendation :)  ) It covers the basic design of maven platform & it is more example oriented. so you better start with that .....

  • The maven complete Reference: book

If you are planning to go deep in to the maven world, this is the book. 

happy coding!!!!

Monday, March 8, 2010

Blowing in the Wind ....

During my O/L literature studies there was this poem (it was under the poems section) called "Blowing in the Wind" by Bob Dylan. Our teachers were good at explaining the meanings, social messages, etc that are given by those poems, since those are the exam topics.But when it comes to reciting poems, it was like a paragraph reading.

Recently when I was surfing the web(without a specific goal ) I found this video with the title, "Blowing in the Wind" & honestly I did not expect it to be this good. It was amazing !!!!. Had I know that this song is this beautiful, I would have love the English literature subject a little bit more.

I enjoyed this song very much, check it out........
(note that the original version of this song is by Bob Dylan. But I prefer this version by Katie Melua)