commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oalex...@apache.org
Subject cvs commit: jakarta-commons-sandbox/services/src/java/org/apache/commons/services ConfigObjectCreateRule.java EventModule.java EventRegistration.java InitConfigRule.java Leaf.java Queue.java QueueModule.java ServiceManager.java ServiceModule.java
Date Wed, 30 Jan 2002 09:26:02 GMT
oalexeev    02/01/30 01:26:02

  Modified:    services/src/java/org/apache/commons/services
                        ConfigObjectCreateRule.java EventModule.java
                        EventRegistration.java InitConfigRule.java
                        Leaf.java Queue.java QueueModule.java
                        ServiceManager.java ServiceModule.java
  Log:
  Finish digester related code.
  
  Revision  Changes    Path
  1.2       +2 -2      jakarta-commons-sandbox/services/src/java/org/apache/commons/services/ConfigObjectCreateRule.java
  
  Index: ConfigObjectCreateRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/services/src/java/org/apache/commons/services/ConfigObjectCreateRule.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConfigObjectCreateRule.java	22 Jan 2002 18:44:34 -0000	1.1
  +++ ConfigObjectCreateRule.java	30 Jan 2002 09:26:02 -0000	1.2
  @@ -17,7 +17,7 @@
   
   /** 
    * @author Oleg V Alexeev
  - * @version $Revision: 1.1 $ $Date: 2002/01/22 18:44:34 $
  + * @version $Revision: 1.2 $ $Date: 2002/01/30 09:26:02 $
    */
   public class ConfigObjectCreateRule extends ObjectCreateRule {
   
  @@ -44,7 +44,7 @@
                           ((ConfigObject)configObject).initDigester( 
                                   digester, initialPath );
                           if (digester.getLogger().isDebugEnabled()) {
  -                                digester.getLogger().debug("Call to the initDigester()
for " 
  +                                digester.getLogger().debug("Call to the initDigester()
for ConfigObject instance - " 
                                           + configObject.getClass().getName());
                           }
                   }
  
  
  
  1.5       +15 -18    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- EventModule.java	22 Jan 2002 18:44:34 -0000	1.4
  +++ EventModule.java	30 Jan 2002 09:26:02 -0000	1.5
  @@ -12,10 +12,11 @@
   import java.util.HashMap;
   import org.apache.commons.pool.impl.GenericKeyedObjectPool;
   import org.apache.commons.digester.Digester;
  +import org.apache.commons.digester.ObjectCreateRule;
   
   /** Event module. Generate events.
    * 
  - *  @version $Id: EventModule.java,v 1.4 2002/01/22 18:44:34 oalexeev Exp $
  + *  @version $Id: EventModule.java,v 1.5 2002/01/30 09:26:02 oalexeev Exp $
    *  @author Oleg V Alexeev
    */
   public class EventModule extends Module {
  @@ -78,23 +79,19 @@
   
           public Digester initDigester( Digester digester, String path ) {
   
  -                if( path!=null )
  -                        path += "/";
  -                else
  -                        path = "";
  -
  -                String serviceManagerPath =
  -                        path + "service-manager";
  -
  -                String eventsRegistrationPath =
  -                        serviceManagerPath + "/event-module";
  -
  -                String servicesRegistrationPath =
  -                        serviceManagerPath + "/service-module";
  -
  -                String queuesRegistrationPath =
  -                        serviceManagerPath + "/queue-module";
  -                
  +                if( path==null || path.length()==0 )
  +                        throw new IllegalArgumentException( "Module can not be used alone.
The path argument is mandatory." );
  +
  +                String eventPath = 
  +                        path + "event";
  +
  +                digester.addRule( eventPath,
  +                        new ObjectCreateRule( digester, 
  +                        "org.apache.commons.services.EventRegistration", "type" ) );
  +                digester.addSetNext( eventPath, "addEventRegistration",
  +                        "org.apache.commons.services.EventRegistration" );
  +                digester.addSetProperties( eventPath );
  +
                   return digester;
           }
   
  
  
  
  1.2       +2 -2      jakarta-commons-sandbox/services/src/java/org/apache/commons/services/EventRegistration.java
  
  Index: EventRegistration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/services/src/java/org/apache/commons/services/EventRegistration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EventRegistration.java	19 Dec 2001 16:33:08 -0000	1.1
  +++ EventRegistration.java	30 Jan 2002 09:26:02 -0000	1.2
  @@ -10,7 +10,7 @@
   
   /** Event registration.
    * 
  - *  @version $Id: EventRegistration.java,v 1.1 2001/12/19 16:33:08 oalexeev Exp $
  + *  @version $Id: EventRegistration.java,v 1.2 2002/01/30 09:26:02 oalexeev Exp $
    *  @author Oleg V Alexeev
    */
   public class EventRegistration {
  @@ -35,4 +35,4 @@
                   this.name = name;
           }
   
  -}
  \ No newline at end of file
  +}
  
  
  
  1.2       +6 -6      jakarta-commons-sandbox/services/src/java/org/apache/commons/services/InitConfigRule.java
  
  Index: InitConfigRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/services/src/java/org/apache/commons/services/InitConfigRule.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InitConfigRule.java	22 Jan 2002 18:44:34 -0000	1.1
  +++ InitConfigRule.java	30 Jan 2002 09:26:02 -0000	1.2
  @@ -16,19 +16,19 @@
   
   /** 
    * @author Oleg V Alexeev
  - * @version $Revision: 1.1 $ $Date: 2002/01/22 18:44:34 $
  + * @version $Revision: 1.2 $ $Date: 2002/01/30 09:26:02 $
    */
   public class InitConfigRule extends Rule {
   
  -        protected ServiceManager serviceManager = null;
  +        protected ConfigObject configObject = null;
           
  -        public InitConfigRule( Digester digester, ServiceManager serviceManager ) {
  +        public InitConfigRule( Digester digester, ConfigObject configObject ) {
                   super( digester );
  -                this.serviceManager = serviceManager;
  +                this.configObject = configObject;
           }
   
           public void begin( Attributes attributes ) throws Exception {
  -                digester.push( serviceManager );
  +                digester.push( configObject );
           }
   
           public void end() throws Exception {
  @@ -36,7 +36,7 @@
           }
   
           public void finish() throws Exception {
  -                serviceManager = null;
  +                configObject = null;
           }
   
   }
  
  
  
  1.2       +11 -1     jakarta-commons-sandbox/services/src/java/org/apache/commons/services/Leaf.java
  
  Index: Leaf.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/services/src/java/org/apache/commons/services/Leaf.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Leaf.java	17 Dec 2001 16:38:18 -0000	1.1
  +++ Leaf.java	30 Jan 2002 09:26:02 -0000	1.2
  @@ -12,7 +12,7 @@
   
   /** Base class for all 'leaf' classes - Event, Service, Queue.
    *  
  - *  @version $Id: Leaf.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
  + *  @version $Id: Leaf.java,v 1.2 2002/01/30 09:26:02 oalexeev Exp $
    *  @author Oleg V Alexeev
    */
   public class Leaf implements Serializable {
  @@ -25,6 +25,16 @@
   
           public void setParentModule( Module parentModule ) {
                   this.parentModule = parentModule;
  +        }
  +
  +        protected String name = null;
  +
  +        public String getName() {
  +                return name;
  +        }
  +
  +        public void setName( String name ) {
  +                this.name = name;
           }
   
           public void init() {
  
  
  
  1.2       +2 -7      jakarta-commons-sandbox/services/src/java/org/apache/commons/services/Queue.java
  
  Index: Queue.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/services/src/java/org/apache/commons/services/Queue.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Queue.java	17 Dec 2001 16:38:18 -0000	1.1
  +++ Queue.java	30 Jan 2002 09:26:02 -0000	1.2
  @@ -14,7 +14,7 @@
    *  walk throw all services in ServiceManager and pass event to 
    *  every of them.
    * 
  - *  @version $Id: Queue.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
  + *  @version $Id: Queue.java,v 1.2 2002/01/30 09:26:02 oalexeev Exp $
    *  @author Oleg V Alexeev
    */
   public class Queue extends Leaf {
  @@ -34,14 +34,9 @@
                   Service service = null;
                   Iterator iterator = parentModule.getServiceManager().getServiceModule().getServices();
   
  -                System.out.println( "Execute in queue '" + this.getClass().getName() +
"'" );
  -                System.out.println( "for event '" + event.getClass().getName() + "'" );
  -                
                   while( iterator.hasNext() ) {
                           service = (Service)iterator.next();
   
  -                System.out.println( "Execute for service '" + service.getClass().getName()
+ "'" );
  -
                           if( service==null ) {
                                   if( strongCheck ) {
                                           throw new Exception( "Service not available!" );
  @@ -59,4 +54,4 @@
                   strongCheck = false;
           }
   
  -}
  \ No newline at end of file
  +}
  
  
  
  1.3       +19 -3     jakarta-commons-sandbox/services/src/java/org/apache/commons/services/QueueModule.java
  
  Index: QueueModule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/services/src/java/org/apache/commons/services/QueueModule.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- QueueModule.java	22 Jan 2002 18:44:34 -0000	1.2
  +++ QueueModule.java	30 Jan 2002 09:26:02 -0000	1.3
  @@ -15,7 +15,7 @@
   
   /** QueueModule - manages queues.
    * 
  - *  @version $Id: QueueModule.java,v 1.2 2002/01/22 18:44:34 oalexeev Exp $
  + *  @version $Id: QueueModule.java,v 1.3 2002/01/30 09:26:02 oalexeev Exp $
    *  @author Oleg V Alexeev
    */
   public class QueueModule extends Module {
  @@ -59,8 +59,8 @@
                   defaultQueue = null;
           }
   
  -        public void addQueue( String name, Queue queue ) {
  -                queues.put( name, queue );
  +        public void addQueue( Queue queue ) {
  +                queues.put( queue.getName(), queue );
                   queue.setParentModule( this );
           }
   
  @@ -86,7 +86,23 @@
           }
   
           public Digester initDigester( Digester digester, String path ) {
  +
  +                if( path==null || path.length()==0 )
  +                        throw new IllegalArgumentException( "Module can not be used alone.
The path argument is mandatory." );
  +
  +                String queuePath = 
  +                        path + "queue";
  +
  +                //FIXIT - replace class name with configurable property
  +                digester.addRule( queuePath,
  +                        new ConfigObjectCreateRule( digester, 
  +                        "org.apache.commons.services.SequenceQueue", "type", 
  +                        queuePath ) );
  +                digester.addSetNext( queuePath, "addQueue",
  +                        "org.apache.commons.services.Queue" );
  +
                   return digester;
  +
           }
   
   }
  
  
  
  1.6       +27 -17    jakarta-commons-sandbox/services/src/java/org/apache/commons/services/ServiceManager.java
  
  Index: ServiceManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/services/src/java/org/apache/commons/services/ServiceManager.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ServiceManager.java	22 Jan 2002 18:44:34 -0000	1.5
  +++ ServiceManager.java	30 Jan 2002 09:26:02 -0000	1.6
  @@ -17,13 +17,13 @@
   /** 
    *  Core class in package.
    * 
  - *  @version $Id: ServiceManager.java,v 1.5 2002/01/22 18:44:34 oalexeev Exp $
  + *  @version $Id: ServiceManager.java,v 1.6 2002/01/30 09:26:02 oalexeev Exp $
    *  @author Oleg V Alexeev
    */
  -public class ServiceManager implements Serializable {
  +public class ServiceManager implements Serializable, ConfigObject {
   
           public static int DEFAULT_LOG_LEVEL =
  -            org.apache.commons.logging.SimpleLog.LOG_LEVEL_OFF;
  +            org.apache.commons.logging.SimpleLog.LOG_LEVEL_ALL;
   
           protected EventModule eventModule = null;
   
  @@ -59,6 +59,7 @@
           public void setEventModule( EventModule eventModule ) {
                   this.eventModule = eventModule;
                   this.eventModule.setServiceManager( this );
  +                log.debug( "Set EventModule of class " + eventModule.getClass().getName()
);
           }
   
           public ServiceModule getServiceModule() {
  @@ -68,6 +69,7 @@
           public void setServiceModule( ServiceModule serviceModule ) {
                   this.serviceModule = serviceModule;
                   this.serviceModule.setServiceManager( this );
  +                log.debug( "Set ServiceModule of class " + serviceModule.getClass().getName()
);
           }
   
           public QueueModule getQueueModule() {
  @@ -77,10 +79,7 @@
           public void setQueueModule( QueueModule queueModule ) {
                   this.queueModule = queueModule;
                   this.queueModule.setServiceManager( this );
  -        }
  -
  -        public String getConfigURI() {
  -                return "";
  +                log.debug( "Set QueueModule of class " + queueModule.getClass().getName()
);
           }
   
           public Digester initDigester( Digester digester, String path ) {
  @@ -115,22 +114,25 @@
                           eventsRegistrationPath ) );
                   digester.addSetNext( eventsRegistrationPath, "setEventModule",
                           "org.apache.commons.services.EventModule" );
  +                digester.addSetProperties( eventsRegistrationPath );
   
                   // Init services
                   digester.addRule( servicesRegistrationPath, 
                           new ConfigObjectCreateRule( digester,
                           "org.apache.commons.services.ServiceModule", "type",
                           servicesRegistrationPath ) );
  -                digester.addSetNext( eventsRegistrationPath, "setServiceModule",
  +                digester.addSetNext( servicesRegistrationPath, "setServiceModule",
                           "org.apache.commons.services.ServiceModule" );
  +                digester.addSetProperties( servicesRegistrationPath );
   
                   // Init queues
                   digester.addRule( queuesRegistrationPath, 
                           new ConfigObjectCreateRule( digester,
                           "org.apache.commons.services.QueueModule", "type",
                           queuesRegistrationPath ) );
  -                digester.addSetNext( eventsRegistrationPath, "setQueueModule",
  +                digester.addSetNext( queuesRegistrationPath, "setQueueModule",
                           "org.apache.commons.services.QueueModule" );
  +                digester.addSetProperties( queuesRegistrationPath );
   
                   //----------------------------
   
  @@ -138,21 +140,29 @@
   
           }
   
  -        public void init() {
  +        public void init( String configURI ) {
                   Digester digester = initDigester( new Digester(), null );
  +                digester.setLogger( log );
                   try {
  -                        digester.parse( getConfigURI() );
  +                        digester.parse( configURI );
                   } catch ( Exception e ) {
  +                        log.error( "Exception at ServiceManager.init()", e );
                   }
           }
   
           public void destroy() {
  -                eventModule.destroy();
  -                eventModule = null;
  -                serviceModule.destroy();
  -                serviceModule = null;
  -                queueModule.destroy();
  -                queueModule = null;
  +                if( eventModule!=null ) {
  +                        eventModule.destroy();
  +                        eventModule = null;
  +                }
  +                if( serviceModule!=null ) {
  +                        serviceModule.destroy();
  +                        serviceModule = null;
  +                }
  +                if( queueModule!=null ) {
  +                        queueModule.destroy();
  +                        queueModule = null;
  +                }
           }
   
           public Object execute() throws Exception {
  
  
  
  1.3       +16 -3     jakarta-commons-sandbox/services/src/java/org/apache/commons/services/ServiceModule.java
  
  Index: ServiceModule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/services/src/java/org/apache/commons/services/ServiceModule.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ServiceModule.java	22 Jan 2002 18:44:34 -0000	1.2
  +++ ServiceModule.java	30 Jan 2002 09:26:02 -0000	1.3
  @@ -15,7 +15,7 @@
   
   /** ServiceModule manages services. 
    * 
  - *  @version $Id: ServiceModule.java,v 1.2 2002/01/22 18:44:34 oalexeev Exp $
  + *  @version $Id: ServiceModule.java,v 1.3 2002/01/30 09:26:02 oalexeev Exp $
    *  @author Oleg V Alexeev
    */
   public class ServiceModule extends Module {
  @@ -49,8 +49,8 @@
                   services = null;
           }
   
  -        public void addService( String name, Service service ) {
  -                services.put( name, service );
  +        public void addService( Service service ) {
  +                services.put( service.getName(), service );
                   service.setParentModule( this );
           }
   
  @@ -72,6 +72,19 @@
           }
   
           public Digester initDigester( Digester digester, String path ) {
  +
  +                if( path==null || path.length()==0 )
  +                        throw new IllegalArgumentException( "Module can not be used alone.
The path argument is mandatory." );
  +
  +                String servicePath = 
  +                        path + "service";
  +
  +                // FIXIT!
  +                digester.addRule( servicePath,
  +                        new ConfigObjectCreateRule( digester, "", "type", servicePath )
);
  +                digester.addSetNext( servicePath, "addService",
  +                        "org.apache.commons.services.Service" );
  +
                   return digester;
           }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message