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

unecessary invocation of exists and readData for each listener? #63

Open
wy96f opened this issue Jan 4, 2017 · 0 comments
Open

unecessary invocation of exists and readData for each listener? #63

wy96f opened this issue Jan 4, 2017 · 0 comments

Comments

@wy96f
Copy link

wy96f commented Jan 4, 2017

Could the code below:

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);
                }
            }
        });
    }
}

modify as:

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

        @Override
        public void run() throws Exception {
            // reinstall watch
            exists(path, true);
            try {
                Object data = readData(path, null, true);
                for (final IZkDataListener listener : listeners) {
                    listener.handleDataChange(path, data);
                }
            } catch (ZkNoNodeException e) {
                for (final IZkDataListener listener : listeners) {
                    listener.handleDataDeleted(path);
                }
            }
        }
    });
}
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

1 participant