You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by al...@apache.org on 2007/03/23 23:17:56 UTC

svn commit: r521919 - in /incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima: analysis_engine/ analysis_engine/impl/ internal/util/ resource/ resource/impl/ util/ util/impl/

Author: alally
Date: Fri Mar 23 15:17:50 2007
New Revision: 521919

URL: http://svn.apache.org/viewvc?view=rev&rev=521919
Log:
Added JMX MBeans for CAS Pools
UIMA-358: http://issues.apache.org/jira/browse/UIMA-358

Added:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ManagementObject.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPoolManagement.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImpl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImplMBean.java
Modified:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/AnalysisEngineManagement.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineImplBase.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineManagementImpl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/JmxMBeanAgent.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/CasManager.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/CasManager_impl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPool.java

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/AnalysisEngineManagement.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/AnalysisEngineManagement.java?view=diff&rev=521919&r1=521918&r2=521919
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/AnalysisEngineManagement.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/AnalysisEngineManagement.java Fri Mar 23 15:17:50 2007
@@ -22,6 +22,7 @@
 import java.util.Map;
 
 import org.apache.uima.cas.CAS;
+import org.apache.uima.resource.ManagementObject;
 
 /**
  * Monitoring and management interface to an AnalysisEngine. An application can obtain an instance
@@ -31,7 +32,7 @@
  * that you can register with an MBeanServer. For information on JMX see <a
  * href="http://java.sun.com/j2se/1.5.0/docs/api/javax/management/package-summary.html"/>
  */
-public interface AnalysisEngineManagement {
+public interface AnalysisEngineManagement extends ManagementObject {
   /**
    * Gets a name for this AnalysisEngineManagement object, which will be unique among all of its
    * siblings (i.e. the objects returned from its parent's {@link #getComponents()} method.
@@ -106,16 +107,4 @@
    * the statistics for all the components of the aggregate.
    */
   void resetStats();
-
-  /**
-   * Gets a valid JMX MBean name that is unique among all AnalysisEngineManagement objects in this
-   * JVM. (Technically, it is unique only among AnalysisEngineManagement objects loaded by the same
-   * ClassLoader, which is whatever ClassLoader was used to load the UIMA Framework classes.)
-   * <p>
-   * If you are running with JRE 1.5, this is the name used to register this object with the
-   * platform MBeanServer.
-   * 
-   * @return
-   */
-  String getUniqueMBeanName();
 }

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineImplBase.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineImplBase.java?view=diff&rev=521919&r1=521918&r2=521919
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineImplBase.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineImplBase.java Fri Mar 23 15:17:50 2007
@@ -91,6 +91,11 @@
    */
   private Object mMBeanServer;
 
+  /**
+   * An optional name prefix for this AnalysisEngine's MBean.
+   */
+  private String mMBeanNamePrefix;
+
   /*
    * (non-Javadoc)
    * 
@@ -110,11 +115,11 @@
       // read parameters from additionalParams map
       Properties perfSettings = null;
       mMBeanServer = null;
-      String mbeanNamePrefix = null;
+      mMBeanNamePrefix = null;
       if (aAdditionalParams != null) {
         perfSettings = (Properties) aAdditionalParams.get(PARAM_PERFORMANCE_TUNING_SETTINGS);
         mMBeanServer = aAdditionalParams.get(PARAM_MBEAN_SERVER);
-        mbeanNamePrefix = (String)aAdditionalParams.get(PARAM_MBEAN_NAME_PREFIX);
+        mMBeanNamePrefix = (String)aAdditionalParams.get(PARAM_MBEAN_NAME_PREFIX);
       }
       // set performance tuning settings
       if (perfSettings != null) {
@@ -123,8 +128,14 @@
       // register MBean with MBeanServer. If no MBeanServer specified in the
       // additionalParams map, this will use the platform MBean Server
       // (Java 1.5 only)
-      getMBean().setName(getMetaData().getName(), getUimaContextAdmin(), mbeanNamePrefix);
+      getMBean().setName(getMetaData().getName(), getUimaContextAdmin(), mMBeanNamePrefix);
       JmxMBeanAgent.registerMBean(getManagementInterface(), mMBeanServer);
+      
+      //if this is the root component, also configure the CAS Manager's JMX info at this point
+      //TODO: not really necessary to do this every time, only for the first AE we initialize that
+      //uses this CasManager.
+      getCasManager().setJmxInfo(mMBeanServer, 
+              getUimaContextAdmin().getRootContext().getManagementInterface().getUniqueMBeanName());
     }
     return result;
   }
@@ -512,5 +523,13 @@
    */
   protected boolean isProcessTraceEnabled() {
     return mProcessTraceEnabled;
+  }
+  
+  protected Object getMBeanServer() {
+    return mMBeanServer;
+  }
+  
+  protected String getMBeanNamePrefix() {
+    return mMBeanNamePrefix;
   }
 }

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineManagementImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineManagementImpl.java?view=diff&rev=521919&r1=521918&r2=521919
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineManagementImpl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/AnalysisEngineManagementImpl.java Fri Mar 23 15:17:50 2007
@@ -35,11 +35,11 @@
  * Implements Monitoring/Management interface to an AnalysisEngine.
  * 
  */
-public class AnalysisEngineManagementImpl implements AnalysisEngineManagementImplMBean,
-        AnalysisEngineManagement {
+public class AnalysisEngineManagementImpl 
+    implements AnalysisEngineManagementImplMBean, AnalysisEngineManagement {
 
   private static final long serialVersionUID = 1988620286191379887L;
- 
+  
   private static final Pattern RESERVED_CHAR_PATTERN = Pattern.compile("[\",=:*?]");
   
   static final DecimalFormat format = new DecimalFormat("0.##");
@@ -225,9 +225,8 @@
       prefix = aCustomPrefix;
       if (!prefix.endsWith(":") && !prefix.endsWith(",")) {
         prefix += ",";
-      }
+}
     }
-    
     // compute the unique name   
     // (first get the rootMBean and assign it a unique name if it doesn't already have one)
     AnalysisEngineManagementImpl rootMBean = (AnalysisEngineManagementImpl) aContext

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/JmxMBeanAgent.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/JmxMBeanAgent.java?view=diff&rev=521919&r1=521918&r2=521919
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/JmxMBeanAgent.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/JmxMBeanAgent.java Fri Mar 23 15:17:50 2007
@@ -23,12 +23,12 @@
 import java.lang.reflect.Method;
 
 import org.apache.uima.UIMAFramework;
-import org.apache.uima.analysis_engine.AnalysisEngineManagement;
+import org.apache.uima.resource.ManagementObject;
 import org.apache.uima.util.Level;
 
 /**
  * Utility class for registering MBeans with a JMX MBeanServer. This allows AnalysisEngine
- * performance stats to be monitored through JMX.
+ * performance stats to be monitored through JMX, for example.
  */
 public class JmxMBeanAgent {
   /**
@@ -41,7 +41,7 @@
    *          running under Java 1.5. Earlier versions of Java did not have a platform MBeanServer;
    *          in that case, this method will do nothing.
    */
-  public static void registerMBean(AnalysisEngineManagement aMBean, Object aMBeanServer) {
+  public static void registerMBean(ManagementObject aMBean, Object aMBeanServer) {
     if (!jmxAvailable) // means we couldn't find the required classes and methods
     {
       return;
@@ -88,7 +88,7 @@
    *          running under Java 1.5. Earlier versions of Java did not have a platform MBeanServer;
    *          in that case, this method will do nothing.
    */
-  public static void unregisterMBean(AnalysisEngineManagement aMBean, Object aMBeanServer) {
+  public static void unregisterMBean(ManagementObject aMBean, Object aMBeanServer) {
     if (!jmxAvailable) // means we couldn't find the required classes and methods
     {
       return;

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/CasManager.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/CasManager.java?view=diff&rev=521919&r1=521918&r2=521919
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/CasManager.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/CasManager.java Fri Mar 23 15:17:50 2007
@@ -25,6 +25,7 @@
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CasOwner;
 import org.apache.uima.resource.metadata.ProcessingResourceMetaData;
+import org.apache.uima.util.CasPoolManagement;
 
 /**
  * Manages creation and pooling of CAS instances within an AnalysisEngine.
@@ -63,7 +64,7 @@
    * @throws ResourceInitializationException
    *           if a CAS could not be created.
    */
-  void defineCasPool(String aRequestorContextName, int aSize, Properties aPerformanceTuningSettings)
+  void defineCasPool(String aRequestorContextName, int aMinimumSize, Properties aPerformanceTuningSettings)
           throws ResourceInitializationException;
 
   /**
@@ -101,5 +102,17 @@
    * @param requiredInterface
    *          interface to get. Currently must be either CAS or JCas.
    */
-  AbstractCas getCasInterface(CAS cas, Class requiredInterface);  
+  AbstractCas getCasInterface(CAS cas, Class requiredInterface);
+  
+  /**
+   * Configures this CAS Manager so it can register an MBean for each of its CAS pools.
+   * 
+   * @param aMBeanServer the JMX MBean Server to register MBeans with.  If null, the
+   *   platform MBeanServer (Java 1.5+ only) will be used.
+   * @param aRootComponentMBeanName unique MBean name for the root component that owns
+   *   this CAS Manager.  The names of the CAS Pool MBeans will be formed by appending
+   *   <code>,casPoolContextName=[contextName]</code> to the root component name, where
+   *   [contextName] is the requestorContextName for the CasPool.
+   */
+  public void setJmxInfo(Object aMBeanServer, String aRootComponentMBeanName);
 }

Added: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ManagementObject.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ManagementObject.java?view=auto&rev=521919
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ManagementObject.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ManagementObject.java Fri Mar 23 15:17:50 2007
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.resource;
+
+/**
+ * Base interface for objects that expose a monitoring and management interface to a 
+ * UIMA component or some part of the UIMA framework.
+ * <p>
+ * In this implementation, objects implementing this interface will always be JMX-compatible MBeans
+ * that you can register with an MBeanServer. For information on JMX see <a
+ * href="http://java.sun.com/j2se/1.5.0/docs/api/javax/management/package-summary.html"/>
+ */
+public interface ManagementObject {
+  /**
+   * Gets a valid JMX MBean name that is unique among all ManagementObjects in this
+   * JVM. (Technically, it is unique only among ManagementObjects objects loaded by the same
+   * ClassLoader, which is whatever ClassLoader was used to load the UIMA Framework classes.)
+   * <p>
+   * If you are running with JRE 1.5, this is the name used to register this object with the
+   * platform MBeanServer.
+   * 
+   * @return a unique MBean name
+   */
+  String getUniqueMBeanName();
+}

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/CasManager_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/CasManager_impl.java?view=diff&rev=521919&r1=521918&r2=521919
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/CasManager_impl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/CasManager_impl.java Fri Mar 23 15:17:50 2007
@@ -30,6 +30,7 @@
 import org.apache.uima.cas.CASException;
 import org.apache.uima.cas.TypeSystem;
 import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.internal.util.JmxMBeanAgent;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.resource.CasDefinition;
 import org.apache.uima.resource.CasManager;
@@ -38,6 +39,7 @@
 import org.apache.uima.resource.metadata.ProcessingResourceMetaData;
 import org.apache.uima.util.CasCreationUtils;
 import org.apache.uima.util.CasPool;
+import org.apache.uima.util.impl.CasPoolManagementImpl;
 
 /**
  * Simple CAS Manager Implementation used in the AnalysisEngine framework. Maintains a pool of 1 CAS
@@ -56,6 +58,10 @@
   
   private TypeSystem mCurrentTypeSystem = null;
 
+  private Object mMBeanServer;
+
+  private String mMBeanNamePrefix;
+
   public CasManager_impl(ResourceManager aResourceManager) {
     mResourceManager = aResourceManager;
   }
@@ -119,21 +125,25 @@
    * 
    * @see org.apache.uima.resource.CasManager#setMinimumCasPoolSize(java.lang.String, int)
    */
-  public void defineCasPool(String aRequestorContextName, int aSize,
+  public void defineCasPool(String aRequestorContextName, int aMinimumSize,
           Properties aPerformanceTuningSettings) throws ResourceInitializationException {
-    if (aSize > 0) {
+    if (aMinimumSize > 0) {
       CasPool pool = (CasPool) mRequestorToCasPoolMap.get(aRequestorContextName);
       if (pool == null) {
         // this requestor hasn't requested a CAS before
-        pool = new CasPool(aSize, this, aPerformanceTuningSettings);
+        pool = new CasPool(aMinimumSize, this, aPerformanceTuningSettings);
         populateCasToCasPoolMap(pool);
         mRequestorToCasPoolMap.put(aRequestorContextName, pool);
+        //register with JMX
+        registerCasPoolMBean(aRequestorContextName, pool);
+
       } else {
         throw new UIMARuntimeException(UIMARuntimeException.DEFINE_CAS_POOL_CALLED_TWICE,
                 new Object[] { aRequestorContextName });
       }
     }
   }
+
   
   /* (non-Javadoc)
    * @see org.apache.uima.resource.CasManager#createNewCas(java.util.Properties)
@@ -176,8 +186,25 @@
               new Object[] { requiredInterface });
     }
   }
+    
+  /* (non-Javadoc)
+   * @see org.apache.uima.resource.CasManager#setJmxInfo(java.lang.Object, java.lang.String)
+   */
+  public void setJmxInfo(Object aMBeanServer, String aRootMBeanName) {
+    mMBeanServer = aMBeanServer;
+    if (aRootMBeanName.endsWith("\"")) {
+      mMBeanNamePrefix = aRootMBeanName.substring(0, aRootMBeanName.length() - 1) + " CAS Pools\",";
+    }
+    else {
+      mMBeanNamePrefix = aRootMBeanName + " CAS Pools,";
+    }
+  }
 
-  private void populateCasToCasPoolMap(CasPool aCasPool) {
+  protected Map getCasToCasPoolMap() {
+    return mCasToCasPoolMap;
+  }
+  
+  protected void populateCasToCasPoolMap(CasPool aCasPool) {
     CAS[] casArray = new CAS[aCasPool.getSize()];
     for (int i = 0; i < casArray.length; i++) {
       casArray[i] = ((CASImpl) aCasPool.getCas()).getBaseCAS();
@@ -187,5 +214,18 @@
       aCasPool.releaseCas(casArray[i]);
     }
   }
+  
+  /**
+   * Registers an MBean for the given CasPool.
+   * @param aRequestorContextName context name that identifies this CasPool
+   * @param pool the CasPool
+   */
+  protected void registerCasPoolMBean(String aRequestorContextName, CasPool pool) {
+    if (mMBeanNamePrefix != null) {
+      String mbeanName = mMBeanNamePrefix + "casPoolContextName=" + aRequestorContextName;
+      CasPoolManagementImpl mbean = new CasPoolManagementImpl(pool, mbeanName);
+      JmxMBeanAgent.registerMBean(mbean, mMBeanServer);
+    }
+  }  
 
 }

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPool.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPool.java?view=diff&rev=521919&r1=521918&r2=521919
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPool.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPool.java Fri Mar 23 15:17:50 2007
@@ -269,6 +269,14 @@
   public int getSize() {
     return mNumInstances;
   }
+  
+  /**
+   * Gets the number of CASes currently available in this pool.
+   * @return the numberof available CASes 
+   */
+  public int getNumAvailable() {
+    return getFreeInstances().size();
+  }  
 
   /**
    * @param componentDescriptionsOrMetaData

Added: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPoolManagement.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPoolManagement.java?view=auto&rev=521919
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPoolManagement.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasPoolManagement.java Fri Mar 23 15:17:50 2007
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.util;
+
+import org.apache.uima.resource.ManagementObject;
+
+
+/**
+ * Management interface to a {@link CasPool}.
+ */
+public interface CasPoolManagement extends ManagementObject {
+  
+  /**
+   * Get the total size of the CAS Pool.
+   * @return the pool size
+   */
+  public int getPoolSize();
+  
+  /**
+   * Get the number of CAS instances currently available in the pool.
+   * @return the number of available CAS instances
+   */
+  public int getAvailableInstances();
+  
+  /**
+   * Get the average time, in milliseconds, that getCas() requests on
+   * the pool have to wait for a CAS to become available
+   * @return average wait time in milliseconds
+   */
+  public int getAverageWaitTime();
+}

Added: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImpl.java?view=auto&rev=521919
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImpl.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImpl.java Fri Mar 23 15:17:50 2007
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.util.impl;
+
+import org.apache.uima.util.CasPool;
+import org.apache.uima.util.CasPoolManagement;
+
+/**
+ * Implements Monitoring/Management interface to a CasPool.
+ */
+public class CasPoolManagementImpl implements CasPoolManagement, CasPoolManagementImplMBean {
+
+  private CasPool mCasPool;
+  private String mUniqueMBeanName;
+  
+  public CasPoolManagementImpl(CasPool aCasPool, String aUniqueMBeanName) {
+    mCasPool = aCasPool;
+    mUniqueMBeanName = aUniqueMBeanName; 
+  }
+  
+  /* (non-Javadoc)
+   * @see org.apache.uima.util.CasPoolManagement#getAvailableInstances()
+   */
+  public int getAvailableInstances() {
+    return mCasPool.getNumAvailable();
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.uima.util.CasPoolManagement#getAverageWaitTime()
+   */
+  public int getAverageWaitTime() {
+    // TODO Auto-generated method stub
+    return 0;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.uima.util.CasPoolManagement#getPoolSize()
+   */
+  public int getPoolSize() {
+    return mCasPool.getSize();
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.uima.resource.impl.ManagementObject_ImplBase#getUniqueMBeanName()
+   */
+  public String getUniqueMBeanName() {
+    return mUniqueMBeanName;
+  }  
+}

Added: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImplMBean.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImplMBean.java?view=auto&rev=521919
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImplMBean.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/impl/CasPoolManagementImplMBean.java Fri Mar 23 15:17:50 2007
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.util.impl;
+
+/**
+ * JMX MBean interface for monitoring CASPool state.
+ */
+public interface CasPoolManagementImplMBean {
+  /**
+   * Get the total size of the CAS Pool.
+   * @return the pool size
+   */
+  public int getPoolSize();
+  
+  /**
+   * Get the number of CAS instances currently available in the pool.
+   * @return the number of available CAS instances
+   */
+  public int getAvailableInstances();
+  
+  /**
+   * Get the average time, in milliseconds, that getCas() requests on
+   * the pool have to wait for a CAS to become available
+   * @return average wait time in milliseconds
+   */
+  public int getAverageWaitTime();
+}