You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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();
}
}
}
The text was updated successfully, but these errors were encountered:
method:
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 {
The text was updated successfully, but these errors were encountered: