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/specs/j2ee-management/src/test/org/apache/management/j2ee StateTest.java
Date Mon, 18 Aug 2003 13:29:30 GMT
gregw       2003/08/18 06:29:30

  Modified:    specs/j2ee-management project.xml
  Added:       specs/j2ee-management/src/java/org/apache/management/j2ee
                        NotificationType.java State.java
                        StateManageable.java
               specs/j2ee-management/src/test/org/apache/management/j2ee
                        StateTest.java
  Log:
  moved jsr77 model to the spec package
  
  Revision  Changes    Path
  1.4       +1 -2      incubator-geronimo/specs/j2ee-management/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/j2ee-management/project.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- project.xml	16 Aug 2003 19:31:46 -0000	1.3
  +++ project.xml	18 Aug 2003 13:29:30 -0000	1.4
  @@ -14,7 +14,6 @@
     <siteDirectory></siteDirectory>
     <distributionDirectory></distributionDirectory>
     
  -  <package>javax.management.j2ee</package>
     <currentVersion>DEV</currentVersion>
     
     
  
  
  
  1.1                  incubator-geronimo/specs/j2ee-management/src/java/org/apache/management/j2ee/NotificationType.java
  
  Index: NotificationType.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.management.j2ee;
  
  import javax.management.Notification;
  import javax.management.NotificationFilterSupport;
  import javax.management.MBeanServerNotification;
  import javax.management.NotificationFilter;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/18 13:29:30 $
   */
  public interface NotificationType {
      /**
       * A new managed object was created.
       */
      String OBJECT_CREATED = "j2ee.object.created";
  
      /**
       * A managed object was deleted
       */
      String OBJECT_DELETED = "j2ee.object.deleted";
  
      /**
       * A state manageable object entered the starting state
       */
      String STATE_STARTING = "j2ee.state.starting";
  
      /**
       * A state manageable object entered the running state
       */
      String STATE_RUNNING = "j2ee.state.running";
  
      /**
       * A state manageable object entered the stopping state
       */
      String STATE_STOPPING = "j2ee.state.stopping";
  
      /**
       * A state manageable object entered the stopped state.
       */
      String STATE_STOPPED = "j2ee.state.stopped";
  
      /**
       * A state manageable object entered the failed state
       */
      String STATE_FAILED = "j2ee.state.failed";
  
      /**
       * An attribute has change value
       */
      String ATTRIBUTE_CHANGED = "j2ee.attribute.changed";
  
      /**
       * An array containg all of the know J2EE notification types
       */
      String[] TYPES = new String[]{
          OBJECT_CREATED, OBJECT_DELETED,
          STATE_STARTING, STATE_RUNNING, STATE_STOPPING, STATE_STOPPED, STATE_FAILED,
          ATTRIBUTE_CHANGED
      };
  
      /**
       * A notification filter which lets all J2EE notifications pass
       */
      NotificationFilter NOTIFICATION_FILTER = new NotificationFilter() {
          public boolean isNotificationEnabled(Notification notification) {
              String type = notification.getType();
              for (int i = 0; i < TYPES.length; i++) {
                  if(TYPES[i].equals(type)) {
                      return true;
                  }
              }
              return false;
          }
      };
  }
  
  
  
  1.1                  incubator-geronimo/specs/j2ee-management/src/java/org/apache/management/j2ee/State.java
  
  Index: State.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.management.j2ee;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/18 13:29:30 $
   */
  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, NotificationType.STATE_STARTING);
      public static final State RUNNING =
              new State("running", RUNNING_INDEX, NotificationType.STATE_RUNNING);
      public static final State STOPPING =
              new State("stopping", STOPPING_INDEX, NotificationType.STATE_STOPPING);
      public static final State STOPPED =
              new State("stopped", STOPPED_INDEX, NotificationType.STATE_STOPPED);
      public static final State FAILED =
              new State("failed", FAILED_INDEX, NotificationType.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;
  
      /**
       * Type value to be broadcasted on entering this state.
       */
      private final String eventTypeValue;
  
  
      private State(String name, int index, String anEventTypeValue) {
          this.name = name;
          this.index = index;
          eventTypeValue = anEventTypeValue;
      }
  
      public int toInt() {
          return index;
      }
  
      public String getEventTypeValue() {
          return eventTypeValue;
      }
  
      public String toString() {
          return name;
      }
  }
  
  
  
  1.1                  incubator-geronimo/specs/j2ee-management/src/java/org/apache/management/j2ee/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.management.j2ee;
  
  
  /**
   * Implements the JSR 77 state model
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/18 13:29:30 $
   */
  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.
       * @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.
       *
       * @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 stop() throws Exception, IllegalStateException;
  
  }
  
  
  
  1.1                  incubator-geronimo/specs/j2ee-management/src/test/org/apache/management/j2ee/StateTest.java
  
  Index: StateTest.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.management.j2ee;
  
  import junit.framework.TestCase;
  
  /**
   * Unit test for org.apache.geronimo.common.State class
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/18 13:29:30 $
   */
  
  public class StateTest extends TestCase {
  
      public void testValues() {
  
          assertEquals(0, State.STARTING_INDEX);
          assertEquals(1, State.RUNNING_INDEX);
          assertEquals(2, State.STOPPING_INDEX);
          assertEquals(3, State.STOPPED_INDEX);
          assertEquals(4, State.FAILED_INDEX);
  
          assertEquals(0, State.STARTING.toInt());
          assertEquals(1, State.RUNNING.toInt());
          assertEquals(2, State.STOPPING.toInt());
          assertEquals(3, State.STOPPED.toInt());
          assertEquals(4, State.FAILED.toInt());
      }
  
      public void testLessThanMin() {
          assertNull(State.fromInt(-1));
      }
  
      public void testGreaterThanMax() {
          assertNull(State.fromInt(5));
      }
  
      public void testName() {
          assertEquals("starting", State.STARTING.toString());
          assertEquals("running", State.RUNNING.toString());
          assertEquals("stopping", State.STOPPING.toString());
          assertEquals("stopped", State.STOPPED.toString());
          assertEquals("failed", State.FAILED.toString());
      }
  
      public void testEventTypeValue() {
          assertEquals("j2ee.state.starting", State.STARTING.getEventTypeValue());
          assertEquals("j2ee.state.running", State.RUNNING.getEventTypeValue());
          assertEquals("j2ee.state.stopping", State.STOPPING.getEventTypeValue());
          assertEquals("j2ee.state.stopped", State.STOPPED.getEventTypeValue());
          assertEquals("j2ee.state.failed", State.FAILED.getEventTypeValue());
      }
  }
  
  
  

Mime
View raw message