hadoop-zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Burton" <bur...@spinn3r.com>
Subject Updated NodeWatcher...
Date Thu, 08 Jan 2009 08:00:32 GMT
I've updated based on the last round of feedback regarding ZK operation:
http://pastebin.com/f66898b7

This is what I think the API should look like for event based applications
without any insane requirements.

You write code like:

        NodeListener listener = new NodeListener() {

                public void onData( String path, Stat stat, byte[] data ) {
                    System.out.printf( "event: onData path: %s, version: %s,
data: %s\n", path, stat.getVersion(), new String( data ) );

                }

                public void onKeeperException( KeeperException e ) {
                    System.out.printf( "event: onKeeperException: \n" );
                    e.printStackTrace();
                }

                public void onFailure() {
                    System.out.printf( "event: onFailure\n" );
                }

                public void onConnect() {
                    System.out.printf( "event: onConnect\n" );
                }

            };

        NodeWatcher nWatcher = new NodeWatcher( "server45.example.com:2181,
server46.example.com:2181,server47.example.com:2181", listener );
        nWatcher.watch( "/foo" );

        nWatcher.poll();

.... and then you will receive events back from ZK when the files are
updated.

I believe it handles all race and fail conditions of ZK which was the hard
part since some of these are subtle or not really documented.

I'd be willing to contrib this if others found it useful.

I think we're going to use it as our main interface to ZK since it solves
all the issues I care about.

Kevin

-- 
Founder/CEO Spinn3r.com
Location: San Francisco, CA
AIM/YIM: sfburtonator
Skype: burtonator
Work: http://spinn3r.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message