Sunday, November 13, 2011

Installing Io on Snow Leopard

Started on Seven Languages in Seven Weeks . Interesting set of 7 languages. Y'day reached Io - Day One. Had to do some googling around to get Io working on OS X.

In case you intend to do the same, here is the gist of the steps required to get going

  • Download Io source from git-repo
sudo git clone git://github.com/stevedekorte/io.git
  • Next step is to run the build.sh file in the cloned git  io directory. You might get the following error
~/software/io/libs/iovm/source/IoObject_inline.h:322: error: ‘always_inline’ function could not be inlined in call to ‘IoObject_rawGetSlot_’: recursive inlining

  • You need to modify the file  ~/software/io/libs/basekit/source/Common_inline.h change
#define NS_INLINE static __inline__ __attribute__((always_inline)) 
in the section #if defined(__APPLE__)  to
#define NS_INLINE static inline

        Friday, April 15, 2011

        Trying REBOL

        REBOL was the language I wanted to explore. Today I thought of writing a timezone converter application using REBOL.

        The application should be able to convert time from Indian timezone to Munich and Boston timezone. This conversion is related to my current project.

        With this weird requirement, I decided to use the most weird way to convert time. I decided to use the timeanddate.com timezone converter to do the conversion. As a result, the application has to make an HTTP GET call to this link and parse the resulting web page to find the converted time.

        Summarizing the Approach:
        1. Write a REBOL UI application that takes the Indian time as input
        2. On click of Convert, makes an HTTP call to the website with input given by the user.
        3. Parse the resulting web page and find the converted time.
        4. Show the converted time on the UI !!

        Here is the REBOL code for the application.
        This is a REBOL code for timezone convertor

        REBOL
        [
        Title: "Timezone Convertor IN to BOS & MUN"
        Author: "Srikanth Seshadri"
        ]

        t-time: to-string now/time

        time-get: func [inp-time tz] [
        page: reform [
        "http://www.timeanddate.com/worldclock/converted.html?hour="inp-time/hour"&min="inp-time/minute"&sec="inp-time/second"&p1=438&p2="tz]
        tzurl: to-url page
        tz-text: load/markup tzurl
        zone-found: false tg-time: now
        foreach item tz-text [
        if all [string? item zone-found ] [ tg-time: item break]
        if all [string? item any[ find item "(U.S.A" find item "(Germ"] ] [zone-found: true]
        ]
        tg-time
        ]

        gui: layout [
        backdrop effect [gradient 0x1 white]
        across
        h3 "Timezone Converter IN -> BOS & MUN" black return
        lab "Indian Time"
        t-time: field t-time 60x24 return
        tab
        button "Convert Time" [
        inp-time: (to-time t-time/text)
        if inp-time
        [
        boslbl/text: reform ["Time in Boston: " time-get inp-time 43]
        munlbl/text: reform ["Time in Munich: " time-get inp-time 83]
        show boslbl
        show munlbl
        ]
        ] keycode [#"^m"] return
        boslbl: h4 "[---------------------------------------------------------------------]" return
        munlbl: h4 "[---------------------------------------------------------------------]" return
        ]
        view center-face gui

        and the output

        This is most strange way to do timezone conversion, but the learnings and development was fun; all the effort was worth it!

        Monday, September 06, 2010

        World War II + India + Java

        While exploring Java timezone related API, it was a surprise to me that during the World War II, India(being colony of England) had Daylight Saving Time !

        This timezone was in effect from 1-Sept-1942 to 15-Oct-1945. Interestingly, this DST is supported by Java date time API.

        DateFormat indiaDtFmt = new SimpleDateFormat("dd/MM/yyyy HH'h'mm");
        DateFormat gmtDtFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        indiaDtFmt.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));
        gmtDtFmt.setTimeZone(TimeZone.getTimeZone("GMT"));

        Date worldWarIIDate = indiaDtFmt.parse("02/02/1944 06h30");
        Date nonWorldWarIIDate = indiaDtFmt.parse("02/02/2006 06h30");

        System.err.println(gmtDtFmt.format(worldWarIIDate) +" GMT");
        System.err.println(gmtDtFmt.format(nonWorldWarIIDate) +" GMT");

        The above code produces the following output.

        1944-02-02 00:00:00 GMT
        2006-02-02 01:00:00 GMT

        So the during the World War II, India was in the timezone +4.30 GMT compared to the normal timezone of +5.30 GMT.

        This also mean the horoscopes of the people born in India during the World War II need to take this DST into consideration. These people include celebrities like Ilaiyaraaja,Azim Premji,Amitabh Bachchan etc.

        Obviously this well known to Astrologers.Here is one of the links for war-time correction for horoscopes. Another link for war time correction across the world.




        Saturday, July 31, 2010

        Auto Fare Converter


        New Auto fare in Bangalore is in effect from Aug 1, 2010. But, Autos have been given 2 month time period to change their meters.

        As a result, commuters are expected to know the fare conversion from old to new. Either trust the Auto Driver or have a print of the fare conversion table published.

        So I quickly wrote a mobile application to do the conversion. I wrote 2 versions, one android version and other Java ME (MIDP 2.0) application.




        Here are the links to the application installables





        Application Usage:
        1. Enter the current fare in the meter.
        2. Click Convert button.
        3. The amount you need to pay, the new fare, will be shown.


        Monday, July 26, 2010

        BMTC Bus Ticket Cost Calculation

        In a recent travel through BMTC bus to my office, I was involved in a big fight between another software engineer and the bus conductor on - how the ticket price was calculated? The software engineer did not know Kannada and the bus conductor could explain in the English. I served as the translator in that heated argument :)... here is the info how the ticket price is calculated.

        Note: The calculation is performed by the ticketing machine given to the bus conductor so the conductor cannot cheat you!

        BMTC divides the routes into stages. Following is the 'Fare Table' of BMTC Bus No 45. You can get the 'Fare Table' for your route from the conductor....Please Ask!













        FARE TABLE-010
        StageNameFare
        1KAMAKYA0.00
        2KATTRIGUPPE5.00
        3HOSAKERE HALLI9.00
        4BANK COLONY10.00
        5GANESH BHAVAN13.00
        6CHAMARAJPET15.00
        7GOODS ROAD16.00
        8KBS16.00


        Now the stage you climb the bus is the Stage 1 for you and of course the stage you get off is the last stage for you. Lets see the following examples of fare calculation with the previous assumption.

        Fare from

        • KAMAKYA to KBS = Stage 8 - Stage 0 = 8 Stages crossed = Rs 16
        • BANK COLONY to GOODS Road = Stage 7 - Stage 4 = 3 Stages Crossed = Rs 9
        • GOODS ROAD to KBS = Stage 8 - Stage 7 = 1 Stage crossed = Rs 5
        Algorithmically,


        List stageList=[KAMKYA...KBS]
        List fareList=[0..16]
        int start= stageList.indexOf[YOUR START STAGE]
        int end = stageList.indexOf[YOUR END STAGE]
        Fare= fareList[end-start]

        Hope the calculation is clear!

        Sunday, May 30, 2010

        Reading Java Concurrency

        The j.u.c package added to Java in 1.5 introduced me to the world of Concurrency research itself. Somehow i never thought of looking to this package beyond Executors class.

        Here is the study plan for that worked for me...
        1. Locks, Conditions And Fairness
        2. Understanding the Java Memory Model and its fix by JSR 133
        3. Happens-Before and volatile.
        4. LL/SC, CAS concepts
        5. Atomic package
        6. Concurrent Data Structures & Synchronizers
        7. Executors,Futures and other threading concepts.
        People & Forums:
        1. Articles by Brian Goetz, Doug Lea
        2. Java concurrency Interest group.

        Two useful books:
        1. Concurrent Programming In Java by Doug Lea.
        2. Java Concurrency in Practice By Brian Goetz

        Sunday, January 31, 2010

        rmToMp3.pl

        Here is the perl script to convert .rm files to .mp3 format on linux. Needed this script since my DVD player cannot play .rm files. Script needs the following software to work
        1. Perl
        2. mplayer
        3. lame
        4. wget
        The script can download rm or ram files and then process the download .rm files to produce the .mp3 file.
        #!/usr/bin/perl -w
        use strict;

        BEGIN{
        $\="\n";
        }

        &usage if @ARGV!=1;
        my $fileName=shift;
        &usage if ($fileName !~ m#\.(ram|rm)$#);
        &process_ram($fileName) if ($fileName =~ m|\.ram$|);
        &process_rm($fileName) if ($fileName =~ m|\.rm$|);


        sub usage(){
        print STDERR "usage: $0 filename.rm/ram\n";
        exit 1;
        }

        sub process_ram(){
        my $fileName=shift;
        $fileName=&processUrl($fileName);
        open RAM_FILE, $fileName || die "Failed To Process File: $!";
        while(){
        chomp;
        chop if ~ m/\r$/;
        $_ = &processUrl($_);
        &convertToMp3($_);
        }
        close RAM_FILE;
        }

        sub process_rm(){
        my $fileName=shift;
        $fileName=&processUrl($fileName);
        &convertToMp3($fileName);
        }

        sub convertToMp3(){
        my $fileName=shift;
        chomp($fileName);
        chop($fileName) if $fileName =~ m/\r$/;
        print "Processing File...$fileName";
        my ($dirName,$baseName)=&dirname($fileName);
        $baseName =~ s/\.rm/.mp3/;
        die "Invalid File: ${fileName}" unless(-e $fileName);
        `mplayer $fileName -ao pcm 2>/dev/null`;
        `lame -h -b 128 audiodump.wav $dirName/$baseName`;
        `rm audiodump.wav`;
        }

        sub dirname(){
        return (".",$_[0]) unless $_[0] =~ m|^/|;
        return $_[0]=~ m|(.*/)(.*)$|;
        }
        sub processUrl(){
        my $fileName=shift;
        chomp($fileName);
        if(&isUrl($fileName)){
        &download($fileName);
        return $fileName =~ m|.*/(.*)$|,$1;
        }
        return $fileName;
        }

        sub isUrl(){
        $_[0] =~ m/^http.*/;
        }

        sub download(){
        print "Downloading File...$_[0]";
        system("wget -c $_[0]")==0 || die "Failed to download file: $_[0]";
        }


        Wednesday, November 04, 2009

        Encroachers Hammering Project

        Recent anti-encroachment drive of Mysore is an example of admirable planning and execution. The drive was directed and managed by the MCC commissioner K. S Raykar.

        Planning Phase:Almost 6 months

        a) to get approvals from higher ups including district minister Shobha Karandlaje

        b) to develop project execution plan.

        Departments Involved: MCC, MUDA, Mysore Police (KSRP, CAR, DAR...etc), Telecom Department

        Project Leads: K.S Raykar( MCC Commissioner), Manivannan (DCP), Sunil Agarwal (Police Commissioner)

        Project Team Structure/Resourcing:

        Commanded by: 2 teams of MUDA and MCC

        Executed By: 27 teams of workers!!!

        The team organization and composition of each team is shown below.




        Risks/ Risk Mitigation:

        Stay Order from Court: The operation was started on a Sunday, early in the morning - no court is open at that time.

        Influence from elected representatives: All the phone lines, land line and mobile, were jammed with help of Telecom providers - physical presence required for any kind of influence.

        People gathering to protest: Jamming of phone lines prevent mobilization of people. Also, 500 policemen providing security would deter anyone raising voice.

        Result: More than 450 encroachments cleared by noon!

        Issues Encountered: There was protest by the elected representatives at the demolition site. The threat of arrest, and few arrests, by the police was enough to diffuse the crowd.

        Post Execution: MCC Commissioner goes on a 3 day sick leave from Monday – leaving all the encroachers and their supporters with the rubble!

        Monday, July 13, 2009

        A Geyser Weekend

        This weekend has been a Geyser weekend. All the weekend I was hunting for a geyser to buy. I realized this is not an easy task considering the kind of stuff you need to look for. Here is a small checklist of stuff you need to be aware for buying a geyser in India.

        Capacity: 25-15 liters Storage - This is enough for a bathroom geyser in most household of 4 to 6 ppl. The decision in this case has to be based on the requirement since the cost difference between a 25 ltr and 15 ltr model is Rs 400.

        Plastic Body (ABS) Acrylonitrile Butadiene Styrene (C8H8• C4H6•C3H3N)n plastic has very good electrical insulation properties.

        Copper Drum
        - Copper has special anti corrosive properties that prolongs the life of the water heater. This is useful for hard water areas.The heat retention in Copper Drum is more than that of stainless steel.

        Pressure - It is recommended to select a heater with pressure withstanding capacity of 6 Kg/cm2 and above in case of high rise apartments where the pressure can build-up due to water inlet. This might be due to a pressure pump used for water or water gushing down from the overhead tank.

        Adjustable Temperature - Ideal water temperature for a bath is 40- 45 degrees. This would save some money the electric bill!!

        Thermal Cut-out - A fail-safe device to prevent over heating and boiling

        Pressure cum vacuum release–prevents build up of excessive pressure (by releasing water) or vacuum (sucking in air) inside the tank.

        Semi return device – prevents dry heating of the element by cutting off flow from the tank- ensuring that element is always immersed in water.

        2-in-1 pressure cum release valve - Ensures positive and negative pressure is not created inside the tank

        Ceramic Heating Element - No electric shock. It is a cartridge type element that is not in contact with water. Also the heat transfer is over a much larger surface area. The result- longer elements, life, lower salt deposits, hence ideal for hard water areas, easier to replace without draining the water.

        PUF Insulation - Poly Urethene Foam prevents heat loss, retains heat longer.


        Certifications & Warranty
        ISI/BIS certification - A must india.
        Warranty period for 5 years.
        IEC international certification .
        And of course 5 star energy rating!!

        I happened to select a water heater with most of theses specifications - 2 years down the line i will be evaluating these criteria :)

        Friday, June 19, 2009

        Solving a Linear Programming Problem

        Operations Research (OR) is one of the key constituents of analytics. Solving a Linear Programming Problem (LPP) is core to OR. In one of my projects we have used a Simplex solver to choose an optimal solution from a set of available solutions. Its quite interesting to see a real life LPP.

        We use the SYMPHONY an open source generic MILP (Mixed-Integer Linear Programs) solver from COIN-OR.

        This solver takes two inputs

        • Problem model file: The Problem Model file contains the formulation of the LPP to be solved. The file uses GMPL (a subset of AMPL) a modeling language for Mathematical Programming.
        • Input data file:This file contains the input data of the problem to be solved.

        Equipped with this information I decided to solve one of the 6th Semester Engineering LPP problems.(I still have my 6th Sem OR notes!!)

        Problem Statement:
        A small scale hardware production plant produces Nuts, Bolts and Rivets. A box of Nuts fetches a profit of Rs 20 per fortnight. Profit per fortnight from a box of Bolts and Rivets is Rs 6 and Rs 8 respectively. A box of Nuts requires 8 hrs of Milling, 2 hrs of lathe time and 4 hrs of threading time. A box of Bolts requires 2 hrs of Milling, and 4 hrs of threading time. A box of Rivets requires 3 hrs of milling and 1 hr of lathe time. Further milling, threading and lathe can operate 250 hrs, 150hrs and 50hrs per fortnight. Find an optimal solution to maximize the profit per fortnight of production plant.

        Mathematical Formulation:
        Lets formulate the problem to be solved. Let x1, x2, x3 represent the optimal quantities of production of the Nuts, Bolts and Rivets per fortnight.

        The objective and constraints formulated can be easily derived from the problem statement.

        Objective: Maximize 20 x1 + 6 x2 + 8 x3

        Milling Constraints:
        8 x1 + 2x2 + 3x3 <= 250

        Threading Constraints:
        4 x1 + 3x2 + 0x3 <= 150

        Lathe Constraints:

        2 x1 + 0x2 + 1x3 <= 50

        Model File:

        Now we have to represent our mathematical formulation in way the Symphony solver can understand. Following is the formulation of the same problem in GMPL format.

        Filename: HardwarePlant.mod

        /*Input Data we need to Solve*/

        /* Input Set of products */
        set products;

        /* Gains of the product */
        param gain{i in products};

        /* Milling Requirements of the product */
        param milling{i in products};

        /* Lathe Requirements of the product */
        param lathe{i in products};

        /* Threading Requirements of the product */
        param thread{i in products};

        /* Milling Limit*/
        param millingLimit;

        /* Threading Limit*/
        param threadLimit;

        /* lathe Limit*/
        param latheLimit;


        /*Variable Declarations*/
        var x{i in products}, >= 0;

        /*Objective*/
        maximize profit: sum{i in products} gain[i]*x[i];

        /*Constraints*/
        subject to millingMachine: sum{i in products} milling[i]*x[i] <= millingLimit;

        subject to latheMachine: sum{i in products} lathe[i]*x[i] <= latheLimit;

        subject to threadMachine: sum{i in products} thread[i]*x[i] <= threadLimit;

        end;
        At first we take as input a set of products. Then we need the gain for each of the products. Next, we need the milling, threading and lathe requirements for the product. We also need the limits for each of the machines. Thats all the input we need to find an optimal solution.

        We define a variable set x representing the quantities of each of the product. We need to determine the values of x.

        Further we define the objective and constraints to choose the optimal solution.

        Input Data File:

        Following is the input data file from our problem statement to be used with the model file.

        Filename: HardwarePlant.dat

        data;

        set products:= Nuts Bolts Rivets;


        param gain:=Nuts 20
        Bolts 6
        Rivets 8 ;

        param milling:=Nuts 8
        Bolts 2
        Rivets 3;

        param thread:=Nuts 4
        Bolts 3
        Rivets 0;

        param lathe:=Nuts 2
        Bolts 0
        Rivets 1;

        param millingLimit := 250;
        param threadLimit := 150;
        param latheLimit := 50;

        end;

        First we provide the input set of products. This can be strings representing the name of the products.Name of the product acts as an index for the rest of the parameters

        Next we specify the gain per fortnight. From the model file its evident that we need gain for every product. We specify the name of the product and gain. As mentioned above the name serves as an index into the gain set.

        We use the similar approach as above and specify the values for milling, threading and lathe requirements.

        Finally, we specify the scalar values for the limits.

        Execution:
        Using the model and input file, Symphony solver can be executed as follows

        symphony -F HardwarePlant.mod -D HardwarePlant.dat

        The execution produces the following output (only the relevant part shown)
        Solution Cost: 700.000
        +++++++++++++++++++++++++++++++++++++++++++++++++++
        Column names and values of nonzeros in the solution
        +++++++++++++++++++++++++++++++++++++++++++++++++++
        x[Bolts] 50.000
        x[Rivets] 50.000

        Analyzing the output:
        The solver is recommending for production of 50 bolts, 50 rivets and no nuts in a fortnight. And the optimal profit is Rs 700 per fortnight.
        This is answer that matches the hand solved solution in my notes!!


        Wednesday, May 27, 2009

        Wednesday, May 20, 2009

        ESB - Does my project need it?

        A key component of the SOA architecture is ESB. Most often ESB is used as silver bullet to clean-up the Enterprise integration mesh.

        I came across quite an interesting perspective after a brief session with Jim Webber, an advocate of Guerilla SOA.

        From my past experience following are some of the key reasons for using an ESB.

        ESB cleans-up the integration mesh (or mess)

        A typical diagram of ESB based transformation is as shown above. In reality all the mesh gets into the ESB itself; ESB encapsulates the mesh. Subsequent to the ESB based solution implementation, enterprises would have to setup teams to manage the ESB and deal with the governance around the ESB usage.

        Eventually there is a possibility of the mesh outgrowing the ESB and spilling over; taking the integration back to where it started. Only difference this time is that the ESB will be part of the mesh.

        ESB is good for business process orchestration

        This is one of major feature that attracts a lot of developers. As a result, the business process gets into the ESB. The ESB now contains the critical business process of the enterprise, apart being just an integration back bone. This makes whole system extra complex with business logic spread all over.

        Other ESB vices

        In general usage of ESB results in vendor lock in. Business process is always wired in using vendor specific languages.

        Performance hit with ESB is significant. More dollars are spent scaling this beast.

        Occasionally project requires development custom adapter/data transformers to be used with ESB - additional effort for the development team with already strict time lines.


        Is ESB useless?

        No, its not; but ESB is not a silver bullet.

        ESB assists the project in meeting the data transformation and communication requirements. Its a good candidate for dealing with disparate protocols (FTP, IIOP, and SOAP) between the interacting systems

        How do I deal my integration mess?

        Business Chaos Modeling!!

        As I understand, Guerrilla SOA advocates modeling the SOA integration based on the real world business process. This is an interesting perspective.

        As we all know traditional software that models the business domain is the one best meeting the business requirement. Why can't we extend this to SOA?

        Just model the business interactions between services. If thats a mesh, so be it. The business itself is running with so many interactions.

        If a clean-up is required, then the change should originate from the business domain. This business domain change will percolate and would warrant a change in the SOA model.

        I feel this is idea of modeling the business chaos among the services is so much in line with the philosophy of SOA which promotes the alignment of software systems in line with the business.

        ESB can definitely not clean-up the so called chaos that originates in the business domain.

        Business Process Orchestration

        Business process is just business logic; why treat the process as a special entity? Implement the process like any other business logic. Such an implementation would ensure the entire business logic remains as a single unit and is more manageable.

        Managing Chaos

        Manageability of the solution/system post implementation is critical to any client. Although we model the business domain mesh in our system, it critical that the mesh be manageable. Monitoring and control interfaces to manage interactions are essential.

        Summary

        A manageable business integration (SOA), with thoughtful ESB usage would definitely make the client happy and align the implementation with business!!

        Hmm...quite a change of ideas in me after getting to know about Guerrilla SOA!!


        Sunday, March 08, 2009

        REST/ROA - UNIX File System

        I have been trying to understand the differences between REST and ROA. It seems they are useful only when they are coupled together. Specifically, they complement each other in terms the ground rules they lay down!!

        REST advocates uniform interface for the system. ROA divides the entire system into resources. Everything in the system is a resource and accessed using a similar interface.

        The following idea might be a little far-fetched or I might be completely wrong in understanding ROA/REST and UNIX file system!!

        REST/ROA concepts might be new to enterprise application design. However, I feel such concepts have been in use in system design; though they are not referred to by the same name.

        I feel UNIX file system is a good example of application of REST/ROA principles. Everything in the file system is a file any device, hard disk, console etc. are considered as files. So in the file system, file is the resource and access/usage to this resource is consistent across. Most of the operations that can be performed with a regular file can be done with any type of file.

        Thursday, February 26, 2009

        Variadic Macros - Quite Cool!!

        For the past few days, I have been doing C/CUDA based development. A good break from the the regular Java programming.

        CUDA does not support printf function in non-device emulation mode. During development we used to switch between emulation and non-emulation mode frequently. The switch was done using a compile time flag.

        We needed a way to remove the all the printf calls in non-emulation mode and have them execute in the emulation mode. The solution was to use Variadic Macro (Thanks to my friend who found the existence of such a macro).

        Finally our solution was:


        #ifdef EMU
        int log(char*msg, ...) {

        va_list args;
        va_start(args, msg);
        return vprintf(msg, args);

        }
        #else
        #define log(msg, ...)
        #endif
        We used the log variadic macro in our code. Nice learning!!

        Tuesday, December 02, 2008

        Easy Mock 2.3 on J2SE 1.4

        Easy Mock 2.x versions provide better API than Easy Mock 1.x versions. But the 2.x versions do not run on J2SE 1.4 versions.

        My current project uses J2SE 1.4. So i had no option but to use Easy Mock 1.2 for testing. Over a weekend i decided to port Easy Mock 2.3 onto J2SE 1.4.

        I have successfully ported EasyMock 2.3 onto J2SE 1.4. I have also added a new EasyMockTestCase to compensate for the lack of static imports in Java 1.4.

        I have hosted the ported code on http://code.google.com/p/easymock23onjdk14/

        Sunday, November 23, 2008

        Oracle XE "Processes" Parameter

        Oracle XE is an excellent lightweight substitute for the real Oracle database during development. A good database to run on every developer machine.

        One of the common issues with XE is that the connection refused exceptions generated when a project test suite consisting of significant number of database tests is run. This is also true for any database intensive, connection pool application running on Oracle XE.

        This is primarily due to the XE initialization parameter "processes".

        Following is the definition of this parameter as mentioned in the Oracle documentation.


        Specifying the Maximum Number of Processes

        The PROCESSES initialization parameter determines the maximum number of operating system processes that can be connected to Oracle Database concurrently. The value of this parameter must be a minimum of one for each background process plus one for each user process. The number of background processes will vary according the database features that you are using. For example, if you are using Advanced Queuing or the file mapping feature, you will have additional background processes. If you are using Automatic Storage Management, then add three additional processes.

        In short the "processes" parameter controls the maximum number of concurrent connections to the database. By default this is set to 50. Increasing this parameter will help in resolution of the "connection refused" issue mentioned above.

        Following are the steps to change the parameter.

        1. Connect to the database
        sqlplus sys as sysdba


        2. See the value of the process parameter
        show parameter processes

        Sample Output

        NAME TYPE VALUE
        ------------------------------------ -----------
        aq_tm_processes integer 0
        db_writer_processes integer 1
        gcs_server_processes integer 0
        job_queue_processes integer 4
        log_archive_max_processes integer 2
        processes integer 50

        3. Change the parameter
        alter system set processes=500 scope=spfile
        500 is a sample value, set it to any appropriate value. spfile represents the server parameters file.

        4. Shutdown the database
        shutdown immediate

        5. Start the database
        startup

        6. Look at the parameters.
        show parameter processes

        The processes parameter should have changed to the new value.

        Now running the test suite or any database intense application would not cause the connection refused error to be generated.

        Monday, September 04, 2006

        try THE catch IN finally

        As widely known the finally clause of Java has be implemented as a mini-subroutine. The subrountine is within the bytecodes of the method containing the finally clause.
        The jsr instruction cause a local jump to the sub-routine code and ret instruction cause a return from the sub-routine.
        A very interesting impact of this implementation can be seen below.

        public int getNum()
        {
        int i=2;

        try
        {
        return i;
        }
        finally
        {
        i=3;
        }

        }

        The return value of the above method is always 2 not 3. The value change in the finally clause doesn't impact the return value.

        The reason behind such a behaviour is as follows.

        The finally clause is executed prior to the return statement as expected. Before jumping to the code in finally clause, the return value is popped off from the stack and stored in a local variable. The reason for this action is that in Java finally clause can to also place another return value on the stack, can be through a return statement in finally itself.

        So the value of i which is 2 is popped-off the stack and stored in a local variable. During the execution of the finally clause the value of i is altered to 3. The finally clause finishes execution and the control is transferred back to the return statement.

        ~*~Now the return statement uses the stored value as the return value of the method. The return statement is not evaluated again, implies i is not evaluated again, so the change made to i in the finally clause is ineffective.~*~

        The change can be made effective only by explicitly adding a return statement to return the value of i in the finally clause.

        Thursday, August 31, 2006

        Java Code Quality for Programmers- Tools for the trade

        Ensuring code quality is an herculean task in J2EE/Java projects today. Fortunately,a lot of tools that help in improving the quality of the Java language code are available as free and open source software. Using these set tools make the code developed conformant to the standards right from the outset of the development phase.


        Following is a one such list of usage of different tools to improve the Java code quality that I use in my projects:

        1. IDE customization: This constitutes the first line of defense. All the developer IDE must be configured with the same rules for Java code and documentation. Be it Eclipse, Netbeans or Rational Application Developer. This ensures that the code is formatted in similar manner across IDEs and the entire code base is coherent. Further, the IDEs provide a 'Format' option that would automatically format the whole code to the specification provided. This step removes almost all developer 'coding standard' errors.


        2.CheckStyle(http://checkstyle.sourceforge.net/): Checkstyle performs a detailed check of code conformance with Java Coding Standards. The tool also points out common functional errors made by programmers. A Checkstyle configuration file customized for the current project coding standards should be created and distributed to the team. This is a better way of communicating the project coding guidelines than a verbal discourse or a huge MS Word/PDF document.Checkstyle plug-ins are available for almost all the popular IDEs. The project Checkstyle configuration can be fed to the IDE plug-in so that any non-conformance is immediately highlighted to the developer in the code. This ensures the code developed is in line with the project coding standards.

        3. FindBugs(http://findbugs.sourceforge.net/): FindBugs inspects the Java byte code for bug patterns. Running FindBugs on the code developed reveals a set of issues, majority of runtime bugs, that cannot be caught by the source code analysis tools. Again plug-ins are available for popular IDEs.


        Note: Checkstyle and FindBugs can be used without an IDE. The IDE integration is a just an option and left to the discretion of the developer.

        Once the above steps/tools have been performed on the code by the developer. The code is ready for the review phase.

        Usage of such tools by developers, provide them with a lot of learning about the standards, do's and don'ts of Java programming. These tools free the reviewers from delving into code level laborious issues like documentation, indentation etc, which are best done with automated tools. The reviewer can use the same tools or tools like PMD(http://pmd.sourceforge.net/) and JNCSS(http://www.kclee.de/clemens/java/javancss/) to determine design issues, code complexity.etc.