cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject cvs commit: cocoon-2.2/src/kernel/org/apache/cocoon/kernel/startup KernelLoader.java KernelServlet.java
Date Mon, 17 May 2004 21:08:32 GMT
pier        2004/05/17 14:08:32

  Modified:    src/kernel/org/apache/cocoon/kernel DeployedWirings.java
                        KernelDeployer.java
               src/kernel/org/apache/cocoon/kernel/composition
                        Lifecycle.java
               src/kernel/org/apache/cocoon/kernel/startup
                        KernelLoader.java KernelServlet.java
  Log:
  Implementing events I had to introduce a new method called "start()" in the
  Lifecycle interface, but I seriously don't like it... :-(
  
  Revision  Changes    Path
  1.12      +10 -1     cocoon-2.2/src/kernel/org/apache/cocoon/kernel/DeployedWirings.java
  
  Index: DeployedWirings.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/DeployedWirings.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DeployedWirings.java	15 May 2004 23:07:50 -0000	1.11
  +++ DeployedWirings.java	17 May 2004 21:08:32 -0000	1.12
  @@ -263,4 +263,13 @@
               ((Lifecycle)this.composer).destroy();
           }
       }
  +
  +    /**
  +     * <p>Notify this {@link DeployedWirings} of framework startup.</p>
  +     */
  +    public void start() {
  +        if (this.composer instanceof Lifecycle) {
  +            ((Lifecycle)this.composer).start();
  +        }
  +    }
   }
  
  
  
  1.12      +41 -1     cocoon-2.2/src/kernel/org/apache/cocoon/kernel/KernelDeployer.java
  
  Index: KernelDeployer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/KernelDeployer.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- KernelDeployer.java	7 May 2004 21:14:25 -0000	1.11
  +++ KernelDeployer.java	17 May 2004 21:08:32 -0000	1.12
  @@ -275,6 +275,46 @@
       /* ====================================================================== */
   
       /**
  +     * <p>Notify all blocks of the framework startup.</p>
  +     * 
  +     * @see org.apache.cocoon.kernel.composition.Composer#start()
  +     */
  +    public void start() {
  +        Iterator iterator = this.wiringsByInstance.entrySet().iterator();
  +        while (iterator.hasNext()) {
  +            Map.Entry entry = (Map.Entry) iterator.next();
  +            DeployableInstance instance = (DeployableInstance) entry.getKey();
  +            DeployedWirings wirings = (DeployedWirings) entry.getValue();
  +            try {
  +                wirings.start();
  +                this.log.info("Started instance \"" + instance + "\"");
  +            } catch (Throwable t) {
  +                this.log.warn("Exception starting \"" + instance + "\"", t);
  +            }
  +        }
  +    }
  +
  +    /**
  +     * <p>Stop and destroy all blocks.</p>
  +     */
  +    public void stop() {
  +        Iterator iterator = this.wiringsByInstance.entrySet().iterator();
  +        while (iterator.hasNext()) {
  +            Map.Entry entry = (Map.Entry) iterator.next();
  +            DeployableInstance instance = (DeployableInstance) entry.getKey();
  +            DeployedWirings wirings = (DeployedWirings) entry.getValue();
  +            try {
  +                wirings.destroy();
  +                this.log.info("Stopped instance \"" + instance + "\"");
  +            } catch (Throwable t) {
  +                this.log.warn("Exception stopping \"" + instance + "\"", t);
  +            }
  +        }
  +    }
  +
  +    /* ====================================================================== */
  +
  +    /**
        * <p>Replace the specified block {@link Instance} with another one.</p>
        *
        * <p>This method will replace a deployed {@link Instance} with another,
  
  
  
  1.6       +15 -1     cocoon-2.2/src/kernel/org/apache/cocoon/kernel/composition/Lifecycle.java
  
  Index: Lifecycle.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/composition/Lifecycle.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Lifecycle.java	6 May 2004 20:09:33 -0000	1.5
  +++ Lifecycle.java	17 May 2004 21:08:32 -0000	1.6
  @@ -76,4 +76,18 @@
        */
       public void destroy()
       throws Exception;
  +    
  +    /**
  +     * <p>Notify this instance that the framework initialized all blocks.</p>
  +     * 
  +     * <p>The framework calls this method to notify an object implementing
  +     * the {@link Lifecycle} interface that all blocks have been initalized
  +     * correctly. This might be helpful to event triggers, to instruct that
  +     * all configured listeners have been created.</p>
  +     * 
  +     * <p><b>TODO:</b> This method needs to be thought out more in the
scope of
  +     * event handling. Should the framework provide event dispatching between
  +     * wired block instances?</p>
  +     */
  +    public void start();
   }
  
  
  
  1.3       +19 -2     cocoon-2.2/src/kernel/org/apache/cocoon/kernel/startup/KernelLoader.java
  
  Index: KernelLoader.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/startup/KernelLoader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- KernelLoader.java	6 May 2004 20:09:33 -0000	1.2
  +++ KernelLoader.java	17 May 2004 21:08:32 -0000	1.3
  @@ -24,7 +24,17 @@
    * @author <a href="mailto:pier@apache.org">Pier Fumagalli</a>
    * @version 1.0 (CVS $Revision$)
    */
  -public class KernelLoader {
  +public class KernelLoader implements Runnable {
  +
  +    private KernelDeployer deployer = null;
  +
  +    private KernelLoader(KernelDeployer deployer) {
  +        this.deployer = deployer;
  +    }
  +
  +    public void run() {
  +        this.deployer.stop();
  +    }
   
       public static void main(String args[]) {
           if (args.length < 1) {
  @@ -45,6 +55,13 @@
               /* Instantiate an installer and process deployment */
               Installer installer = new Installer(deployer);
               installer.process(ConfigurationBuilder.parse(args[1]));
  +
  +            /* Start the framework */
  +            deployer.start();
  +            
  +            /* Register a shutdown hook */
  +            Thread thread = new Thread(new KernelLoader(deployer));
  +            Runtime.getRuntime().addShutdownHook(thread);
   
           } catch (Throwable t) {
               logger.fatal("An error occurred initializing", t);
  
  
  
  1.5       +5 -1      cocoon-2.2/src/kernel/org/apache/cocoon/kernel/startup/KernelServlet.java
  
  Index: KernelServlet.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/startup/KernelServlet.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- KernelServlet.java	6 May 2004 20:09:33 -0000	1.4
  +++ KernelServlet.java	17 May 2004 21:08:32 -0000	1.5
  @@ -122,6 +122,9 @@
               this.wirings = new CoreWirings(this.deployer);
               KernelServlet.instance = this;
   
  +            /* Start the framework */
  +            this.deployer.start();
  +
           } catch (Throwable throwable) {
               String message = "An error occurred initializing the kernel";
               logger.fatal(message, throwable);
  @@ -131,6 +134,7 @@
   
       public void destroy() {
           this.logger.info("Kernel shutdown");
  +        this.deployer.stop();
       }
   
       public void service(ServletRequest request, ServletResponse response)
  
  
  

Mime
View raw message