Thursday, August 28, 2008

Difference between Remittance and Transfer

In financial industries, 'Remittance' refers to an action of sending money from an individual to other not being resulted from either sale and transfer of good and funds. 'Transfer' generally refers to an action of sending money from a party to other as payment for a good or service.
E.g. CitiBank Japan have different charge for remittance and transfer

Friday, August 8, 2008

Calling RMI from EJB Stateless Session Bean

I have to analyze one of our J2EE application(s), that call RMI from a Stateless Session Bean. I originally think that it could be a problem, because our Session Bean use remote object as singleton and the rule said that Session Bean shall be programed in thread safe manner because its methods run concurrently within container's threads. To confirm that I decided to do some experiments.
I create a sample RMI server
/* SampleServer.java */
import java.rmi.*;

public interface SampleServer extends Remote
{
  public int sum(int a,int b) throws RemoteException;
}

import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;

/* SampleServerImpl.java */
public class SampleServerImpl extends UnicastRemoteObject
                             implements SampleServer
{
  SampleServerImpl() throws RemoteException
  {
     super();
  }

  public int sum(int a,int b) throws RemoteException
  {
     try {
       Thread.sleep(5000);
     } catch (InterruptedException e){
       e.printStackTrace();
     }

     return a + b;
  }

  public static void main(String args[])
  {
    try
      {
        SampleServerImpl sampleServer = new SampleServerImpl();

        Registry registry = LocateRegistry.createRegistry(8989);
        registry.rebind("Sample", sampleServer);

        System.out.println("Server waiting.....");
      }
    catch (RemoteException e)
      {
         e.printStackTrace();
      }
  }
}
I compile these classes compile and run using JDK1.5 with jmx enabled according jconsole article
$ javac SampleServer.java SampleServerImpl.java
$ rmic SampleServerImpl
$ java -Dcom.sun.management.jmxremote SampleServerImpl
I decide to use JRUBY to create and run a 20 thread(s), each issue a call RMI server
$jirb
> import java.rmi.Naming  
> sample = Naming.lookup("//127.0.0.1:8989/Sample")
> (1..20).each { Thread.new { puts sample.sum(3,7)} }
>
Then I run jconsole supplied in JDK1.5 and watch thread pool of the RMI server
$jconsole
The result is everything is OK, for each incoming call request, RMI server create a separate thread to handle it and the thread is dropped after it completion.

Wednesday, July 9, 2008

Joining ING Direct Japan

I have given a resignation letter to the CEO of CSE, the company that I worked for 11 years. Officially I will join ING Direct Japan at the end of August and will move to Tokyo.
Taking such decision is not easy, CSE is not just my workplace, it is part of my life, where I put a lot of my desire and hope. These past 11 years was rewarding and I never regret of the decision to move from Prague to Hanoi in 1997. But it is time to change.
If anyone have chance to be in Tokyo, don't forget to drop me a e-mail, I will be pleased to go with you for a drink.

Saturday, May 10, 2008

Faster jruby startup

One of issue with JRuby and Java in general is long startup time. As the result, a lot of peoples including myself use MRI when developing application and then use JRuby to test and run the application.
Recent change is jruby shell script have improved startup time at significantly by putting JRuby library into java boot classpath (using -Xbootclasspath/a:) instead of normal classpath to bypass java class verification, however it still so slow compare to MRI.
Below is a simple test on machine
1. jruby lib in classpath
huy@huy-desktop:/u01/jruby-1.1.1/bin$ time jruby -e "puts 'hello world'"
hello world

real    0m2.934s
user    0m2.604s
sys     0m0.136s

2. jruby lib in boot classpath
huy@huy-desktop:/u01/jruby-1.1.1/bin$ time jruby -e "puts 'hello world'"
hello world

real    0m1.124s
user    0m0.896s
sys     0m0.072s
3. MRI
huy@huy-desktop:/u01/jruby-1.1.1/bin$ time ruby -e "puts 'hello world'"
hello world

real    0m0.060s
user    0m0.004s
sys     0m0.004s

Tuesday, April 15, 2008

Why Python

I known Python during the time I read the book "Test-Driven Development By Example". It is dynamic programming language like Ruby. However I don't like that language as Ruby because of it's syntax, missing open classes, having difficult meta programming style, etc..
I get attention of Python after recent release of Google AppEngine, a combination of web framework written in Python with hosting service. Google AppEngine allows us to develop application in our machine then upload to Google hosting service and benefit from Google Infrastructure including identity management, Google datastore, scalability on demand, etc. . Google AppEngine is now available only for Python developers, they are many so within few hours from announcement of Google AppEngine, the first free 10,000 accounts has gone.
Python has additional good characteristics to be considered as language on new projects:
- Python can compile program to byte code so it has reputation of better performance then Ruby.
- In addition to C implementation, Python has already quite mature .Net and Java implementation, which can be very strong arguments in any integration projects.
- Python has proven track on scalable web site like Google or framework as Django , Zope or application as ERP5

Friday, February 22, 2008

Sunday, January 20, 2008

Using git for newbie

I am doing some experiment with Rubinius code base, which uses distributed SCM git. Comparing with Subversion, Git is a little bit more difficult, so It takes me a while to understand its commands and find the proper way to work with it. Without commit right, here are typical commands I use in my work flow.

Clone a remote repository into the local disk - repository is create as a clone of the remote repository identified by a given url
git clone git://git.rubini.us/code 
cd code # goto directory containing local repository 
git config user.name "le huy"  #configure your name 
git config user.email "lehuy20@gmail.com" #and email that will be used when committing
Sample .git/config - git create a .git directory to store it's data, file .git/config contains configuration data including remote repository, which remote branch is link with which local one
cat .git/config 
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = git://github.com/evanphx/rubinius.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[gui]
        geometry = 885x450+5+65 399 192
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "cpp"]
        remote = origin
        merge = refs/heads/cpp
Submodule - git submodule is used to link to external repository (equivalent to subversion extern)
cat .gitmodules
[submodule "mspec"]
        path = mspec
        url = git://github.com/brixen/mspec.git
[submodule "spec/frozen"]
        path = spec/frozen
        url = git://github.com/brixen/rubyspec.git
init and update submodule from external repository
git submodule init # init submodule repository based on .gitmodules
git submodule update
Show current branch - show which branch we are working on, switch between them
git branch # will show us local branches 
* cpp
  master

git branch -a # will show us all branches including local and remote 
* cpp
  master
  origin/cmakebuild
  origin/cpp
  origin/fusion-experiment
  origin/instance_eval
  origin/master
  origin/wilson64

git checkout master # switch to branch named 'master'
git checkout dev # switch to branch named 'dev'
We can sometime create new branches in addition to 'master' to work concurrently on many features
Create new branch
git branch working  # create branch 'working' 
git checkout working # switch to branch named 'working'
git branch dev --track origin/dev # create local branch 'dev' that track the remote branch origin/dev
The current working branch is now 'working'

Delete branch - we can remove unused branch if it is no longer needed
git branch -d working # delete 'working' branch
Update from remote repository - e.g. wait until someone commit the patch to the main trunk then update changes from git://git.rubini.us/code
git pull will perform merge change on remote branch to local branch
git pull
git rebase will save local changes away, update from remote branch, and then reapply them
git rebase master 
Push change to remote repository
git push # push will update a --track branch in remote repository,
Edit source code - do some source code editing
gedit kernel/core/kernel.rb
Show modification - show what I have modify without committing change
git diff HEAD # HEAD is symbol for latest/head version of current branch
Revert back -when recognizing that there is something wrong, we can undo the modification, all changes are lost
git reset --hard HEAD
Edit source code - Do some source code editing again
gedit kernel/core/module.rb
Commit changes - commit change in current branch
git commit -a -s # vi editor will be popped up for entering committing message
Create patch - create patch containing changes between 2 branches local 'master' and remote 'origin/master'
git checkout master # switch to branch 'master'
git format-patch origin/master --stdout # to standard output
git format-patch origin/master -o ../patch # create formated patch as a file and store in directory ../patch
Create a ticket - goto in http://rubinius.lighthouseapp.com/m create a ticket and attach a patch file to it

Revert change - switch to branch named 'master' and revert back directory tree in original state, all changes are lost
git checkout master
git reset --hard HEAD 
Resolve conflict - if there is a conflict on file, git stop doing and ask for manually resolve, to inform that the conflict has been resolved on e.g. kernel/core/module.rb, use
gedit kernel/core/module.rb # after manually resolve conflict
git add kernel/core/module.rb # inform git that conflict on file kernel/core/module.rb is resolved
Apply patch
git-apply ../patch/0001-Fixes-for-Class-include-and-Class-extend-to-handle-c.patch
Apply patch partly - if a patch contains modification of multi files and there are conflict with some of them during patching, then use --reject option to modify only non-conflicted files and create filename.rej for those conflicted
git-apply --reject ../patch/0001-Fixes-for-Class-include-and-Class-extend-to-handle-c.patch 
Remove file from stage Making change into git repository actually happens in two steps, 1) add the new/modified file into stage area 2) commit stage area. If for some reason, we want to revert the step 1) we can do as follow
$git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached ..." to unstage)
#
# new file: dict_parser/tests/dict_tests.py
#
$ git rm --cached dict_parser/tests/dict_tests.py
rm 'dict_parser/tests/dict_tests.py'
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
# dict_parser/
Git getting popular now when many open source projects moved from subversion to git, Zack Rusin has done very nice git cheat sheet summarizing git usage scenarios below

Friday, December 21, 2007

Saturday, November 24, 2007