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/17 17:38:18 UTC

cvs commit: jakarta-commons-sandbox/services/src/java/org/apache/commons/services Event.java EventModule.java Leaf.java LogEvent.java LogService.java Module.java Queue.java QueueModule.java SequenceQueue.java Service.java ServiceManager.java ServiceModule.java

oalexeev    01/12/17 08:38:18

  Added:       services .cvsignore LICENSE PROPOSAL.html
                        build.properties.sample build.xml
               services/src/java/org/apache/commons/services Event.java
                        EventModule.java Leaf.java LogEvent.java
                        LogService.java Module.java Queue.java
                        QueueModule.java SequenceQueue.java Service.java
                        ServiceManager.java ServiceModule.java
  Log:
  Initial load of services subproject.
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/services/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  dist
  target
  build.properties
  
  
  1.1                  jakarta-commons-sandbox/services/LICENSE
  
  Index: LICENSE
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", 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 names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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
   * <http://www.apache.org/>.
   */
  
  
  
  
  1.1                  jakarta-commons-sandbox/services/PROPOSAL.html
  
  Index: PROPOSAL.html
  ===================================================================
  <html>
  <head>
  <title>Proposal for Service Manager</title>
  </head>
  <body bgcolor="white">
  
  <div align="center">
  <h1>Proposal for <em>Service Manager</em> Package</h1>
  </div>
  
  <h3>(0) Rationale</h3>
  
  <p>
  Some projects (Jakarta-Struts, for example... 8) ) needs for extending by 
  the multiple ways. And each extending is core API modification, which  
  sometimes is not so neccessary for every developer. Service Manager add 
  ability to any framework use pluggable Service modules as config-based 
  extensions.
  </p>
  
  <h3>(1) Scope of the Package</h3>
  
  <p>
  Service Manager Package can be used as some kind of universal bridge from 
  central application to the exteranl modules.
  </p>
  
  <p>
  The package should :
  <ul>
  <li>Have an API which should be as simple to use as possible</li>
  <li>Provide ability to plug additional modules without recompilation.</li>
  <li>Use Digester as configuration reader.</li>
  <li>Build 'live' configuration model for pluggable Services with ability 
  to extend Digester rules at process of configuration reading and specify 
  its own configuration inside of Service configuration tag.</li> 
  <li>Make ServiceManager's config plugguble into parent application config 
  reader if it is based on Digester.</li> 
  </ul>
  </p>
  
  <h3>(1.5) Interaction With Other Packages</h3>
  
  <p><em>Services</em> relies on:
  </p>
  
  <ul>
    <li>Java Development Kit (Version 1.3 or later)
    </li>
    <li>commons-digester</li>
    <li>commons-beanutils</li>
    <li>commons-collections</li>
    <li>commons-logging</li>
  </ul>
  
  <h3>(2) Required Jakarta-Commons Resources</h3>
  
  <ul>
  
  <li>CVS Repository - New directory <code>services</code> in the 
  <code>jakarta-commons-sandbox</code> CVS repository.</li>
  
  <li>Initial Committers - The list is provided below. </li>
  
  <li>Mailing List - Discussions will take place on the general
  <em>jakarta-commons@jakarta.apache.org</em> mailing list. To help list
  subscribers identify messages of interest, it is suggested that the
  message subject of messages about this component be prefixed with
  [Services].</li>
  
  <li>Bugzilla - New component "Servises" under the "Commons" product
  category, with appropriate version identifiers as needed.</li>
  
  <li>Jyve FAQ - New category "commons-services" (when available).</li>
  </ul>
  
  
  <h3>(4) Initial Committers</h3>
  
  <p>The initial committers on the Service Manager component shall be:</p>
  
  <ul>
    <li>Oleg V Alexeev</li>
  </ul>
  
  </body>
  </html>
  
  
  
  1.1                  jakarta-commons-sandbox/services/build.properties.sample
  
  Index: build.properties.sample
  ===================================================================
  commons-beanutils.jar=../../jakarta-commons/beanutils/dist/commons-beanutils.jar
  commons-collections.jar=../../jakarta-commons/collections/dist/commons-collections.jar
  commons-digester.jar=../../jakarta-commons/digester/dist/commons-digester.jar
  commons-logging.jar=../../jakarta-commons/logging/dist/commons-logging.jar
  
  
  
  1.1                  jakarta-commons-sandbox/services/build.xml
  
  Index: build.xml
  ===================================================================
  <project name="Services" default="compile" basedir=".">
  
  
  <!--
          "Services" component of the Jakarta Commons Subproject
          $Id: build.xml,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
  -->
  
  
  <!-- ========== Initialize Properties ===================================== -->
  
  
    <property file="build.properties"/>                <!-- Component local   -->
    <property file="../build.properties"/>             <!-- Commons local     -->
    <property file="${user.home}/build.properties"/>   <!-- User local        -->
  
  
  <!-- ========== External Dependencies ===================================== -->
  
  
    <!-- The directories corresponding to your necessary dependencies -->
    <property name="commons-collections.jar" value="../../jakarta-commons/collections/dist/commons-collections.jar"/>
    <property name="commons-beanutils.jar"   value="../../jakarta-commons/beanutils/dist/commons-beanutils.jar"/>
    <property name="commons-digester.jar"    value="../../jakarta-commons/digester/dist/commons-digester.jar"/>
    <property name="commons-logging.jar"    value="../../jakarta-commons/logging/dist/commons-logging.jar"/>
  
  
  <!-- ========== Component Declarations ==================================== -->
  
  
    <!-- The name of this component -->
    <property name="component.name"          value="services"/>
  
    <!-- The title of this component -->
    <property name="component.title"         value="Service Manager Library"/>
  
    <!-- The current version number of this component -->
    <property name="component.version"       value="1.0-dev"/>
  
    <!-- The base directory for compilation targets -->
    <property name="build.home"              value="target"/>
  
    <!-- The base directory for component configuration files -->
    <property name="conf.home"               value="src/conf"/>
  
    <!-- The base directory for distribution targets -->
    <property name="dist.home"               value="dist"/>
  
    <!-- The base directory for component sources -->
    <property name="source.home"             value="src/java"/>
  
    <!-- The base directory for unit test sources -->
    <property name="test.home"               value="src/test"/>
  
  <!-- ========== Compiler Defaults ========================================= -->
  
  
    <!-- Should Java compilations set the 'debug' compiler option? -->
    <property name="compile.debug"           value="true"/>
  
    <!-- Should Java compilations set the 'deprecation' compiler option? -->
    <property name="compile.deprecation"     value="false"/>
  
    <!-- Should Java compilations set the 'optimize' compiler option? -->
    <property name="compile.optimize"        value="true"/>
  
    <!-- Construct compile classpath -->
    <path id="compile.classpath">
      <pathelement location="${commons-collections.jar}"/>
      <pathelement location="${commons-beanutils.jar}"/>
      <pathelement location="${commons-digester.jar}"/>
      <pathelement location="${commons-logging.jar}"/>
    </path>
  
  
  <!-- ========== Executable Targets ======================================== -->
  
  
    <target name="init" description="Initialize and evaluate conditionals">
      <echo message="-------- ${component.title} ${component.version} --------"/>
      <filter  token="name"                  value="${component.name}"/>
      <filter  token="version"               value="${component.version}"/>
    </target>
  
  
    <target name="prepare" depends="init" description="Prepare build directory">
      <mkdir dir="${build.home}"/>
      <mkdir dir="${build.home}/classes"/>
      <mkdir dir="${build.home}/conf"/>
      <mkdir dir="${build.home}/docs"/>
      <mkdir dir="${build.home}/docs/api"/>
      <mkdir dir="${build.home}/tests"/>
    </target>
  
   
    <target name="compile" depends="prepare" description="Compile shareable components">
      <javac  srcdir="${source.home}"
             destdir="${build.home}/classes"
               debug="${compile.debug}"
         deprecation="${compile.deprecation}"
            optimize="${compile.optimize}">
        <classpath refid="compile.classpath"/>
      </javac>
      <copy    todir="${build.home}/classes" filtering="on">
        <fileset dir="${source.home}" excludes="**/*.java"/>
      </copy>
    </target>
  
  
    <target name="clean"
     description="Clean build and distribution directories">
      <delete    dir="${build.home}"/>
      <delete    dir="${dist.home}"/>
    </target>
  
  
    <target name="all" depends="clean,compile"
     description="Clean and compile all components"/>
  
  
    <target name="javadoc" depends="compile"
     description="Create component Javadoc documentation">
      <mkdir      dir="${dist.home}"/>
      <mkdir      dir="${dist.home}/docs"/>
      <mkdir      dir="${dist.home}/docs/api"/>
      <javadoc sourcepath="${source.home}"
                  destdir="${dist.home}/docs/api"
             packagenames="org.apache.commons.*"
                   author="true"
                  private="true"
                  version="true"
                 doctitle="&lt;h1&gt;${component.title}&lt;/h1&gt;"
              windowtitle="${component.title} (Version ${component.version})"
                   bottom="Copyright (c) 2001 - Apache Software Foundation"/>
    </target>
  
  
    <target name="dist" depends="compile,javadoc"
     description="Create binary distribution">
      <!-- TODO: top level files like LICENSE and README -->
      <mkdir      dir="${dist.home}"/>
      <copy      file="../LICENSE"
                todir="${dist.home}"/>
      <jar    jarfile="${dist.home}/commons-${component.name}.jar"
              basedir="${build.home}/classes"/>
      <mkdir      dir="${dist.home}/src"/>
      <copy     todir="${dist.home}/src" filtering="on">
        <fileset  dir="${source.home}"/>
      </copy>
    </target>
  
  
  </project>
  
  
  1.1                  jakarta-commons-sandbox/services/src/java/org/apache/commons/services/Event.java
  
  Index: Event.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.commons.services;
  
  /** Base class for all Events.
   * 
   *  @version $Id: Event.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
   *  @author Oleg V Alexeev
   */
  public class Event extends Leaf {
  
  }
  
  
  1.1                  jakarta-commons-sandbox/services/src/java/org/apache/commons/services/EventModule.java
  
  Index: EventModule.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.commons.services;
  
  /** Event module. Generate events.
   * 
   *  @version $Id: EventModule.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
   *  @author Oleg V Alexeev
   */
  public class EventModule extends Module {
  
          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;
          }
  
  }
  
  
  1.1                  jakarta-commons-sandbox/services/src/java/org/apache/commons/services/Leaf.java
  
  Index: Leaf.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.commons.services;
  
  import java.io.Serializable;
  
  /** Base class for all 'leaf' classes - Event, Service, Queue.
   *  
   *  @version $Id: Leaf.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
   *  @author Oleg V Alexeev
   */
  public class Leaf implements Serializable {
  
          protected Module parentModule = null;
  
          public Module getParentModule() {
                  return parentModule;
          }
  
          public void setParentModule( Module parentModule ) {
                  this.parentModule = parentModule;
          }
  
          public void init() {
                  parentModule = null;
          }
  
          public void destroy() {
                  parentModule = null;
          }
  
  }
  
  
  1.1                  jakarta-commons-sandbox/services/src/java/org/apache/commons/services/LogEvent.java
  
  Index: LogEvent.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.commons.services;
  
  import org.apache.commons.logging.Log;
  
  /** Special event for LogService.
   * 
   *  @version $Id: LogEvent.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
   *  @author Oleg V Alexeev
   */
  public class LogEvent extends Event {
  
          protected String message = null;
  
          public String getMessage() {
                  return message;
          }
  
          public void setMessage( String message ) {
                  this.message = message;
          }
  
          protected Throwable error = null;
  
          public Throwable getError() {
                  return error;
          }
  
          public void setError( Throwable error ) {
                  this.error = error;
          }
  
          public void init() {
                  super.init();
                  message = null;
                  error = null;
          }
  
  }
  
  
  1.1                  jakarta-commons-sandbox/services/src/java/org/apache/commons/services/LogService.java
  
  Index: LogService.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.commons.services;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogSource;
  
  /** LogService uses inversal logging bridge from commons-logging.
   * 
   *  @version $Id: LogService.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
   *  @author Oleg V Alexeev
   */
  public class LogService extends Service {
  
          public static int DEFAULT_LOG_LEVEL = org.apache.commons.logging.Log.OFF;
  
          protected Log log = null;
  
          protected void initLog() {
                  try {
                          LogSource.setLogImplementation( "org.apache.commons.logging.SimpleLog" );
                          log = LogSource.makeNewLogInstance( "org.apache.struts.sman.logging.SimpleLog" );
                  } catch ( Exception _e ) {
                  }
                  log = LogSource.makeNewLogInstance( "org.apache.struts.sman.logging.default" );
                  log.setLevel( DEFAULT_LOG_LEVEL );
          }
  
          public LogService() {
                  initLog();
          }
  
          public void init() {
                  super.init();
                  log.setLevel( DEFAULT_LOG_LEVEL );
          }
  
          public void destroy() {
                  super.destroy();
                  log = null;
          }
  
          public Log getLog() {
                  return log;
          }
  
          public Object execute( Event event ) {
                  if( event instanceof LogEvent ) {
                          LogEvent logEvent = (LogEvent)event;
                          log.info( logEvent.getMessage(), logEvent.getError() );
                  } else {
                                  log.info( event );
                                  log.debug( event );
                                  log.fatal( event );
                                  log.error( event );
                          if( log.isInfoEnabled() ) 
                                  log.info( event );
                  }
                  return null;
          }
  
  }
  
  
  1.1                  jakarta-commons-sandbox/services/src/java/org/apache/commons/services/Module.java
  
  Index: Module.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.commons.services;
  
  import java.io.Serializable;
  
  /** Base class for modules.
   * 
   *  @version $Id: Module.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
   *  @author Oleg V Alexeev
   */
  public class Module implements Serializable {
  
          protected boolean strongCheck = false;                
  
          public boolean getStrongCheck() {
                  return strongCheck;
          }
  
          public void setStrongCheck( boolean strongCheck ) {
                  this.strongCheck = strongCheck;
          }
  
          protected ServiceManager serviceManager = null;
  
          public ServiceManager getServiceManager() {
                  return serviceManager;
          }
  
          public void setServiceManager( ServiceManager serviceManager ) {
                  this.serviceManager = serviceManager;
          }
  
          public void init() {
                  strongCheck = false;
                  serviceManager = null;
          }
  
          public void destroy() {
                  serviceManager = null;                
          }
  
  }
  
  
  1.1                  jakarta-commons-sandbox/services/src/java/org/apache/commons/services/Queue.java
  
  Index: Queue.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.commons.services;
  
  import java.util.Iterator;
  
  /** Base class for Queues. Implements default queue's behaviour -
   *  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 $
   *  @author Oleg V Alexeev
   */
  public class Queue extends Leaf {
  
          protected boolean strongCheck = false;
  
          public boolean getStrongCheck() {
                  return strongCheck;
          }
  
          public void setStrongCheck( boolean strongCheck ) {
                  this.strongCheck = strongCheck;
          }
  
          public Object execute( Event event ) throws Exception {
                  int processed = 0;
                  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!" );
                                  }
                          } else {
                                  service.execute( event );
                                  processed++;
                          }
                  }
                  return new Integer( processed );
          }
  
          public void init() {
                  super.init();
                  strongCheck = false;
          }
  
  }
  
  
  1.1                  jakarta-commons-sandbox/services/src/java/org/apache/commons/services/QueueModule.java
  
  Index: QueueModule.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.commons.services;
  
  import java.util.Map;
  import java.util.HashMap;
  import java.util.Iterator;
  
  /** QueueModule - manages queues.
   * 
   *  @version $Id: QueueModule.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
   *  @author Oleg V Alexeev
   */
  public class QueueModule extends Module {
  
          protected Map queues = null;
  
          protected Queue defaultQueue = null;
  
          protected void initDefaultQueue() {
                  defaultQueue = new Queue();
                  defaultQueue.setParentModule( this );
          }
  
          protected void initQueues() {
                  queues = new HashMap();
          }
  
          public QueueModule() {
                  initQueues();
                  initDefaultQueue();
          }
  
          public void init() {
                  super.init();
                  queues.clear();
                  defaultQueue.init();
          }
  
          public void destroy() {
                  super.destroy();
                  Iterator iterator = queues.values().iterator();
                  Queue queue = null;
  
                  while( iterator.hasNext() ) {
                          queue = (Queue)iterator.next();
                          queue.destroy();
                  }
                  queues.clear();
                  queues = null;
                  defaultQueue.destroy();
                  defaultQueue = null;
          }
  
          public void addQueue( String name, Queue queue ) {
                  queues.put( name, queue );
                  queue.setParentModule( this );
          }
  
          public void removeQueue( String name ) {
                  queues.remove( name );
          }
  
          public Queue getQueue( String name ) throws Exception {
                  Queue queue = (Queue)queues.get( name );
                  if( queue==null ) {
                          if( strongCheck ) {
                                  throw new Exception( "Can not find queue for name" );
                          } else {
                                  return getDefaultQueue();
                          }
                  } else {
                          return queue;
                  }
          }
  
          public Queue getDefaultQueue() {
                  return defaultQueue;
          }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/services/src/java/org/apache/commons/services/SequenceQueue.java
  
  Index: SequenceQueue.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.commons.services;
  
  import java.util.Iterator;
  
  /** Queue with ability to call services, by the names from
   *  array. 
   * 
   *  @version $Id: SequenceQueue.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
   *  @author Oleg V Alexeev
   */
  public class SequenceQueue extends Queue {
  
          protected String[] sequence = null;
  
          public String[] getSequence() {
                  return sequence;
          }
  
          public void setSequence( String[] sequence ) {
                  this.sequence = sequence;
          }
  
          public Object execute( Event event ) throws Exception {
                  int processed = 0;
                  Service service = null;
                  ServiceModule serviceModule = parentModule.getServiceManager().getServiceModule();
  
                  System.out.println( "Execute in queue '" + this.getClass().getName() + "'" );
                  System.out.println( "for event '" + event.getClass().getName() + "'" );
                  
                  for( int i = 0; i<sequence.length; i++ ) {
                          service = serviceModule.getService( sequence[i] );
  
                  System.out.println( "Execute for service '" + service.getClass().getName() + "'" );
  
                          if( service==null ) {
                                  if( strongCheck ) {
                                          throw new Exception( "Service not available!" );
                                  }
                          } else {
                                  service.execute( event );
                                  processed++;
                          }
                  }
                  return new Integer( processed );
          }
  
  }
  
  
  1.1                  jakarta-commons-sandbox/services/src/java/org/apache/commons/services/Service.java
  
  Index: Service.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.commons.services;
  
  /** Base Service class.
   * 
   *  @version $Id: Service.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
   *  @author Oleg V Alexeev
   */
  public class Service extends Leaf {
  
          public Object execute( Event event ) {
                  return this.getClass().getName();
          }
  
  }
  
  
  1.1                  jakarta-commons-sandbox/services/src/java/org/apache/commons/services/ServiceManager.java
  
  Index: ServiceManager.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.commons.services;
  
  import java.io.Serializable;
  
  /** 
   *  Core class in package.
   * 
   *  @version $Id: ServiceManager.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
   *  @author Oleg V Alexeev
   */
  public class ServiceManager implements Serializable {
  
          protected EventModule eventModule = null;
  
          protected ServiceModule serviceModule = null;
  
          protected QueueModule queueModule = null;
  
          public EventModule getEventModule() {
                  return eventModule;
          }
  
          public void setEventModule( EventModule eventModule ) {
                  this.eventModule = eventModule;
                  this.eventModule.setServiceManager( this );
          }
  
          public ServiceModule getServiceModule() {
                  return serviceModule;
          }
  
          public void setServiceModule( ServiceModule serviceModule ) {
                  this.serviceModule = serviceModule;
                  this.serviceModule.setServiceManager( this );
          }
  
          public QueueModule getQueueModule() {
                  return queueModule;
          }
  
          public void setQueueModule( QueueModule queueModule ) {
                  this.queueModule = queueModule;
                  this.queueModule.setServiceManager( this );
          }
  
          public void init() {
                  ;
          }
  
          public void destroy() {
                  eventModule.destroy();
                  eventModule = null;
                  serviceModule.destroy();
                  serviceModule = null;
                  queueModule.destroy();
                  queueModule = null;
          }
  
          public Object execute() throws Exception {
                  Event event = eventModule.getDefaultEvent();
                  Queue queue = queueModule.getDefaultQueue();
                  return queue.execute( event );
          }
  
          public Object execute( String queueName ) throws Exception {
                  Event event = eventModule.getDefaultEvent();
                  return execute( queueName, event );
          }
  
          public Object execute( Event event ) throws Exception {
                  Queue queue = queueModule.getDefaultQueue();
                  return queue.execute( event );
          }
  
          public Object execute( String queueName, Event event ) throws Exception {
                  Queue queue = queueModule.getQueue( queueName );
                  return queue.execute( event );
          }
  
  
  }
  
  
  1.1                  jakarta-commons-sandbox/services/src/java/org/apache/commons/services/ServiceModule.java
  
  Index: ServiceModule.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.commons.services;
  
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Iterator;
  
  /** ServiceModule manages services. 
   * 
   *  @version $Id: ServiceModule.java,v 1.1 2001/12/17 16:38:18 oalexeev Exp $
   *  @author Oleg V Alexeev
   */
  public class ServiceModule extends Module {
  
          protected Map services = null;
  
          protected void initServices() {
                  services = new HashMap();
          }
  
          public ServiceModule() {
                  super();
                  initServices();
          }
          
          public void init() {
                  super.init();
                  services.clear();
          }
  
          public void destroy() {
                  super.destroy();
                  Iterator iterator = services.values().iterator();
                  Service service = null;
  
                  while( iterator.hasNext() ) {
                          service = (Service)iterator.next();
                          service.destroy();
                  }
                  services.clear();
                  services = null;
          }
  
          public void addService( String name, Service service ) {
                  services.put( name, service );
                  service.setParentModule( this );
          }
  
          public void removeService( String name ) {
                  services.remove( name );
          }
  
          public Service getService( String name ) throws Exception {
                  // FIX  - check name for null
                  Service service = (Service)services.get( name );
                  if( service==null ) {
                          throw new Exception( "Service not found for name - '" + name + "'" );
                  }
                  return service;
          }
  
          public Iterator getServices() {
                  return services.values().iterator();
          }
  
  }
  
  
  

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