Friday, November 20, 2009

Finally my freepastry nodes are working

In past few weeks I have been working with Freepastry in order to implement a p2p substrate. Freepastry is the java implementation of pastry algorithm based on DHT. But I was very unhappy in this case that the Pastry nodes implemented in different machines were not communicating. More technically bootstrap node is not identified by the lately come nodes and hence the nodes are not organizing into a ring. But while running on same JVM it works well. Btw finally I could able to make it worked. i.e nodes are now joining to pastry ring and communicating residing even in different machines also.
Initially It was not working because of that I had forget to implement one code line that perform the call to register() method of endpoint reference object.

Not only that. There are some other points also that I found and which was not mentioned in freepastry tutorial.
1) For the Bootstrap node bootAdress(InetAdrress) should be the real Ip( or the domain name also could be worked but I didn't check ) of the machine and the boot port and bind port should be equal.
int bindport = Integer.parseInt(args[0]);
InetAdress bootaddr = InetAddress.getByName(args[1]);
int bootport = Integer.parseInt(args[2]);

Note that here if you start new node as the bootstrap(parent) node then you should pass local IP or domain name of local maching as as the bootaddr and same port number for both bindport and bootport.
So if the ip of the local machin is then your command line arguments should be like
$java [-options] class 9001 9001

2) In FreePastry Application class (in this example MyApp) where we normally initiate the reference for Endpoint, dont forget to call register() method.

import rice.p2p.commonapi.Application;
import rice.p2p.commonapi.Endpoint;
import rice.p2p.commonapi.Id;
import rice.p2p.commonapi.Message;
import rice.p2p.commonapi.Node;
import rice.p2p.commonapi.NodeHandle;
import rice.p2p.commonapi.RouteMessage;

public class MyApp implements Application {

protected Endpoint endpoint;

public MyyApp(Node node) {

this.endpoint = node.buildEndpoint(this, "myinstance");


//some codes go here

Therefore the Warning is...
If somebody wish to implement freepastry and forget to call this register() method your other pastry nodes who are waiting to receive messages from the first node wont receive pastry messages.

Monday, November 16, 2009

Changing default java setting on ubuntu

By default ubuntu comes with default GCJ flavor of Java which sometimes gives trouble when working in console to compile and run java programs. I recently faced to this problem. So here I thought to write how to change the default java setting on ubuntu.

Nothing much. we only need to change two things in advance that is java and javac command.

To choose Java
Just installing new Java flavours does not change the default Java pointed to by /usr/bin/java. You must explicitly set this:

$ sudo update-java-alternatives -l to see the current configuration and possibilities.

$sudo update-java-alternatives -s XXXX to set the XXX java version as default. For Sun Java 6 this would be sudo update-java-alternatives -s java-6-sun

Run java -version to ensure that the correct version is being called.

Alternative way

$sudo update-alternatives --config java

Although the above changes are done the system may still refer to old 'javac' setting.

To choose javac

To check which javac is fired when type javac -version use

$which javac


To check this javac is a real program or a symlink
ls -al /usr/bin/javac
lrwxrwxrwx 1 root root 23 2009-07-29 19:42 /usr/bin/javac -> /etc/alternatives/javac

It is a symlink. follow the same command again.
$ls -al

lrwxrwxrwx 1 root root 42 2009-11-16 14:59 /etc/alternatives/javac -> /usr/lib/jvm/java-gcj/bin/javac

So probably the /etc/alternatives/javac link will point to the not desired javac. Change it (as root) using:

$ln -sf /etc/alternatives/javac