if((stat=zk.exists(node.getPath(),false))!=null) {
if(handlers.containsKey(clazz)) {
//set this node
zk.setData(node.getPath(), handlers.get(clazz).serialize(node.getData()),stat.getVersion());
} else {
throw new NodeKeeperException(String.format("cannot find handler for '%s'",node.getData().getClass().getName()));
}
} else {
//create all node parent recursively if necessary
if(node.getPath().contains(PATH_SEPARATOR) && node.getPath().lastIndexOf(PATH_SEPARATOR)>0) {
buildRecursively(node.getPath().substring(0, node.getPath().lastIndexOf(PATH_SEPARATOR)), String.format("created by %s", this.getClass().getName()).getBytes());
}
//serialize data
if(handlers.containsKey(clazz)) {
//create this node
zk.create(node.getPath(), handlers.get(clazz).serialize(node.getData()), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} else {
throw new NodeKeeperException(String.format("cannot find handler for '%s'",node.getData().getClass().getName()));
}
}
} catch (KeeperException e) {
throw new NodeKeeperException(String.format("cannot write data for node '%s'", node.getPath()));
}
}