try
{
_lock.writeLock().lock();
// TODO: optimize it by get stat from callback
Stat stat = new Stat();
Object readData =
_accessor.get(dataPath, stat, AccessOption.THROW_EXCEPTION_IFNOTEXIST);
ZNode znode = _cache.get(dataPath);
if (znode != null)
{
Stat oldStat = znode.getStat();
// System.out.println("handleDataChange: " + dataPath + ", data: " + data);
// System.out.println("handleDataChange: " + dataPath + ", oldCzxid: " +
// oldStat.getCzxid() + ", newCzxid: " + stat.getCzxid()
// + ", oldVersion: " + oldStat.getVersion() + ", newVersion: " +
// stat.getVersion());
znode.setData(readData);
znode.setStat(stat);
// if create right after delete, and zkCallback comes after create
// no DataDelete() will be fired, instead will fire 2 DataChange()
// see ZkClient.fireDataChangedEvents()
if (oldStat.getCzxid() != stat.getCzxid())
{
fireEvents(dataPath, EventType.NodeDeleted);
fireEvents(dataPath, EventType.NodeCreated);
}
else if (oldStat.getVersion() != stat.getVersion())
{
// System.out.println("\t--fireNodeChanged: " + dataPath + ", oldVersion: " +
// oldStat.getVersion() + ", newVersion: " + stat.getVersion());
fireEvents(dataPath, EventType.NodeDataChanged);
}