Tuesday, January 18, 2011

Java 4,5,6.. What next???? Python.. Scala.. Erlang...

For a Java Fan it becomes a lot easier day by day  to lost in the overgrowing languages in the JVM world, that includes Groovy, Jython and a host of other languages with Groovy being the Flag bearer. However with the stagnancy of Java ( i m saying this because the next java version is slated to be released in Summer of 2012) and  with the introduction of other languages, it seems a good choice/time for a java developer to taste other languages. Some of the major languages that a java developer i think one should follow on is.

  • PYTHON: It seems to be a great language by syntax and looks like a relative of 'C' language. The Current version of Python 2.7 is seems to be much popular than 3x version. Because of its ability to run on multiple platforms that includes (Linux, JVM, .Net) i think this should be the first choice of a developer. The emergence of Various Development Frameworks like WxPython, Django ( best for web app development) provide a strong reason to go for this language. In addition we also have to consider Google's Bet on python, ( Google really invest heavily on python with Guido Van Rassum on this board, ya the same person who created python). I think before trying out the same java feature ever and ever again, one should see the new angle python brought into development e.g. Virtual enviroment, Easy_install, Pip etc. The central repository pypi definitely helps the developer to get an understanding of all the libraries with their documentation a lot.
    Some important links are:
  • ERLANG: Wanna go for a concurrent languages, that ERLANG seems to be extremely fit to the concurrent world. Developed by Ericssion in 1985 and open sourced in 2000 this language serves as a basis for one of biggest platforms on the world, that includes FACEBOOK CHAT and facebook page rendering things. The Syntax is seems to be an complex one, but with the time it turns out to do the thing in a much simpler way. It also plays a great part in the NoSql movement with CouchDB being created in it. So give ERLANG a try, if concurrency seems to exist anywhere near you.
    In addition this also support Web development, Nitrogen is the framework here, that one needs to look into.
  • GROOVY: The ability to call itself Java++ and with the recent web development in GRAILS framework ( somewhat similiar to Rails framwork) will make this language an excellent choice for Java developers, since the language fundaments and syntax seems a lot similar to java. ( Relationship can be considered Java -> Groovy as C -> C++). since you can use all the java libraries can be used in GROOVY, so a java developer can find him/her on the best side of river & safe at home.
  • SCALA: The mixture of OOP & FP ( functional programming) and its concurrent features makes this languages an excellent bread earning language of future. Since scala provide the concurrency in terms of "ACTORS" ( ya inherited from ERLANG)  and with web development frameworks like LIFT, SINATRA it can be termed as the replacement of java on to the JVM in the next coming years. Like Groovy you can use all existing java libraries, however the learning curve is little steep because of the complexity of the language. But as per my observation and as per the blogosphere world this language can fit extremely well in the Java world.
    Even as per a blog the Groovy developer says "if he knows that Scala exists and is about to come then he would never had developed Groovy". This statement itself says a lot about Scala.
    Some important links are:
Personally out of above 4 i will mark the languages in this order Python -> Scala -> Erlang unless you have a special inclination or have a special requirement.
So go ahead, give it a try and find out to do the thing differently rather then repeating yourself each and every time. SO remember, remain DRY ( dont repeat yourself).
          If you want to know about the Good Books in any of the above, please write me in the comments section or mail me. Surely, will love to tell anyone.
        Sorry, for the Typos..

Monday, January 10, 2011

No Nonsense - Apache + Python + Django installation gude

Python + Apache Integration:
  In order to work python with apache, we need to take care of the python version with the apache version. if we are using python version <= 2.5 then we have to use mod_python instead of using mod_wsgi. MOD_WSGI used to work with python 2.6 and python 2.7 version.

This post will simply presents a guide to install Django on the Apache 2.2 version with python 2.7
For that we need to follow the steps in the order:

  •  Download the Mod_wsgi.so from the following link http://code.google.com/p/modwsgi/ as per your apache and python version.
  •  Place the ".so" apache module file in the Modules folder of apache installation.
  • Modify the Httpd.conf file to include the following line in it. (make sure you rename the so file to mod_wsgi, otherwise use the complete name in the below listing)
    LoadModule wsgi_module modules/mod_wsgi.so   
  • Now create a sample Django project called "Sample" in ("C:\djangoprojects") directory and create multiple apps in it. The directory structure of Sample is given below.  (dont care about apache_django.py we will discuss this filelater on )

  • Now create a simple app "Users" in the this django project "c:\djangoprojects\sample", the directory contents are as below
  • Make sure you are able to run the Project using the inbuilt Django server. by using following URL (http://localhost:8000/Sample/Users)
  • Now Create a file called "apache_django.wsgi" in the Sample project folder. This file basically provides an bridge between the APACHE and the Django. This provides the apache with the wsgi handler for the Python Web based application.
    Paste the following contents in this file.
    # apache django settings.
    import os
    import sys
    os.environ['DJANGO_SETTINGS_MODULE'] = 'Sample.settings'
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()
    where, Sample.settings refers to the Settings.py file of Django present in the Sample project folder as shown above.
  • Now in the apache Httpd.conf file paste the following lines at the bottom
    WSGIScriptAlias /Django "C:/djnagoProjects/Sample/apache_django.wsgi"
    <Directory "C:/djnagoProjects/Sample">
    Order allow,deny
    Allow from all
    Where, the first line will specify that the whole application will be accessbile at (http://localhost/Django) and the individual module will be available at (http://localhost/Django/Users).
    And the rest of the lines are simply allow  you to allow the access rights over the directory.
  • That's all, just make sure you restart apache and that's the complete magic is being done through Mod_wsgi bridge. Now access the path (http://localhost/Django) and the result is

    Please write back, in case i made an error , or u face any problems....
    Happy Pythoning.......

Sunday, January 9, 2011

Monitoring Your server - java

During development and testing times we required to continously monitor our server for a number of resons:

  1. Find out amount of memory taken
  2. Find out the number of classes loaded in memory
  3. Checking out the different types of memory being used by our program ( Heap, Permgen etc. )
  4. To get a know how of all the SQL commands issued by the application
  5. and a number of things.... that a developer had to take care.
This can be achieved using a number of open source tools available freely on our blogosphere. Two of the most popular are
  1. Java Melody ( Awesome one , Java Melody )
  2. Lambda Probe ( http://www.lambdaprobe.org/d/index.htm )
 both are excellent tools and how to use them is being covered in the online documentation of both of the projects. Both of them comes as a war file, so we can directly deploy it to the server and monitor the details of our requests, sessions, memory and lots of things.
 however There is an advantage that i found of Melody over Probe is that melody can be used to cover up a single application on to the server i.e. if you have an WAR deployed on to the server, you can find the details only in context of the same application, and not to the complete server. In addition Melody is an active project while Probe seems to be an dead one.
Both of them has the unique advantage of running over multiple servers because both of them supports the Server API specification, so we just need to use some filters which are being present in the assoicated Jar Files and make the available to our application.
As I am started using Java melody i will post more of the details regarding it soon. 
Here are some of the attached details being thrown by both of them. I had used Melody within a particular application while Probe to cover up the whole server.
Happy Monitoring........