geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gr...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/context TransactionInterceptor.java
Date Thu, 14 Aug 2003 07:14:34 GMT
gregw       2003/08/14 00:14:34

  Modified:    modules/core/src/java/org/apache/geronimo/common
                        AbstractComponent.java AbstractInterceptor.java
                        Component.java State.java
               modules/core/src/java/org/apache/geronimo/ejb/container
                        ContainerImpl.java
               modules/core/src/java/org/apache/geronimo/ejb/context
                        TransactionInterceptor.java
  Added:       modules/core/src/java/org/apache/geronimo/common
                        AbstractContainer.java AbstractStateManageable.java
                        StateManageable.java
  Log:
  This commit is an attempt to continue moving gently towards the JSR77 state mechanism
  without committing to any MBean backbone choise etc.
  
  This commit has some of the ideas from the patch submitted by gianny_damour@hotmail.com
  Specifically the addition of the JSR77 state change notifications to the State class.
  However I have left his full notification mechanism out for now, as I am unclear
  if this is the way we are going.  I have put and abstract notification method
  onto AbstractComponent, so it will be simple to add the real notification mechanism when
  we know what that is.
  
  The rest of the commit is more in the same theme. Gently moving towards JSR77.
  I have extracted the state stuff from Component into a StateManageable interface
  and an AbstractStateManageable.
  
  Unfortunately JSR77 wants it's state as an int, so getState now returns
  an int.  But getStateInstance is there to get the object itself.  I have
  put a bit more toInt an fromInt support into the State class.
  
  For symmetry I created the AbstractContainer class, but it does nothing
  at this stage.  It needs the startRecursive handling moved to it once
  we have a real Container interface (one which you can iterate over
  the Components would be good).
  
  Submitted by: Greg Wilkins
  Reviewed by: Nameless the cat
  
  Revision  Changes    Path
  1.4       +19 -164   incubator-geronimo/modules/core/src/java/org/apache/geronimo/common/AbstractComponent.java
  
  Index: AbstractComponent.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/common/AbstractComponent.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractComponent.java	13 Aug 2003 02:12:40 -0000	1.3
  +++ AbstractComponent.java	14 Aug 2003 07:14:33 -0000	1.4
  @@ -55,128 +55,17 @@
    */
   package org.apache.geronimo.common;
   
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
  -
   /**
  - *
  - *
  + * A helper implementation of the Component interface that should 
  + * be used as a base class for Component implementations.
    *
    * @version $Revision$ $Date$
    */
  -public class AbstractComponent implements Component
  +public class AbstractComponent 
  +    extends AbstractStateManageable
  +    implements Component
   {
  -    private State state= State.STOPPED;
  -    private long startTime;
       private Container container;
  -    protected Log log= LogFactory.getLog(getClass());
  -
  -    public State getState()
  -    {
  -        return state;
  -    }
  -
  -    /**
  -     * Set the Component state.
  -     * @param newState
  -     * @throws IllegalStateException Thrown if the transition is not supported by the JSR77
lifecycle.
  -     */
  -    protected void setState(State newState) throws IllegalStateException
  -    {
  -        switch (state.getIndex())
  -        {
  -            case State.STOPPED_INDEX :
  -                {
  -                    switch (state.getIndex())
  -                    {
  -                        case State.STARTING_INDEX :
  -                            break;
  -                        case State.STOPPED_INDEX :
  -                        case State.RUNNING_INDEX :
  -                        case State.STOPPING_INDEX :
  -                        case State.FAILED_INDEX :
  -                            throw new IllegalStateException(
  -                                "Can not transition to " + newState + " state from " +
state);
  -                    }
  -                    break;
  -                }
  -
  -            case State.STARTING_INDEX :
  -                {
  -                    switch (state.getIndex())
  -                    {
  -                        case State.RUNNING_INDEX :
  -                        case State.FAILED_INDEX :
  -                        case State.STOPPING_INDEX :
  -                            break;
  -                        case State.STOPPED_INDEX :
  -                        case State.STARTING_INDEX :
  -                            throw new IllegalStateException(
  -                                "Can not transition to " + newState + " state from " +
state);
  -                    }
  -                    break;
  -                }
  -
  -            case State.RUNNING_INDEX :
  -                {
  -                    switch (state.getIndex())
  -                    {
  -                        case State.STOPPING_INDEX :
  -                        case State.FAILED_INDEX :
  -                            break;
  -                        case State.STOPPED_INDEX :
  -                        case State.STARTING_INDEX :
  -                        case State.RUNNING_INDEX :
  -                            throw new IllegalStateException(
  -                                "Can not transition to " + newState + " state from " +
state);
  -
  -                    }
  -                    break;
  -                }
  -
  -            case State.STOPPING_INDEX :
  -                {
  -                    switch (state.getIndex())
  -                    {
  -                        case State.STOPPED_INDEX :
  -                        case State.FAILED_INDEX :
  -                            break;
  -                        case State.STARTING_INDEX :
  -                        case State.RUNNING_INDEX :
  -                        case State.STOPPING_INDEX :
  -                            throw new IllegalStateException(
  -                                "Can not transition to " + newState + " state from " +
state);
  -                    }
  -                    break;
  -                }
  -
  -            case State.FAILED_INDEX :
  -                {
  -                    switch (state.getIndex())
  -                    {
  -                        case State.STARTING_INDEX :
  -                        case State.STOPPING_INDEX :
  -                            break;
  -                        case State.STOPPED_INDEX :
  -                        case State.RUNNING_INDEX :
  -                        case State.FAILED_INDEX :
  -                            throw new IllegalStateException(
  -                                "Can not transition to " + newState + " state from " +
state);
  -                    }
  -                    break;
  -                }
  -        }
  -        log.debug("State changed from " + state + " to " + newState);
  -        if (newState==State.RUNNING)
  -            startTime= System.currentTimeMillis();
  -        state= newState;
  -
  -    }
  -
  -    public long getStartTime()
  -    {
  -        return startTime;
  -    }
   
       public final Container getContainer()
       {
  @@ -185,68 +74,34 @@
   
       public final void setContainer(Container container)
       {
  -        if (state != State.STOPPED)
  +        if (getStateInstance() != State.STOPPED)
           {
               throw new IllegalStateException(
  -                "Set container can only be called while in the stopped state: state=" +
state);
  +                "Set container can only be called while in the stopped state: state=" +
getStateInstance());
           }
           this.container= container;
       }
   
  -    public void start() throws Exception
  -    {
  -        try
  -        {
  -            setState(State.STARTING);
  -            doStart();
  -            setState(State.RUNNING);
  -        }
  -        finally
  -        {
  -            if (state != State.RUNNING)
  -                setState(State.FAILED);
  -        }
  -    }
  -
  -    public void startRecursive() throws Exception
  -    {
  -        start();
  -    }
  -
  -    /**
  -     * Do the start tasks for the component.  Called in the STARTING state by 
  -     * the start() and startRecursive() methods to perform the tasks required to 
  -     * start the component. The default implementation does nothing.
  -     * @throws Exception
  +    /* (non-Javadoc)
  +     * @see org.apache.geronimo.common.AbstractStateManageable#doStart()
        */
       public void doStart() throws Exception
       {
       }
   
  -    public void stop()
  +    /* (non-Javadoc)
  +     * @see org.apache.geronimo.common.AbstractStateManageable#doStop()
  +     */
  +    public void doStop() throws Exception
       {
  -        // Do the actual stop tasks
  -        try
  -        {
  -            setState(State.STOPPING);
  -            doStop();
  -            setState(State.STOPPED);
  -        }
  -        catch (Exception e)
  -        {
  -            log.warn("Stop failed", e);
  -            setState(State.FAILED);
  -        }
       }
   
  -    /**
  -     * Do the stop tasks for the component.  Called in the STOPPING state by the stop()
  -     * method to perform the tasks required to stop the component.
  -     * This implementation does nothing.
  -     * @throws Exception
  +    /* (non-Javadoc)
  +     * @see org.apache.geronimo.common.AbstractStateManageable#doNotification(java.lang.String)
        */
  -    public void doStop() throws Exception
  +    public void doNotification(String eventTypeValue)
       {
  +        log.debug("notification: "+eventTypeValue+" from "+this);
       }
  -
  +    
   }
  
  
  
  1.4       +2 -2      incubator-geronimo/modules/core/src/java/org/apache/geronimo/common/AbstractInterceptor.java
  
  Index: AbstractInterceptor.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/common/AbstractInterceptor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractInterceptor.java	13 Aug 2003 02:12:40 -0000	1.3
  +++ AbstractInterceptor.java	14 Aug 2003 07:14:33 -0000	1.4
  @@ -69,7 +69,7 @@
       }
   
       public final void setNext(Interceptor nextInterceptor) {
  -        State state = getState();
  +        State state = getStateInstance();
           if (state != State.STOPPED) {
               throw new IllegalStateException("setNext can only be called while in the stopped
state: state=" + state);
           }
  
  
  
  1.4       +3 -55     incubator-geronimo/modules/core/src/java/org/apache/geronimo/common/Component.java
  
  Index: Component.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/common/Component.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Component.java	13 Aug 2003 02:12:40 -0000	1.3
  +++ Component.java	14 Aug 2003 07:14:33 -0000	1.4
  @@ -62,19 +62,8 @@
    *
    * @version $Revision$ $Date$
    */
  -public interface Component {
  -    /**
  -     * Gets the state of this component.
  -     * @return the current state of this component
  -     */
  -    State getState();
  -
  -	/**
  -	 * Gets the start time of this component
  -	 * @return time in milliseonds since epoch that this component was started.
  -	 */
  -	long getStartTime();
  -	
  +public interface Component  extends StateManageable
  +{
       /**
        * Gets the container to which this component belongs.
        * @return the container for which invocations will be intercepted
  @@ -92,47 +81,6 @@
        */
       void setContainer(Container container) throws IllegalStateException, IllegalArgumentException;
   
  -    /**
  -     * Transitions the component to the starting state.  This method has access to the
  -     * container.
  -     *
  -     * Normally a component uses this to cache data from other components. The other components
will
  -     * have been created at this stage, but not necessairly started and may not be ready
to have methods
  -     * invoked on them.
  -     *
  -     * @throws java.lang.Exception if a problem occurs during the transition
  -     * @throws java.lang.IllegalStateException if this interceptor is not in the stopped
or failed state
  -     */
  -    void start() throws Exception, IllegalStateException;
  -
  -	/**
  -	 * Transitions the component to the starting state.  This method has access to the
  -	 * container.
  -	 * 
  -	 * If this Component is a Container, then startRecursive is called on all child Components
  -	 * that are in the STOPPED or FAILED state.
  -	 * Normally a component uses this to cache data from other components. The other components
will
  -	 * have been created at this stage, but not necessairly started and may not be ready to
have methods
  -	 * invoked on them.
  -	 *
  -	 * @throws java.lang.Exception if a problem occurs during the transition
  -	 * @throws java.lang.IllegalStateException if this interceptor is not in the STOPPED or
FAILED state
  -	 */
  -	void startRecursive() throws Exception, IllegalStateException;
  -
  -    /**
  -     * Transitions the component to the stopping state.  This method has access to the
  -     * container.
  -     *
  -	 * If this is Component is a Container, then all its child components must be in the 
  -	 * STOPPED or FAILED State.
  -	 * 
  -     * Normally a component uses this to drop references to data cached in the start method.
  -     * The other components will not necessairly have been stopped at this stage and may
not be ready
  -     * to have methods invoked on them.
  -     */
  -    void stop() throws IllegalStateException;
  -    
   
   
   }
  
  
  
  1.4       +49 -18    incubator-geronimo/modules/core/src/java/org/apache/geronimo/common/State.java
  
  Index: State.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/common/State.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- State.java	13 Aug 2003 02:12:40 -0000	1.3
  +++ State.java	14 Aug 2003 07:14:34 -0000	1.4
  @@ -63,29 +63,60 @@
    */
   public final class State {
   	
  -	public static final int STARTING_INDEX=0;
  -	public static final int RUNNING_INDEX=1;
  -	public static final int STOPPING_INDEX=2;
  -	public static final int STOPPED_INDEX=3;
  -	public static final int FAILED_INDEX=4;
  -	
  -    public static final State STARTING = new State("starting",STARTING_INDEX);
  -    public static final State RUNNING = new State("running",RUNNING_INDEX);
  -	public static final State STOPPING = new State("stopping",STOPPING_INDEX);
  -	public static final State STOPPED = new State("stopped",STOPPED_INDEX);
  -	public static final State FAILED = new State("failed",FAILED_INDEX);
  -	
  +    public static final int STARTING_INDEX=0;
  +    public static final int RUNNING_INDEX=1;
  +    public static final int STOPPING_INDEX=2;
  +    public static final int STOPPED_INDEX=3;
  +    public static final int FAILED_INDEX=4;
  +    
  +    public static final State STARTING =
  +        new State("starting",STARTING_INDEX,"j2ee.state.starting");
  +    public static final State RUNNING =
  +        new State("running",RUNNING_INDEX,"j2ee.state.running");
  +    public static final State STOPPING =
  +        new State("stopping",STOPPING_INDEX,"j2ee.state.stopping");
  +    public static final State STOPPED =
  +        new State("stopped",STOPPED_INDEX,"j2ee.state.stopped");
  +    public static final State FAILED =
  +        new State("failed",FAILED_INDEX,"j2ee.state.failed");
  +
  +    private static final State[] fromInt=
  +        {STARTING,RUNNING,STOPPING,STOPPED,FAILED};
  +        
  +    /**
  +     * Get a State from an int index
  +     * @param index int index of the state
  +     * @return The State instance or null if no such State.
  +     */
  +    public static State fromInt(int index)
  +    {
  +        if (index<0 || index>=fromInt.length)
  +            return null;
  +        return fromInt[index];
  +    }
  +        
       private final String name;
  -	private final int index;
  +    private final int index;
  +
  +    /**
  +     * Type value to be broadcasted on entering this state.
  +     */
  +    private final String eventTypeValue;
  +
   	
  -    private State(String name, int index) {
  +    private State(String name, int index, String anEventTypeValue) {
           this.name = name;
           this.index = index;
  +        eventTypeValue = anEventTypeValue;
       }
   
  -	public int getIndex() {	
  -		return index;
  -	}
  +    public int toInt() {	
  +        return index;
  +    }
  +    
  +    public String getEventTypeValue() {
  +        return eventTypeValue;
  +    }
   	
       public String toString() {
           return name;
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/common/AbstractContainer.java
  
  Index: AbstractContainer.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" 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",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * 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/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.common;
  
  /**
   * Abstract implementation of Container interface.
   * There is no behaviour here yet, as this is just a place holder 
   * for a class that should exist
   * 
   * */
  public abstract class AbstractContainer 
      extends AbstractComponent
      implements Container
  {
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/common/AbstractStateManageable.java
  
  Index: AbstractStateManageable.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" 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",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * 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/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.common;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * Abstract implementation of JSR77 StateManageable.
   * Implementors of StateManageable may use this class and simply provide 
   * doStart, doStop and doNotification methods.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/14 07:14:33 $
   */
  public abstract class AbstractStateManageable implements StateManageable
  {
      protected Log log= LogFactory.getLog(getClass());
      
      private State state= State.STOPPED;
      private long startTime;
  
      /**
       * Do the start tasks for the component.  Called in the STARTING state by 
       * the start() and startRecursive() methods to perform the tasks required to 
       * start the component.
       * @throws Exception
       */
      public abstract void doStart() throws Exception;
      
      /**
       * Do the stop tasks for the component.  Called in the STOPPING state by the stop()
       * method to perform the tasks required to stop the component.
       * @throws Exception
       */
      public abstract void doStop() throws Exception;
  
      /**
       * Do the notification of a state change.
       * @param eventTypeValue Event to notify
       */
      public abstract void doNotification(String eventTypeValue);
  
  
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.common.StateManageable#getStateInstance()
       */
      public State getStateInstance()
      {
          return state;
      }
      
      /* (non-Javadoc)
       * @see org.apache.geronimo.common.StateManageable#getState()
       */
      public int getState()
      {
          return state.toInt();
      }
  
      /**
       * Set the Component state.
       * @param newState
       * @throws IllegalStateException Thrown if the transition is not supported by the JSR77
lifecycle.
       */
      protected void setState(State newState) throws IllegalStateException
      {
          State oldState = state;
  
          switch (state.toInt())
          {
              case State.STOPPED_INDEX :
                  {
                      switch (newState.toInt())
                      {
                          case State.STARTING_INDEX :
                              break;
                          case State.STOPPED_INDEX :
                          case State.RUNNING_INDEX :
                          case State.STOPPING_INDEX :
                          case State.FAILED_INDEX :
                              throw new IllegalStateException(
                                  "Can not transition to " + newState + " state from " + state);
                      }
                      break;
                  }
  
              case State.STARTING_INDEX :
                  {
                      switch (newState.toInt())
                      {
                          case State.RUNNING_INDEX :
                          case State.FAILED_INDEX :
                          case State.STOPPING_INDEX :
                              break;
                          case State.STOPPED_INDEX :
                          case State.STARTING_INDEX :
                              throw new IllegalStateException(
                                  "Can not transition to " + newState + " state from " + state);
                      }
                      break;
                  }
  
              case State.RUNNING_INDEX :
                  {
                      switch (state.toInt())
                      {
                          case State.STOPPING_INDEX :
                          case State.FAILED_INDEX :
                              break;
                          case State.STOPPED_INDEX :
                          case State.STARTING_INDEX :
                          case State.RUNNING_INDEX :
                              throw new IllegalStateException(
                                  "Can not transition to " + newState + " state from " + state);
  
                      }
                      break;
                  }
  
              case State.STOPPING_INDEX :
                  {
                      switch (newState.toInt())
                      {
                          case State.STOPPED_INDEX :
                          case State.FAILED_INDEX :
                              break;
                          case State.STARTING_INDEX :
                          case State.RUNNING_INDEX :
                          case State.STOPPING_INDEX :
                              throw new IllegalStateException(
                                  "Can not transition to " + newState + " state from " + state);
                      }
                      break;
                  }
  
              case State.FAILED_INDEX :
                  {
                      switch (newState.toInt())
                      {
                          case State.STARTING_INDEX :
                          case State.STOPPING_INDEX :
                              break;
                          case State.STOPPED_INDEX :
                          case State.RUNNING_INDEX :
                          case State.FAILED_INDEX :
                              throw new IllegalStateException(
                                  "Can not transition to " + newState + " state from " + state);
                      }
                      break;
                  }
          }
          log.debug("State changed from " + state + " to " + newState);
          if (newState==State.RUNNING)
              startTime= System.currentTimeMillis();
          state= newState;
        
         doNotification(state.getEventTypeValue());
      }
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.common.StateManageable#getStartTime()
       */
      public long getStartTime()
      {
          return startTime;
      }
  
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.common.StateManageable#start()
       */
      public void start() throws Exception
      {
          try
          {
              setState(State.STARTING);
              doStart();
              setState(State.RUNNING);
          }
          finally
          {
              if (state != State.RUNNING)
                  setState(State.FAILED);
          }
      }
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.common.StateManageable#startRecursive()
       */
      public void startRecursive() throws Exception
      {
          start();
      }
  
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.common.StateManageable#stop()
       */
      public void stop()
      {
          // Do the actual stop tasks
          try
          {
              setState(State.STOPPING);
              doStop();
              setState(State.STOPPED);
          }
          catch (Exception e)
          {
              log.warn("Stop failed", e);
              setState(State.FAILED);
          }
      }
  
      
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/common/StateManageable.java
  
  Index: StateManageable.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" 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",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * 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/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.common;
  
  
  /**
   * Implements the JSR 77 state model
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/14 07:14:34 $
   */
  public interface StateManageable
  {
      /**
       * Gets the state of this component as an int.
       * The int return is required by the JSR77 specification.
       * @see getStateInstance to obtain the State instance
       * @return the current state of this component
       */
      int getState();
  
      /**
       * Gets the state of this component as a State instance.
       * @see getStateInstance to obtain the real state
       * @return the current state of this component
       */
      State getStateInstance();
  
      /**
       * Gets the start time of this component
       * @return time in milliseonds since epoch that this component was started.
       */
      long getStartTime();
      
  
      /**
       * Transitions the component to the starting state.  This method has access to the
       * container.
       *
       * Normally a component uses this to cache data from other components. The other components
will
       * have been created at this stage, but not necessairly started and may not be ready
to have methods
       * invoked on them.
       *
       * @throws java.lang.Exception if a problem occurs during the transition
       * @throws java.lang.IllegalStateException if this interceptor is not in the stopped
or failed state
       */
      void start() throws Exception, IllegalStateException;
  
      /**
       * Transitions the component to the starting state.  This method has access to the
       * container.
       * 
       * If this Component is a Container, then startRecursive is called on all child Components
       * that are in the STOPPED or FAILED state.
       * Normally a component uses this to cache data from other components. The other components
will
       * have been created at this stage, but not necessairly started and may not be ready
to have methods
       * invoked on them.
       *
       * @throws java.lang.Exception if a problem occurs during the transition
       * @throws java.lang.IllegalStateException if this interceptor is not in the STOPPED
or FAILED state
       */
      void startRecursive() throws Exception, IllegalStateException;
  
      /**
       * Transitions the component to the stopping state.  This method has access to the
       * container.
       *
       * If this is Component is a Container, then all its child components must be in the

       * STOPPED or FAILED State.
       * 
       * Normally a component uses this to drop references to data cached in the start method.
       * The other components will not necessairly have been stopped at this stage and may
not be ready
       * to have methods invoked on them.
       */
      void stop() throws IllegalStateException;
  
  }
  
  
  
  1.5       +8 -9      incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/container/ContainerImpl.java
  
  Index: ContainerImpl.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/container/ContainerImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ContainerImpl.java	13 Aug 2003 02:12:40 -0000	1.4
  +++ ContainerImpl.java	14 Aug 2003 07:14:34 -0000	1.5
  @@ -62,9 +62,8 @@
   import java.util.Map;
   import javax.management.ObjectName;
   
  -import org.apache.geronimo.common.AbstractComponent;
  +import org.apache.geronimo.common.AbstractContainer;
   import org.apache.geronimo.common.Component;
  -import org.apache.geronimo.common.Container;
   import org.apache.geronimo.common.Interceptor;
   import org.apache.geronimo.common.Invocation;
   import org.apache.geronimo.common.InvocationResult;
  @@ -74,12 +73,12 @@
    *
    *
    * @todo Currently this class implements the startRecursive method of 
  - * the JSR77 lifecycle. This should be moved to an AbstractContainer class
  + * the JSR77 lifecycle. This should be moved to the AbstractContainer class
    * @todo The stop method is implemented as stopRecursive, which should be moved
    * to an abstractContainer class
    * @version $Revision$ $Date$
    */
  -public class ContainerImpl extends AbstractComponent implements Container
  +public class ContainerImpl extends AbstractContainer
   {
       private final Map plugins= new LinkedHashMap();
       private final Map pluginObjects= new LinkedHashMap();
  @@ -132,7 +131,7 @@
           }
           finally
           {
  -            if (getState() != State.RUNNING)
  +            if (getStateInstance() != State.RUNNING)
                   setState(State.FAILED);
           }
       }
  @@ -178,7 +177,7 @@
           }
           finally
           {
  -            if (getState() != State.STOPPED)
  +            if (getStateInstance() != State.STOPPED)
                   setState(State.FAILED);
           }
       }
  @@ -208,7 +207,7 @@
   
       public void putPlugin(String logicalPluginName, ObjectName objectName)
       {
  -        State state= getState();
  +        State state= getStateInstance();
           if (state != State.STOPPED)
           {
               throw new IllegalStateException(
  @@ -224,7 +223,7 @@
   
       public void putPluginObject(String logicalPluginName, Object plugin)
       {
  -        State state= getState();
  +        State state= getStateInstance();
           if (state != State.STOPPED)
           {
               throw new IllegalStateException(
  
  
  
  1.5       +6 -2      incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/context/TransactionInterceptor.java
  
  Index: TransactionInterceptor.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/ejb/context/TransactionInterceptor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TransactionInterceptor.java	13 Aug 2003 02:12:40 -0000	1.4
  +++ TransactionInterceptor.java	14 Aug 2003 07:14:34 -0000	1.5
  @@ -74,8 +74,12 @@
       private Container container;
       private Interceptor nextInterceptor;
   
  -    public State getState() {
  +    public int getState() {
           return transactionInterceptor.getState();
  +    }
  +    
  +    public State getStateInstance() {
  +        return transactionInterceptor.getStateInstance();
       }
   
       public long getStartTime(){
  
  
  

Mime
View raw message