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

XQueryContext has helpless synchronization #852

Closed
alebastrov opened this issue Dec 8, 2015 · 4 comments
Closed

XQueryContext has helpless synchronization #852

alebastrov opened this issue Dec 8, 2015 · 4 comments
Labels
triage issue needs to be investigated

Comments

@alebastrov
Copy link

method:

  • public synchronized ExistRepository getRepository(){...}
  • usage of updateListener field may need sync (if there are several threads which add/remove listeners)
    Also
    inner class (should be static) class ContextUpdateListener does too long synchronization when documentUpdated() and unsubscribe() called, and of course debug() and nodeMoved() should use syncronization
    I would suggest such realization

private static class ContextUpdateListener implements UpdateListener {

    private List<UpdateListener> listeners = new ArrayList<UpdateListener>();

    public void addListener( UpdateListener listener )
    {
        synchronized( this ) {
                       listeners.add( listener );
        }
    }


    public void documentUpdated( DocumentImpl document, int event )
    {
        List<UpdateListener> copyOfListeners = null;
        synchronized( this ) { 
            copyOfListeners = new ArrayList(listeners);
                    }
            for( final UpdateListener listener : copyOfListeners ) {

                if( listener != null ) {
                    listener.documentUpdated( document, event );
                }
            }

    }


    public void unsubscribe()
    {
        List<UpdateListener> copyOfListeners = null;
        synchronized( this ) { 
            copyOfListeners = new ArrayList(listeners);
            listeners = new ArrayList();
                    }
            for( final UpdateListener listener : copyOfListeners ) {

                if( listener != null ) {
                    listener.unsubscribe();
                }
            }
    }


    public void nodeMoved( NodeId oldNodeId, StoredNode newNode )
    {
        List<UpdateListener> copyOfListeners = null;
        synchronized( this ) { 
            copyOfListeners = new ArrayList(listeners);
                    }
        for( int i = 0; i < copyOfListeners.size(); i++ ) {
            final UpdateListener listener = (UpdateListener)copyOfListeners.get( i );

            if( listener != null ) {
                listener.nodeMoved( oldNodeId, newNode );
            }
        }
    }


    public void debug() {
        List<UpdateListener> copyOfListeners = null;
        synchronized( this ) { 
            copyOfListeners = new ArrayList(listeners);
                    }
        LOG.debug(String.format("XQueryContext: %s document update listeners", copyOfListeners.size()));
        for (int i = 0; i < copyOfListeners.size(); i++) {
            ((UpdateListener) copyOfListeners.get(i)).debug();
        }
    }

}
@shabanovd
Copy link
Member

@alebastrov will you able to make PR?

@alebastrov
Copy link
Author

Of course yes, but it may take some time

@alebastrov
Copy link
Author

added PR: #853

@joewiz joewiz added the triage issue needs to be investigated label Sep 17, 2018
@duncdrum
Copy link
Contributor

duncdrum commented Jan 8, 2019

closed by rebased #886

@duncdrum duncdrum closed this as completed Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage issue needs to be investigated
Projects
None yet
Development

No branches or pull requests

4 participants