donaldp     01/02/23 20:00:51

  Added:       src/java/org/apache/avalon/atlantis AbstractKernel.java
                        Application.java ApplicationException.java
                        Facility.java Kernel.java
  Log:
  Rechecked in avalon
  
  Revision  Changes    Path
  1.1                  
jakarta-avalon/src/java/org/apache/avalon/atlantis/AbstractKernel.java
  
  Index: AbstractKernel.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.avalon.atlantis;
  
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.Iterator;
  import org.apache.avalon.AbstractLoggable;
  import org.apache.avalon.Component;
  import org.apache.avalon.ComponentManager;
  import org.apache.avalon.Context;
  import org.apache.avalon.DefaultComponentManager;
  import org.apache.avalon.DefaultContext;
  import org.apache.avalon.camelot.AbstractContainer;
  import org.apache.avalon.camelot.Container;
  import org.apache.avalon.camelot.Entry;
  import org.apache.avalon.camelot.ContainerException;
  import org.apache.avalon.camelot.FactoryException;
  import org.apache.avalon.camelot.Locator;
  
  /**
   * This is the basic Kernel that supports functionality most kernels need.
   * It builds a DAG of blocks, can load/unload/reload blocks, can 
   * configure/reconfigure blocks, can start/stop/initialize blocks, provide
   * contexts for blocks etc.
   *
   * When extending this the developer must set the value of m_entryClass and 
m_applicationClass.
   * ie. 
   * m_entryClass = ServerApplicationEntry.class;
   * m_applicationClass = ServerApplication.class;
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public abstract class AbstractKernel
      extends AbstractContainer
      implements Kernel
  {
      protected boolean         m_initialised       = false;
      protected boolean         m_running           = false;
      protected Class           m_applicationClass;
  
      public void init() 
          throws Exception 
      {
          final Iterator names = list();
          while( names.hasNext() )
          {
              final String name = (String)names.next();
              final Entry entry = getEntry( name );
              initializeEntry( name, entry );
          }
      }    
  
      public void start()
          throws Exception
      {
          final Iterator names = list();
          while( names.hasNext() )
          {
              final String name = (String)names.next();
              final Entry entry = getEntry( name );
              startEntry( name, entry );
          }
      }
     
      public void run() 
      {
          m_running = true;
  
          while( m_running ) 
          {
              try { synchronized( this ) { wait(); } } 
              catch (InterruptedException e) {}
          }
      }
  
      public void stop() 
          throws Exception
      {
          m_running = false;
          synchronized( this ) { notifyAll(); }
  
          final Iterator names = list();
          while( names.hasNext() )
          {
              final String name = (String)names.next();
              final Entry entry = getEntry( name );
              stopEntry( name, entry );
          }
      }
      
      public void dispose() 
          throws Exception
      {
          m_initialised = false;
          
          final Iterator names = list();
          while( names.hasNext() )
          {
              final String name = (String)names.next();
              final Entry entry = getEntry( name );
              disposeEntry( name, entry );
          }
      }
  
      /**
       * Retrieve Application from container. 
       * The Application that is returned must be initialized 
       * and prepared for manipulation.
       *
       * @param name the name of application
       * @return the application
       * @exception ContainerException if an error occurs 
       */
      public Application getApplication( String name )
          throws ContainerException
      {
          final Entry entry = getEntry( name );
  
          try { initializeEntry( name, entry ); }
          catch( final Exception e )
          {
              throw new ContainerException( "Error prepareing entry", e );
          }
  
          return (Application)entry.getInstance();
      }
  
      protected void initializeEntry( final String name, final Entry entry )
          throws Exception
      {
          Application application = (Application)entry.getInstance();
  
          if( null == application )
          {
              preInitializeEntry( name, entry );
              application = createApplicationFor( name, entry );
              entry.setInstance( application );
  
              prepareApplication( name, entry, application );
              application.init();
              postInitializeEntry( name, entry );
          }
      }
  
      protected void startEntry( final String name, final Entry entry )
          throws Exception
      {
          final Application application = (Application)entry.getInstance();
          if( null != application ) 
          {
              application.start();
          }
          else
          {
              getLogger().warn( "Failed to start application " + name +
                                " as it is not initialized" ); 
          }
      }
  
      protected void stopEntry( final String name, final Entry entry )
          throws Exception
      {
          final Application application = (Application)entry.getInstance();
          if( null != application ) 
          {
              application.stop();
          }
          else
          {
              getLogger().warn( "Failed to stop application " + name +
                                " as it is not initialized/started" ); 
          }
      }
  
      protected void disposeEntry( final String name, final Entry entry )
          throws Exception
      {
          Application application = (Application)entry.getInstance();
  
          if( null != application )
          {
              preDisposeEntry( name, entry );
              entry.setInstance( null );
              application.dispose();
              postDisposeEntry( name, entry );
          }
      }
  
      /**
       * This method is called before an entry is initialized.
       * Overide to do something.
       *
       * @param name the name of the entry
       * @param entry the entry
       * @exception Exception if an error occurs
       */
      protected void preInitializeEntry( final String name, final Entry entry )
          throws Exception
      {        
      }
  
      /**
       * This method is called after an entry is initialized.
       * Overide to do something.
       *
       * @param name the name of the entry
       * @param entry the entry
       * @exception Exception if an error occurs
       */
      protected void postInitializeEntry( final String name, final Entry entry )
          throws Exception
      {        
      }
  
      /**
       * This method is called before an entry is disposed.
       * Overide to do something.
       *
       * @param name the name of the entry
       * @param entry the entry
       * @exception Exception if an error occurs
       */
      protected void preDisposeEntry( final String name, final Entry entry )
          throws Exception
      {        
      }
  
      /**
       * This method is called after an entry is disposed.
       * Overide to do something.
       *
       * @param name the name of the entry
       * @param entry the entry
       * @exception Exception if an error occurs
       */
      protected void postDisposeEntry( final String name, final Entry entry )
          throws Exception
      {        
      }
  
      /**
       * Prepare an application before it is initialized.
       * Overide to provide functionality. 
       * Usually used to setLogger(), contextualize, compose, configure.
       *
       * @param name the name of application
       * @param entry the application entry 
       * @param application the application instance
       * @exception Exception if an error occurs
       */
      protected void prepareApplication( final String name, 
                                         final Entry entry, 
                                         final Application application )
          throws Exception
      {
      }
  
      protected Application createApplicationFor( final String name, final 
Entry entry )
          throws Exception
      {
          final Application application = newApplication( name, entry );
          
          if( !m_applicationClass.isInstance( application ) )
          {
              throw new IllegalArgumentException( "Created an application that 
is not " + 
                                                  "of type " + 
m_applicationClass.getName() + 
                                                  " but of type " + 
                                                  
application.getClass().getName() );
          }
          
          return application;
      }
  
      protected Application newApplication( final String name, final Entry 
entry )
          throws Exception
      {
          return (Application)m_applicationClass.newInstance();
      }
  }
  
  
  
  1.1                  
jakarta-avalon/src/java/org/apache/avalon/atlantis/Application.java
  
  Index: Application.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.avalon.atlantis;
  
  import org.apache.avalon.Disposable;
  import org.apache.avalon.Initializable;
  import org.apache.avalon.Startable;
  import org.apache.avalon.Stoppable;
  import org.apache.avalon.camelot.Container;
  
  /**
   * The Application is a self-contained component that performs a specific
   * function. 
   *
   * Example ServerApplications may be a Mail Server, File Server, Directory 
Server etc.
   * Example JesktopApplications may be a Spreadsheet program, browser, mail 
client
   * Example WebApplications may be a particular website or application within 
a website
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface Application 
      extends Initializable, Startable, Stoppable, Disposable, Container
  {
  }
  
  
  
  1.1                  
jakarta-avalon/src/java/org/apache/avalon/atlantis/ApplicationException.java
  
  Index: ApplicationException.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.avalon.atlantis;
  
  import org.apache.avalon.CascadingException;
  
  /**
   * The ApplicationException used to indicate problems with applications.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public class ApplicationException
      extends CascadingException
  {
      public ApplicationException( final String message )
      {
          this( message, null );
      }
  
      public ApplicationException( final String message, final Throwable 
throwable )
      {
          super( message, throwable );
      }
  }
  
  
  
  1.1                  
jakarta-avalon/src/java/org/apache/avalon/atlantis/Facility.java
  
  Index: Facility.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.avalon.atlantis;
  
  import org.apache.avalon.Component;
  
  /**
   * A Facility is a horizontal cut through the kernel. 
   * Unlike Components which offer a Service/Content interface, Facilitys 
   * are used to facilitate the non-Service/Form interface or life-cycle 
orientated
   * methods of Components. See documentation for a clearer explanation.
   *
   * Example Facilities would be 
   * <ul>
   *   <li>ConfigurationRepository that stores configuration data for 
components</li>
   *   <li>ThreadFacility that allows components to run in threads</li>
   *   <li>ContextUtility that builds context information for components</li>
   *   <li>ExportFacility that exports components to external users (perhaps 
via RMI)</li>
   *   <li>NamingFacility that binds compoents to a name in a directory</li>
   *   <li>ManagementFacility that manages components via JMX</li>
   * </ul>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface Facility 
      extends Component
  {
  }
  
  
  
  1.1                  
jakarta-avalon/src/java/org/apache/avalon/atlantis/Kernel.java
  
  Index: Kernel.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.avalon.atlantis;
  
  import org.apache.avalon.camelot.ContainerException;
  
  /**
   * The Kernel is the core of any system.
   * The kernel is responsible for orchestrating low level services 
   * such as loading, configuring and destroying applications. It also 
   * gives access to basic facilities specific to that particular kernel.
   * A ServerKernel may offer scheduling, naming, security, classloading etc.
   * A JesktopKernel may offer inter-application drag-n-drop support.
   * A VEKernel may offer inter-VE transport for Avatars.
   *
   * Note that no facilities are available until after the Kernel has been 
initialized.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   */
  public interface Kernel 
      extends Application, Runnable
  {
      /**
       * Retrieve Application from container. 
       * The Application that is returned must be initialized 
       * and prepared for manipulation.
       *
       * @param name the name of application
       * @return the application
       * @exception ContainerException if an error occurs 
       */
      Application getApplication( String name )
          throws ContainerException;
  }
  
  
  

Reply via email to