Wednesday, December 7, 2011

Spring RMI over firewall

Problem: RMI service is not reachable even if the registry port is open in the firewall

Reason: RMI uses a random service port for communication with client and hence firewall will block this port. Even if you open RMI registry port on firewall the service can not be used since the service port is not open.

Solution: Configure a specific service port instead of the default random port for your RMI service. RMI will use this port instead of using a random port. You can open this port in your firewall and hence make the communication happen. If you are using spring Remoting then its as simple as configuring servicePort property for your RMIServiceExporter.
Eg
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">

    <property name="serviceName" value="MyService"></property>
    <property name="service" ref="MyService"></property>
    <property name="serviceInterface" value="in.example.MyService"></property>
    <property name="registryPort" value="1099"></property>
    <property name="servicePort" value="1100"></property>
</bean>

And the good news is that both registryPort and service port can be the same. That means your firewall requires to open only a single port for your rmi service.

Common Misconception: RMI uses the registry port for communication and opening registry port in firewall is sufficient to support RMI service over firewall

Tuesday, October 25, 2011

Java Green thread

If the thread is handled by the JVM itself then it is called green thread.
Green thread are used in the following cases
1. Operation systems where multi threading is not supported(eg. Low end Mobile OS)
2. If you are using Java 1.1 or previous versions

Green threads are slow because the JVM has to switch between processes

Wednesday, October 5, 2011

Linux: get time in Indian Standard Time (IST)

On Any linux server, if you want to get time in the Indian standart time zone. use the following command

TZ='Asia/Kolkata' date 

For eg: TZ='Asia/Kolkata' date +%Y%m%d gives you 20111005

This is very useful if your server is on a different timezone and your applicaion(shell script) requires Indian Standard time (IST)

note: TZ=IST does not work since shell interpret it as International Standard Time





Saturday, October 1, 2011

Postgres/MySQL database synchronization using RubyRep



It is nice to have a tool which can synchronize two databases so that if you have two copies of a database then you can convert the old database to the latest one, by synchronizing all the missing data to new database. A synchronization tool makes database A same as database B provided that A and B has the same schema. The tool does this by copying all extra data in A to B and deleting extra data in B. One practical use of such a tool is synchronizing a production database to staging database and vice versa.

Database systems like Oracle comes with built in tools to sync two datbases but postgres and mysql does not have a sync tool in its default package. So if you want to synchronize two postgres databases then you require a third party tool. RubyRep is such a synchronization tool which supports postgres and mysql. As the name indicates it is developed using Ruby language, that means you have to install ruby in your machine to use this tool. It also requires a number of gems (ruby libraries), but wait.... Rubyrep also has a Jruby version, that means you can run it on any machine which has a JVM installed on it and you dont have to install any dependencies. Cool, isn't it? All you have to do is to download it, extract it and use it. Here is the home page of RubyRep

A simple guide to using RubyRep

Rubyrep works on the following concepts....
It has to synchronize two databases; the left database and the right database.By default it synchronizes left database to right database. You have to provide the list of tables which has to be synchronized. Ruby rep assumes that your tables are in public schema. If you have other schemas then you have to provide the schma name also. Rubyrep reads the left and right database connection details and other configurations from a config file. The configuration file has its own syntax.So the best way to create a config file is to allow ruby rep to create a default config file, then edit it with your database details.
  1. Creating a config file
rubyrep create CONFIG_FILE
eg: sh rubyrep create myconf.cfg

  1. Scanning difference between two databases
rubyrep scan -c CONFIG_FILE
eg: sh rubyrep scan -c myconf.cfg

  1. Syncing two databases
rubyrep sync -c CONFIG_FILE
eg:sh rubyrep sync -c myconf.cfg

  1. Overwrting the default configurations
To overwrite the configuration in the config file, pass the configuration parameters as arguements to the rubyrep command
eg: rubyrep sync -c alert_manager.cfg 'vertical_lv',tip
Synchronizes only vertical_lv and tip tables
For more details, visit the rubyrep tutorial page.

Friday, July 15, 2011

google asks for mobile number

Have you tried logging in to google from a mobile? google identifies that you have logged in from mobile phone and ask you to enter your mobile number which can be used for password recovery. really cool rite? give it a try

Friday, May 27, 2011

Eclipse fails to restart after a crash

If your eclipse fails to start after a crash, and get stuck at the loading workbench screen then do the following step to recover the issue
go to the workspace folder/.metadata/.plugin/org.eclipse.core.resources/.projects/
For each project delete the .syncinfo.snap and .markers.snap file

Saturday, February 19, 2011

Debugging JUNIT maven test case


It will be very useful if you can test your JUNIT test cases when you are using Maven. Maven supports debugging with eclipse. Steps are as follows

1. Create a new debug configuration in eclipse as Remote Java Debugging on port 5005
2. Set break point on the required class files
3. Go to your project directory and execute the below command 'mvn test -Dmaven.surefire.debug=true' .The Test case will wait for a listener at 5005
4. Now go back to eclipse and start the debugger with the new debug configuration
There you go... Enjoy finding bugs and destroying them:)

Saturday, February 12, 2011

GWT-Google's way of web development

GWT stands for Google WebToolkit, it is a very good technology which allows you to develop your web site using POJO. If you are familiar with Java Swing and want to develop a website then GWT is the right tool for you. 

How does it work? GWT converts the Java code to JavaScript and HTML, that too optimized JavaScript. When you compile GWT application the toolkit generates multiple set of JavaScript and chooses the best JavaScript code. 

GWT can save a lot of maintenance time for web developers because the generated code is compatible with all major browsers. You wont have problems from customers like "The page does not work on Mozilla but works on IE8". Also you don't have to show the below message to your end users. "This website works best with IE8, some features may not work in other browsers"[This is an irritating message for me because I use ubuntu + Mozilla. Even ICICI website shows this message!!!]. Once my team had spent 45 days to make a JSP based website compatible with Mozilla and IE. Still we were having issues, and complaints from customer every day and the maintenance was a never ending process. End of the day customer was not happy too :(


As a developer, I like GWT because it allows you to organize GUI code very well. Code is more readable, maintainable and organized. Imagine each webpage is represented by a class file which can inherit another page and include another page and use all other Object oriented concepts. Obviously its far better than the cumbersome JSPs and few other technologies.

Its not over, you have the built-in AJAX support which allows you to develop your web site using AJAX. Its a very simple interface too.

Lols! What else you need? go for it...

Click here to go to the GWT home page

Tantrajnana

Tantrajnana means Technology in Sanskrit. Welcome you all to my technical sharings. I hope you will benefit from this blog.

            Santhosh Kumar Krishna