hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Hadoop Wiki] Update of "ZooKeeper/ZooKeeperExercise1" by BenjaminReed
Date Tue, 11 Nov 2008 20:18:44 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Hadoop Wiki" for change notification.

The following page has been changed by BenjaminReed:
http://wiki.apache.org/hadoop/ZooKeeper/ZooKeeperExercise1

New page:
Let's start off by creating a minimal ZooKeeper client:

{{{
import java.io.*;
import org.apache.zookeeper.*;

public class SimpleZoo {
    static class MyWatcher implements Watcher {
        public void process(WatchedEvent event) {
            System.err.println(event);
        }
        
    }
    public static void main(String[] args) throws Exception {
        MyWatcher myWatcher = new MyWatcher();
        ZooKeeper zk = new ZooKeeper(args[0], 10000, myWatcher);
        Thread.sleep(10000);
        zk.close();
    }
}
}}}

What events do you get when you start?

Lets create a program to create a znode (I'll use "/motd", but you can pick your own name).
You'll need to add:

{{{
        zk.create("/motd", "hi".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}}}

What happens if you try to create /motd twice?

Create a new simple client to set "/motd":

{{{
        zk.setData("/motd", newdata, -1);
}}}

Create a new simple client to read "/motd".

{{{
        Stat stat = new Stat();
        byte data[] = zk.getData("/motd", true, stat);
}}}

Try changing /data and watch the events you get. What if you change /data twice in a row?
Could this be used for messaging?

Mime
View raw message