directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1156561 - in /directory/apacheds/trunk: core-api/src/main/java/org/apache/directory/server/core/event/ core-api/src/main/java/org/apache/directory/server/core/interceptor/ core-jndi/src/main/java/org/apache/directory/server/core/jndi/ core...
Date Thu, 11 Aug 2011 10:07:21 GMT
Author: elecharny
Date: Thu Aug 11 10:07:20 2011
New Revision: 1156561

URL: http://svn.apache.org/viewvc?rev=1156561&view=rev
Log:
o Extracted the DefaultEventService class from the EventInterceptor
o Removed the addListener( DirectoryService ) method
o Injected the Criteria in the EventService when adding a listener in ServerConext/ServerDirContext
: the criteria was created but never used
o Added some javadoc

Added:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/DefaultEventService.java
Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/event/EventService.java
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java
    directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
    directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/EventInterceptor.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/event/EventService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/event/EventService.java?rev=1156561&r1=1156560&r2=1156561&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/event/EventService.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/event/EventService.java
Thu Aug 11 10:07:20 2011
@@ -34,15 +34,6 @@ import java.util.List;
 public interface EventService
 {
     /**
-     * Registers a DirectoryListener for notification on any and all change 
-     * events on the DIT.
-     *
-     * @param listener the DirectoryListener to deliver notifications to
-     */
-    void addListener( DirectoryListener listener );
-
-    
-    /**
      * Registers a DirectoryListener for notification on change events on the 
      * DIT matching some notification criteria.
      *

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java?rev=1156561&r1=1156560&r2=1156561&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java
Thu Aug 11 10:07:20 2011
@@ -115,7 +115,6 @@ public abstract class BaseInterceptor im
     protected static AttributeType UNIQUE_MEMBER_AT;
 
 
-
     /**
      * default interceptor name is its class, preventing accidental duplication of interceptors
by naming
      * instances differently

Modified: directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java?rev=1156561&r1=1156560&r2=1156561&view=diff
==============================================================================
--- directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
(original)
+++ directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
Thu Aug 11 10:07:20 2011
@@ -1640,7 +1640,7 @@ public abstract class ServerContext impl
             criteria.setAliasDerefMode( AliasDerefMode.getEnum( env ) );
             criteria.setBase( buildTarget( JndiUtils.fromName( name ) ) );
 
-            service.getEventService().addListener( listener );
+            service.getEventService().addListener( listener, criteria );
             listeners.put( namingListener, listener );
         }
         catch ( Exception e )

Modified: directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java?rev=1156561&r1=1156560&r2=1156561&view=diff
==============================================================================
--- directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java
(original)
+++ directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java
Thu Aug 11 10:07:20 2011
@@ -981,7 +981,7 @@ public abstract class ServerDirContext e
             criteria.setAliasDerefMode( AliasDerefMode.getEnum( getEnvironment() ) );
             criteria.setBase( buildTarget( JndiUtils.fromName( name ) ) );
 
-            getDirectoryService().getEventService().addListener( listener );
+            getDirectoryService().getEventService().addListener( listener, criteria );
             getListeners().put( namingListener, listener );
         }
         catch ( Exception e )

Added: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/DefaultEventService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/DefaultEventService.java?rev=1156561&view=auto
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/DefaultEventService.java
(added)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/DefaultEventService.java
Thu Aug 11 10:07:20 2011
@@ -0,0 +1,98 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.server.core.event;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.normalization.FilterNormalizingVisitor;
+import org.apache.directory.shared.ldap.model.filter.ExprNode;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.model.schema.normalizers.ConcreteNameComponentNormalizer;
+import org.apache.directory.shared.ldap.model.schema.normalizers.NameComponentNormalizer;
+
+/**
+ * A class implementing the EventService interface. It stores all the Listener 
+ * associated with a DirectoryService.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+class DefaultEventService implements EventService
+{
+    /** The list of RegistrationEntries being registered */
+    private List<RegistrationEntry> registrations = new CopyOnWriteArrayList<RegistrationEntry>();
+    
+    /** The DirectoryService instance */
+    private DirectoryService directoryService;
+    
+    /** A normalizer used for filters */
+    private FilterNormalizingVisitor filterNormalizer;
+
+    /**
+     * Create an instance of EventService
+     * @param directoryService The associated DirectoryService
+     * @param registrations The list of Registrations
+     */
+    public DefaultEventService( DirectoryService directoryService )
+    {
+        this.directoryService= directoryService;
+        SchemaManager schemaManager = directoryService.getSchemaManager();
+        NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer( schemaManager
);
+        filterNormalizer = new FilterNormalizingVisitor( ncn, schemaManager );
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void addListener( DirectoryListener listener, NotificationCriteria criteria )
throws Exception
+    {
+        criteria.getBase().apply( directoryService.getSchemaManager() );
+        ExprNode result = ( ExprNode ) criteria.getFilter().accept( filterNormalizer );
+        criteria.setFilter( result );
+        registrations.add( new RegistrationEntry( listener, criteria ) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void removeListener( DirectoryListener listener )
+    {
+        for ( RegistrationEntry entry : registrations )
+        {
+            if ( entry.getListener() == listener )
+            {
+                registrations.remove( entry );
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<RegistrationEntry> getRegistrationEntries()
+    {
+        return Collections.unmodifiableList( registrations );
+    }
+}

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/EventInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/EventInterceptor.java?rev=1156561&r1=1156560&r2=1156561&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/EventInterceptor.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/EventInterceptor.java
Thu Aug 11 10:07:20 2011
@@ -24,7 +24,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
@@ -40,12 +39,10 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
 import org.apache.directory.server.core.interceptor.context.OperationContext;
 import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
-import org.apache.directory.server.core.normalization.FilterNormalizingVisitor;
 import org.apache.directory.server.core.partition.ByPassConstants;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
-import org.apache.directory.shared.ldap.model.filter.ExprNode;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.schema.normalizers.ConcreteNameComponentNormalizer;
 import org.apache.directory.shared.ldap.model.schema.normalizers.NameComponentNormalizer;
@@ -61,30 +58,34 @@ import org.slf4j.LoggerFactory;
  */
 public class EventInterceptor extends BaseInterceptor
 {
+    /** A logger for this class */
     private final static Logger LOG = LoggerFactory.getLogger( EventInterceptor.class );
-
-    private List<RegistrationEntry> registrations = new CopyOnWriteArrayList<RegistrationEntry>();
-    private FilterNormalizingVisitor filterNormalizer;
+    
     private Evaluator evaluator;
     private ExecutorService executor;
 
 
-    @Override
-    public void init( DirectoryService directpryService ) throws LdapException
+    /**
+     * Initialize the event interceptor. It creates a pool of executor which will be used
+     * to call the listeners in separate threads.
+     */
+    public void init( DirectoryService directoryService ) throws LdapException
     {
         LOG.info( "Initializing ..." );
-        super.init( directpryService );
+        super.init( directoryService );
 
         NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer( schemaManager
);
-        filterNormalizer = new FilterNormalizingVisitor( ncn, schemaManager );
         evaluator = new ExpressionEvaluator( schemaManager );
         executor = new ThreadPoolExecutor( 1, 10, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(
100 ) );
 
-        this.directoryService.setEventService( new DefaultEventService() );
+        this.directoryService.setEventService( new DefaultEventService( directoryService
) );
         LOG.info( "Initialization complete." );
     }
 
 
+    /**
+     * Call the listener passing it the context.
+     */
     private void fire( final OperationContext opContext, EventType type, final DirectoryListener
listener )
     {
         switch ( type )
@@ -97,7 +98,9 @@ public class EventInterceptor extends Ba
                         listener.entryAdded( ( AddOperationContext ) opContext );
                     }
                 } );
+                
                 break;
+                
             case DELETE:
                 executor.execute( new Runnable()
                 {
@@ -106,7 +109,9 @@ public class EventInterceptor extends Ba
                         listener.entryDeleted( ( DeleteOperationContext ) opContext );
                     }
                 } );
+                
                 break;
+                
             case MODIFY:
                 executor.execute( new Runnable()
                 {
@@ -115,7 +120,9 @@ public class EventInterceptor extends Ba
                         listener.entryModified( ( ModifyOperationContext ) opContext );
                     }
                 } );
+                
                 break;
+                
             case MOVE:
                 executor.execute( new Runnable()
                 {
@@ -124,7 +131,9 @@ public class EventInterceptor extends Ba
                         listener.entryMoved( ( MoveOperationContext ) opContext );
                     }
                 } );
+                
                 break;
+
             case RENAME:
                 executor.execute( new Runnable()
                 {
@@ -133,14 +142,19 @@ public class EventInterceptor extends Ba
                         listener.entryRenamed( ( RenameOperationContext ) opContext );
                     }
                 } );
+                
                 break;
         }
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void add( NextInterceptor next, final AddOperationContext addContext ) throws
LdapException
     {
         next.add( addContext );
+        
         List<RegistrationEntry> selecting = getSelectingRegistrations( addContext.getDn(),
addContext.getEntry() );
 
         if ( selecting.isEmpty() )
@@ -158,6 +172,9 @@ public class EventInterceptor extends Ba
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void delete( NextInterceptor next, final DeleteOperationContext deleteContext
) throws LdapException
     {
         List<RegistrationEntry> selecting = getSelectingRegistrations( deleteContext.getDn(),
deleteContext.getEntry() );
@@ -178,6 +195,9 @@ public class EventInterceptor extends Ba
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void modify( NextInterceptor next, final ModifyOperationContext modifyContext
) throws LdapException
     {
         Entry oriEntry = modifyContext.getEntry();
@@ -205,6 +225,9 @@ public class EventInterceptor extends Ba
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void rename( NextInterceptor next, RenameOperationContext renameContext ) throws
LdapException
     {
         Entry oriEntry = ((ClonedServerEntry)renameContext.getEntry()).getOriginalEntry();
@@ -231,6 +254,9 @@ public class EventInterceptor extends Ba
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void moveAndRename( NextInterceptor next, final MoveAndRenameOperationContext
moveAndRenameContext ) throws LdapException
     {
         Entry oriEntry = moveAndRenameContext.getOriginalEntry();
@@ -283,26 +309,25 @@ public class EventInterceptor extends Ba
     }
 
 
-    List<RegistrationEntry> getSelectingRegistrations( Dn name, Entry entry ) throws
LdapException
+    /**
+     * Find a list of registrationEntries given an entry and a name. We check against
+     * the criteria for each registrationEntry
+     */
+    private List<RegistrationEntry> getSelectingRegistrations( Dn name, Entry entry
) throws LdapException
     {
-        if ( registrations.isEmpty() )
+        if ( directoryService.getEventService().getRegistrationEntries().isEmpty() )
         {
             return Collections.emptyList();
         }
 
         List<RegistrationEntry> selecting = new ArrayList<RegistrationEntry>();
 
-        for ( RegistrationEntry registration : registrations )
+        for ( RegistrationEntry registration : directoryService.getEventService().getRegistrationEntries()
)
         {
             NotificationCriteria criteria = registration.getCriteria();
 
             Dn base = criteria.getBase();
 
-            if ( !criteria.getFilter().isSchemaAware() )
-            {
-                criteria.getFilter().accept( filterNormalizer );
-            }
-
             // fix for DIRSERVER-1502
             if ( ( name.equals( base ) || name.isDescendantOf( base ) )
                 && evaluator.evaluate( criteria.getFilter(), base, entry ) )
@@ -313,49 +338,4 @@ public class EventInterceptor extends Ba
 
         return selecting;
     }
-
-    // -----------------------------------------------------------------------
-    // EventService Inner Class
-    // -----------------------------------------------------------------------
-
-    class DefaultEventService implements EventService
-    {
-        /*
-         * Does not need normalization since default values in criteria is used.
-         */
-        public void addListener( DirectoryListener listener )
-        {
-            registrations.add( new RegistrationEntry( listener ) );
-        }
-
-
-        /*
-         * Normalizes the criteria filter and the base.
-         */
-        public void addListener( DirectoryListener listener, NotificationCriteria criteria
) throws Exception
-        {
-            criteria.getBase().apply( directoryService.getSchemaManager() );
-            ExprNode result = ( ExprNode ) criteria.getFilter().accept( filterNormalizer
);
-            criteria.setFilter( result );
-            registrations.add( new RegistrationEntry( listener, criteria ) );
-        }
-
-
-        public void removeListener( DirectoryListener listener )
-        {
-            for ( RegistrationEntry entry : registrations )
-            {
-                if ( entry.getListener() == listener )
-                {
-                    registrations.remove( entry );
-                }
-            }
-        }
-
-
-        public List<RegistrationEntry> getRegistrationEntries()
-        {
-            return Collections.unmodifiableList( registrations );
-        }
-    }
 }



Mime
View raw message