You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by oa...@apache.org on 2001/12/19 17:50:05 UTC

cvs commit: jakarta-commons-sandbox/services/src/java/org/apache/commons/services EventModule.java

oalexeev    01/12/19 08:50:05

  Modified:    services/src/java/org/apache/commons/services
                        EventModule.java
  Log:
  Add keyed pool to serve Events generation and pooling.
  
  Revision  Changes    Path
  1.2       +58 -23    jakarta-commons-sandbox/services/src/java/org/apache/commons/services/EventModule.java
  
  Index: EventModule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/services/src/java/org/apache/commons/services/EventModule.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EventModule.java	2001/12/17 16:38:18	1.1
  +++ EventModule.java	2001/12/19 16:50:05	1.2
  @@ -8,36 +8,71 @@
   
   package org.apache.commons.services;
   
  +import java.util.Map;
  +import java.util.HashMap;
  +import org.apache.commons.pool.impl.GenericKeyedObjectPool;
  +
   /** Event module. Generate events.
    * 
  - *  @version $Id: EventModule.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
  + *  @version $Id: EventModule.java,v 1.2 2001/12/19 16:50:05 oalexeev Exp $
    *  @author Oleg V Alexeev
    */
   public class EventModule extends Module {
   
  +        protected EventRegistration defaultEventRegistration = null;
  +
  +        protected Map eventRegistrations = new HashMap();
  +
  +        protected GenericKeyedObjectPool pool = null;
  +
  +        public void releaseEvent( Event event ) {
  +                pool.returnObject( event.getEventRegistration().getName(), event );
  +        }
  +
  +        public EventModule() {
  +                pool = new GenericKeyedObjectPool( createEventFactory() );
  +                defaultEventRegistration = createDefaultEventRegistration();
  +        }
  +
  +        protected EventFactory createEventFactory() {
  +                EventFactory eventFactory = new EventFactory();
  +                eventFactory.setEventModule( this );
  +                return eventFactory;
  +        }
  +
  +        protected EventRegistration createDefaultEventRegistration() {
  +                return new EventRegistration();
  +        }
  +
  +        public void addEventRegistration( EventRegistration eventRegistration ) {
  +                eventRegistrations.add( eventRegistration.getName(), eventRegistration );
  +        }
  +
  +        public void init() {
  +                eventRegistrations.clear();
  +                pool.clear();
  +        }
  +
  +        public void destroy() {
  +                eventRegistrations.clear();
  +                pool.clear();
  +                pool.close();
  +        }
  +
  +        public EventRegistration getEventRegistration( String key ) {
  +                EventRegistration eventRegistration = (EventRegistration)eventRegistrations.get( key );
  +                if( eventRegistration==null ) {
  +                        eventRegistration = defaultEventRegistration;
  +                }
  +                return eventRegistration;
  +        }
  +
           public Event getEvent( String name ) throws Exception {
  -                Event event = retrieveEvent( name );
  -                if( event==null ) {
  -                        if( strongCheck ) {
  -                                throw new Exception( "Can not find event for name" );
  -                        } else {
  -                                return getDefaultEvent();
  -                        }
  -                } else {
  -                        return event;
  -                }       
  -        }
  -
  -        public Event getDefaultEvent() {
  -                Event event = new Event();
  -                event.setParentModule( this );
  -                return event;
  -        }
  -
  -        protected Event retrieveEvent( String name ) {
  -                Event event = new Event();
  -                event.setParentModule( this );
  -                return event;
  +                return (Event)pool.borrowObject( name );
  +        }
  +
  +        public Event getDefaultEvent() throws Exception {
  +                return (Event)pool.borrowObject( defaultEventRegistration.getName() );
           }
   
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>