Home » geronimo-2.2-source-release » org.apache.geronimo.kernel.management » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package org.apache.geronimo.kernel.management;
   19   
   20   import java.io.Serializable;
   21   
   22   
   23   /**
   24    * This class contains a type safe enumeration of the states from the J2EE Management specification.
   25    *
   26    * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
   27    */
   28   public final class State implements Serializable {
   29       public static final int STARTING_INDEX = 0;
   30       public static final int RUNNING_INDEX = 1;
   31       public static final int STOPPING_INDEX = 2;
   32       public static final int STOPPED_INDEX = 3;
   33       public static final int FAILED_INDEX = 4;
   34   
   35       public static final State STARTING = new State("starting", STARTING_INDEX, NotificationType.STATE_STARTING);
   36       public static final State RUNNING = new State("running", RUNNING_INDEX, NotificationType.STATE_RUNNING);
   37       public static final State STOPPING = new State("stopping", STOPPING_INDEX, NotificationType.STATE_STOPPING);
   38       public static final State STOPPED = new State("stopped", STOPPED_INDEX, NotificationType.STATE_STOPPED);
   39       public static final State FAILED = new State("failed", FAILED_INDEX, NotificationType.STATE_FAILED);
   40   
   41       private static final State[] fromInt = {STARTING, RUNNING, STOPPING, STOPPED, FAILED};
   42   
   43       /**
   44        * Get a State from an int index
   45        *
   46        * @param index int index of the state
   47        * @return The State instance or null if no such State.
   48        */
   49       public static State fromInt(int index) {
   50           if (index < 0 || index >= fromInt.length) {
   51               return null;
   52           }
   53           return fromInt[index];
   54       }
   55   
   56       /**
   57        * Get a State from an Integer index
   58        *
   59        * @param index Integer index of the state
   60        * @return The State instance or null if no such State.
   61        */
   62       public static State fromInteger(Integer index) {
   63           return fromInt(index.intValue());
   64       }
   65   
   66       public static String toString(int state) {
   67           if (state < 0 || state >= fromInt.length) {
   68               throw new IllegalArgumentException("State must be between 0 and " + fromInt.length);
   69           }
   70           return fromInt[state].name;
   71       }
   72   
   73       /**
   74        * The user readable name of this state from the J2EE Management specification
   75        */
   76       private final String name;
   77   
   78       /**
   79        * The state index from the J2EE Management specification
   80        */
   81       private final int index;
   82   
   83       /**
   84        * Type value to be broadcasted on entering this state.
   85        */
   86       private final String eventTypeValue;
   87   
   88       private State(String name, int index, String anEventTypeValue) {
   89           this.name = name;
   90           this.index = index;
   91           eventTypeValue = anEventTypeValue;
   92       }
   93   
   94       /**
   95        * Gets the integer value of this state as specified in the J2EE Management specification
   96        */
   97       public int toInt() {
   98           return index;
   99       }
  100   
  101       /**
  102        * Gets the event type that should be send after changeing to this state.
  103        *
  104        * @return the event type that should be sent after a transistion to this state
  105        */
  106       public String getEventTypeValue() {
  107           return eventTypeValue;
  108       }
  109   
  110       public String getName() {
  111           return name;
  112       }
  113   
  114       public boolean isRunning() {
  115           return this == State.RUNNING;
  116       }
  117   
  118       public boolean isStopped() {
  119           return this == State.STOPPED;
  120       }
  121   
  122       public boolean isFailed() {
  123           return this == State.FAILED;
  124       }
  125   
  126       public String toString() {
  127           return name;
  128       }
  129   
  130       private Object readResolve() {
  131           return fromInt[index];
  132       }
  133   }

Home » geronimo-2.2-source-release » org.apache.geronimo.kernel.management » [javadoc | source]