Return-Path: Delivered-To: apmail-incubator-directory-cvs-archive@www.apache.org Received: (qmail 30807 invoked from network); 3 Feb 2004 06:54:13 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 3 Feb 2004 06:54:13 -0000 Received: (qmail 22954 invoked by uid 500); 3 Feb 2004 06:53:51 -0000 Delivered-To: apmail-incubator-directory-cvs-archive@incubator.apache.org Received: (qmail 22907 invoked by uid 500); 3 Feb 2004 06:53:50 -0000 Mailing-List: contact directory-cvs-help@incubator.apache.org; run by ezmlm Precedence: bulk Reply-To: directory-dev@incubator.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list directory-cvs@incubator.apache.org Received: (qmail 22891 invoked from network); 3 Feb 2004 06:53:50 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 3 Feb 2004 06:53:50 -0000 Received: (qmail 30763 invoked by uid 65534); 3 Feb 2004 06:54:12 -0000 Date: 3 Feb 2004 06:54:12 -0000 Message-ID: <20040203065412.30761.qmail@minotaur.apache.org> From: akarasulu@apache.org To: directory-cvs@incubator.apache.org Subject: svn commit: rev 6447 - in incubator/directory/eve/trunk/eve/frontend/event: impl merlin-impl merlin-impl/conf merlin-impl/src/java/org/apache/eve/event pojo-impl pojo-impl/src pojo-impl/src/docbook pojo-impl/src/images pojo-impl/src/java pojo-impl/src/java/org pojo-impl/src/java/org/apache pojo-impl/src/java/org/apache/eve pojo-impl/src/java/org/apache/eve/event X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: akarasulu Date: Mon Feb 2 22:54:11 2004 New Revision: 6447 Added: incubator/directory/eve/trunk/eve/frontend/event/merlin-impl/ (props changed) - copied from rev 6407, incubator/directory/eve/trunk/eve/frontend/event/impl/ incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/ incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/project.properties incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/project.xml incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/src/ incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/src/docbook/ incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/src/images/ incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/src/java/ incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/src/java/org/ incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/src/java/org/apache/ incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/src/java/org/apache/eve/ incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/src/java/org/apache/eve/event/ incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/src/java/org/apache/eve/event/DefaultEventRouter.java Removed: incubator/directory/eve/trunk/eve/frontend/event/impl/ incubator/directory/eve/trunk/eve/frontend/event/merlin-impl/src/java/org/apache/eve/event/DefaultEventRouter.java Modified: incubator/directory/eve/trunk/eve/frontend/event/merlin-impl/conf/block.xml incubator/directory/eve/trunk/eve/frontend/event/merlin-impl/project.xml Log: making things conform to proposed layout Modified: incubator/directory/eve/trunk/eve/frontend/event/merlin-impl/conf/block.xml ============================================================================== --- incubator/directory/eve/trunk/eve/frontend/event/impl/conf/block.xml (original) +++ incubator/directory/eve/trunk/eve/frontend/event/merlin-impl/conf/block.xml Mon Feb 2 22:54:11 2004 @@ -7,6 +7,7 @@ + Modified: incubator/directory/eve/trunk/eve/frontend/event/merlin-impl/project.xml ============================================================================== --- incubator/directory/eve/trunk/eve/frontend/event/impl/project.xml (original) +++ incubator/directory/eve/trunk/eve/frontend/event/merlin-impl/project.xml Mon Feb 2 22:54:11 2004 @@ -2,7 +2,7 @@ ${basedir}/../../../project.xml directory - eve-frontend-event-impl + eve-frontend-event-merlin-impl Eve Frontend Event Implementation org.apache.eve.event @@ -35,6 +35,13 @@ directory eve-frontend-event-spi + SNAPSHOT + http://directory.apache.org + + + + directory + eve-frontend-event-pojo-impl SNAPSHOT http://directory.apache.org Added: incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/project.properties ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/project.properties Mon Feb 2 22:54:11 2004 @@ -0,0 +1,3 @@ +maven.xdoc.date=left +maven.xdoc.version=${pom.currentVersion} +merlin.debug=true Added: incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/project.xml ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/project.xml Mon Feb 2 22:54:11 2004 @@ -0,0 +1,44 @@ + + + ${basedir}/../../../project.xml + directory + eve-frontend-event-pojo-impl + + Eve Frontend Event POJO Implementation + org.apache.eve.event + SNAPSHOT + 2003 + + + Event router implementation used by Eve's frontend + + + + Event notification service implementation. + + + + + + directory + eve-frontend-common-api + SNAPSHOT + http://directory.apache.org + + + + directory + eve-frontend-event-spi + SNAPSHOT + http://directory.apache.org + + + + junit + junit + 3.8.1 + http://junit.org + + + + Added: incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/src/java/org/apache/eve/event/DefaultEventRouter.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/eve/frontend/event/pojo-impl/src/java/org/apache/eve/event/DefaultEventRouter.java Mon Feb 2 22:54:11 2004 @@ -0,0 +1,227 @@ +/* + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Eve Directory Server", "Apache Directory Project", "Apache Eve" + and "Apache Software Foundation" must not be used to endorse or promote + products derived from this software without prior written + permission. For written permission, please contact apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation. For more information on the + Apache Software Foundation, please see . + +*/ +package org.apache.eve.event ; + + +import java.util.Set ; +import java.util.HashSet ; +import java.util.Iterator ; +import java.util.EventObject ; + + +/** + * An synchronous implementation of the event router / notification pattern. + * + * @author Alex Karasulu + * @author $Author: akarasulu $ + * @version $Rev: 1452 $ + */ +public class DefaultEventRouter implements EventRouter +{ + /** the set of subscriptions made with this router */ + private Set m_subscriptions = new HashSet() ; + /** the monitor - initially set to the null monitor */ + private EventRouterMonitor m_monitor = new EventRouterMonitorAdapter() ; + + + /** + * @see org.apache.eve.event.EventRouter#subscribe(java.lang.Class, + * org.apache.eve.event.Filter, org.apache.eve.event.Subscriber) + */ + public void subscribe( Class a_type, Filter a_filter, + Subscriber a_subscriber ) + { + if ( ! EventObject.class.isAssignableFrom( a_type ) ) + { + throw new IllegalArgumentException( "Invalid event class: " + + a_type.getName() ) ; + } + + Subscription l_subscription = + new Subscription( a_type, a_filter, a_subscriber ) ; + + if ( ! m_subscriptions.contains( l_subscription ) ) + { + synchronized ( m_subscriptions ) + { + m_subscriptions.add( l_subscription ) ; + } + + m_monitor.addedSubscription( l_subscription ) ; + } + } + + + /** + * @see org.apache.eve.event.EventRouter#unsubscribe( + * org.apache.eve.event.Subscriber) + */ + public void unsubscribe( Subscriber a_subscriber ) + { + Iterator l_list = m_subscriptions.iterator() ; + + synchronized ( m_subscriptions ) + { + while ( l_list.hasNext() ) + { + Subscription l_subscription = ( Subscription ) l_list.next() ; + if ( a_subscriber == l_subscription.getSubscriber() ) + { + l_list.remove() ; + m_monitor.removedSubscription( l_subscription ) ; + } + } + } + } + + + /** + * (non-Javadoc) + * @see org.apache.eve.event.EventRouter#unsubscribe(java.lang.Class, + * org.apache.eve.event.Subscriber) + */ + public void unsubscribe( Class a_type, Subscriber a_subscriber ) + { + Iterator l_list = m_subscriptions.iterator() ; + + synchronized ( m_subscriptions ) + { + while ( l_list.hasNext() ) + { + Subscription l_subscription = ( Subscription ) l_list.next() ; + if ( a_subscriber == l_subscription.getSubscriber() + && a_type.equals( l_subscription.getType() ) ) + { + l_list.remove() ; + m_monitor.removedSubscription( l_subscription ) ; + } + } + } + } + + + /** + * (non-Javadoc) + * @see org.apache.eve.event.EventRouter#unsubscribe(java.lang.Class, + * org.apache.eve.event.Subscriber) + */ + public void unsubscribe( Class a_type, Filter a_filter, + Subscriber a_subscriber ) + { + if ( ! EventObject.class.isAssignableFrom( a_type ) ) + { + throw new IllegalArgumentException( "Invalid event class: " + + a_type.getName() ) ; + } + + final Subscription l_subscription = new Subscription( a_type, a_filter, + a_subscriber ) ; + + synchronized ( m_subscriptions ) + { + m_subscriptions.remove( l_subscription ) ; + } + } + + + /** + * (non-Javadoc) + * @see org.apache.eve.event.EventRouter#publish(org.apache.eve.event.Event) + */ + public void publish( EventObject a_event ) + { + final Subscription [] l_subscriptions ; + + synchronized ( m_subscriptions ) + { + l_subscriptions = ( Subscription [] ) m_subscriptions + .toArray( new Subscription [ m_subscriptions.size() ] ) ; + } + + for ( int ii = 0; ii < l_subscriptions.length; ii++ ) + { + boolean isAssignable = l_subscriptions[ii].getType() + .isAssignableFrom( a_event.getClass() ) ; + + if ( ! isAssignable ) + { + continue ; + } + + if ( l_subscriptions[ii].getFilter() != null && + l_subscriptions[ii].getFilter().apply( a_event ) ) + { + l_subscriptions[ii].getSubscriber().inform( a_event ) ; + } + } + } + + + /** + * Sets the event router's monitor. + * + * @param a_monitor the monitor + */ + void setMonitor( EventRouterMonitor a_monitor ) + { + m_monitor = a_monitor ; + } + + + /** + * Gets the event router's monitor. + * + * @return the monitor + */ + EventRouterMonitor getMonitor() + { + return m_monitor ; + } +}