Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unnecessary exists method invoke? #61

Open
likebean opened this issue Nov 24, 2016 · 1 comment
Open

unnecessary exists method invoke? #61

likebean opened this issue Nov 24, 2016 · 1 comment

Comments

@likebean
Copy link

private void fireDataChangedEvents(final String path, Set<IZkDataListener> listeners) {
    for (final IZkDataListener listener : listeners) {
        _eventThread.send(new ZkEvent("Data of " + path + " changed sent to " + listener) {

            @Override
            public void run() throws Exception {
                // reinstall watch
                exists(path, true);
                try {
                    Object data = readData(path, null, true);
                    listener.handleDataChange(path, data);
                } catch (ZkNoNodeException e) {
                    listener.handleDataDeleted(path);
                }
            }
        });
    }
}

maybe modify as:

private void fireDataChangedEvents(final String path, Set<IZkDataListener> listeners) {
    for (final IZkDataListener listener : listeners) {
        _eventThread.send(new ZkEvent("Data of " + path + " changed sent to " + listener) {

            @Override
            public void run() throws Exception {         
                try {
                    Object data = readData(path, null, true);
                    listener.handleDataChange(path, data);
                } catch (ZkNoNodeException e) {
                    exists(path, true);
                    listener.handleDataDeleted(path);
                }
            }
        });
    }
}
@wy96f
Copy link

wy96f commented Jan 3, 2017

No, you can't. Think of the case that the node is created between the readData and exists where you will not be notified of the data change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants