You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@zookeeper.apache.org by lei liu <li...@gmail.com> on 2011/07/29 10:23:27 UTC

set wacher failed

I write Wacher class,   I call zk.getData(path, watch, null) in process()
method, example below code:

public class AppVersionMappingChildrenNodeWatcher implements Watcher {

    private ZooKeeperManager zooKeeperManager;

    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    //process biz when some child added or deleted
    @Override
    public void process(WatchedEvent event) {

        //open a watcher
        String path = event.getPath();
        logger.info("notify path:"+path);
        String value = "";
        try {
           value = zk.getData(path, watcher, null);
            logger.info("reMonitor for zookeeper in AppVersionMappingWatcher
success,value is:"+value);
        } catch (Exception e) {
            //TODO:huangdou.c: i will lost this machine in this zookeeper
call back group
            logger.error("reOpen watcher failure, this machine will be lost.
please restart");
        }
    }
}


If zk.getData(path, watcher, null) throw Exception,  the watch will be not
left on the node with the given path. The watch will be not  triggered by a
successful operation that sets data on the node, or deletes the node, So my
application will never be notified when the data is changed on the node,
how I can handle the Exception?


Thanks,


LiuLei

Re: set wacher failed

Posted by Patrick Hunt <ph...@apache.org>.
The docs; programmer guide, API, and FAQ are good places to start.
Read through those first. You might also find it helpful to look at
the "recipe" implementations (src/recipes) which implement common
patterns including error handling.

Regards,

Patrick

On Fri, Jul 29, 2011 at 1:23 AM, lei liu <li...@gmail.com> wrote:
> I write Wacher class,   I call zk.getData(path, watch, null) in process()
> method, example below code:
>
> public class AppVersionMappingChildrenNodeWatcher implements Watcher {
>
>    private ZooKeeperManager zooKeeperManager;
>
>    protected Logger logger = LoggerFactory.getLogger(this.getClass());
>
>    //process biz when some child added or deleted
>    @Override
>    public void process(WatchedEvent event) {
>
>        //open a watcher
>        String path = event.getPath();
>        logger.info("notify path:"+path);
>        String value = "";
>        try {
>           value = zk.getData(path, watcher, null);
>            logger.info("reMonitor for zookeeper in AppVersionMappingWatcher
> success,value is:"+value);
>        } catch (Exception e) {
>            //TODO:huangdou.c: i will lost this machine in this zookeeper
> call back group
>            logger.error("reOpen watcher failure, this machine will be lost.
> please restart");
>        }
>    }
> }
>
>
> If zk.getData(path, watcher, null) throw Exception,  the watch will be not
> left on the node with the given path. The watch will be not  triggered by a
> successful operation that sets data on the node, or deletes the node, So my
> application will never be notified when the data is changed on the node,
> how I can handle the Exception?
>
>
> Thanks,
>
>
> LiuLei
>