geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject cvs commit: incubator-geronimo/modules/common/src/test/org/apache/geronimo/common/jmx MBeanProxyFactoryTest.java
Date Sat, 30 Aug 2003 20:38:46 GMT
jdillon     2003/08/30 13:38:46

  Modified:    modules/common/src/java/org/apache/geronimo/common/jmx
                        MBeanProxyFactory.java MBeanProxyHandler.java
               modules/common/src/test/org/apache/geronimo/common/jmx
                        MBeanProxyFactoryTest.java
  Added:       modules/common/src/java/org/apache/geronimo/common/jmx
                        MBeanProxyContext.java
  Log:
   o Drop MBeanProxyFactory.MBeanProxy type in favor of MBeanProxyContext
  
  Revision  Changes    Path
  1.4       +19 -34    incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/jmx/MBeanProxyFactory.java
  
  Index: MBeanProxyFactory.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/jmx/MBeanProxyFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MBeanProxyFactory.java	30 Aug 2003 20:12:23 -0000	1.3
  +++ MBeanProxyFactory.java	30 Aug 2003 20:38:46 -0000	1.4
  @@ -82,14 +82,14 @@
       /**
        * Creates an MBean proxy using the specified interface to the objectName.
        *
  -     * @param type          The interface to implement for this proxy
  -     * @param server        The MBeanServer in which the object is registered
  -     * @param objectName    The objectName of the MBean to proxy
  -     * @return              The new MBean proxy, which implemnts the specified interface.
  +     * @param type      The interface to implement for this proxy
  +     * @param server    The MBeanServer in which the object is registered
  +     * @param target    The objectName of the MBean to proxy
  +     * @return          The new MBean proxy, which implemnts the specified interface.
        */
       public static Object create(final Class type,
                                   final MBeanServer server,
  -                                final ObjectName objectName)
  +                                final ObjectName target)
       {
           if (type == null) {
               throw new NullArgumentException("type");
  @@ -102,9 +102,15 @@
           }
           
           ClassLoader cl = type.getClassLoader();
  -        Class[] types = { type, MBeanProxy.class };
           
  -        MBeanProxyHandler handler =  new MBeanProxyHandler(server, objectName);
  +        //
  +        // jason: I am not sure if MPC will cause name clashes if the interface
  +        //        has a getObjectName() or getMBeanServer() method...
  +        //
  +        
  +        Class[] types = { type, MBeanProxyContext.class };
  +        
  +        MBeanProxyHandler handler =  new MBeanProxyHandler(server, target);
           
           return Proxy.newProxyInstance(cl, types, handler);
       }
  @@ -112,36 +118,15 @@
       /**
        * Creates an MBean proxy using the specified interface to the objectName.
        *
  -     * @param tyep          The interface to implement for this proxy
  -     * @param objectName    The objectName of the MBean to proxy
  -     * @return              The new MBean proxy, which implemnts the specified interface.
  +     * @param type      The interface to implement for this proxy
  +     * @param target    The objectName of the MBean to proxy
  +     * @return          The new MBean proxy, which implemnts the specified interface.
        */
  -    public static Object create(final Class type, final ObjectName objectName)
  +    public static Object create(final Class type, final ObjectName target)
       {
           MBeanServer server = MBeanServerLocator.locate();
           assert server != null;
           
  -        return create(type, server, objectName);
  -    }
  -    
  -    /**
  -     * An interface which all proxies created by {@link MBeanProxyFactory}
  -     * will implement in addition to the requested interface.
  -     */
  -    public static interface MBeanProxy
  -    {
  -        /**
  -         * Return the ObjectName for this proxy.
  -         *
  -         * @return   The ObjectName for this proxy.
  -         */
  -        ObjectName getMBeanProxyObjectName();
  -        
  -        /**
  -         * Return the MBeanServer for this proxy.
  -         *
  -         * @return   The ObjectName for this proxy.
  -         */
  -        MBeanServer getMBeanProxyMBeanServer();
  +        return create(type, server, target);
       }
   }
  
  
  
  1.3       +15 -19    incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/jmx/MBeanProxyHandler.java
  
  Index: MBeanProxyHandler.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/jmx/MBeanProxyHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MBeanProxyHandler.java	30 Aug 2003 20:19:03 -0000	1.2
  +++ MBeanProxyHandler.java	30 Aug 2003 20:38:46 -0000	1.3
  @@ -82,7 +82,7 @@
    * @version $Revision$ $Date$
    */
   public class MBeanProxyHandler
  -    implements InvocationHandler, MBeanProxyFactory.MBeanProxy
  +    implements InvocationHandler, MBeanProxyContext
   {
       protected final MBeanServer server;
       protected ObjectName target;
  @@ -113,8 +113,8 @@
           
           Class declaringClass = method.getDeclaringClass();
           
  -        // if the method belongs to MBeanProxy, then invoke locally
  -        if (declaringClass == MBeanProxyFactory.MBeanProxy.class) {
  +        // if the method belongs to MBeanProxyContext, then invoke locally
  +        if (declaringClass == MBeanProxyContext.class) {
               return method.invoke(this, args);
           }
           
  @@ -173,7 +173,7 @@
               throws Throwable
           {
               return server.getAttribute(
  -                getMBeanProxyObjectName(), 
  +                getObjectName(), 
                   info.getName()
               );
           }
  @@ -193,7 +193,7 @@
               throws Throwable
           {
               server.setAttribute(
  -                getMBeanProxyObjectName(),
  +                getObjectName(),
                   new Attribute(info.getName(), args[0])
               );
               
  @@ -219,7 +219,7 @@
               }
               
               return server.invoke(
  -                getMBeanProxyObjectName(),
  +                getObjectName(),
                   method.getName(),
                   args,
                   signature
  @@ -234,13 +234,10 @@
           
           if (taskCache == null) {
               // Allow sub-class overrides
  -            ObjectName objectName = getMBeanProxyObjectName();
  +            ObjectName target = getObjectName();
               
               // Get information about the target
  -            MBeanInfo info = server.getMBeanInfo(objectName);
  -            
  -            // Initialize the task cache
  -            taskCache = new HashMap();
  +            MBeanInfo info = server.getMBeanInfo(target);
               
               // Load up the attribute mapping
               attributeMap = new HashMap();
  @@ -248,6 +245,9 @@
               for (int i=0; i<attributes.length; i++) {
                   attributeMap.put(attributes[i].getName(), attributes[i]);
               }
  +            
  +            // Initialize the task cache
  +            taskCache = new HashMap();
           }
           
           String methodName = method.getName();
  @@ -317,19 +317,15 @@
       
       
       /////////////////////////////////////////////////////////////////////////
  -    //                              MBeanProxy                             //
  +    //                           MBeanProxyContext                         //
       /////////////////////////////////////////////////////////////////////////
       
  -    //
  -    // TODO: Replace with a MBeanProxyContext interface
  -    //
  -    
  -    public ObjectName getMBeanProxyObjectName()
  +    public ObjectName getObjectName()
       {
           return target;
       }
       
  -    public MBeanServer getMBeanProxyMBeanServer()
  +    public MBeanServer getMBeanServer()
       {
           return server;
       }
  
  
  
  1.1                  incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/jmx/MBeanProxyContext.java
  
  Index: MBeanProxyContext.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.jmx;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  
  /**
   * Provides access to the context in which an MBean proxy is running.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/30 20:38:46 $
   */
  public interface MBeanProxyContext
  {
      /**
       * Return the ObjectName for this proxy.
       *
       * @return   The ObjectName for this proxy.
       */
      ObjectName getObjectName();
      
      /**
       * Return the MBeanServer for this proxy.
       *
       * @return   The ObjectName for this proxy.
       */
      MBeanServer getMBeanServer();
  }
  
  
  
  1.2       +7 -7      incubator-geronimo/modules/common/src/test/org/apache/geronimo/common/jmx/MBeanProxyFactoryTest.java
  
  Index: MBeanProxyFactoryTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/common/src/test/org/apache/geronimo/common/jmx/MBeanProxyFactoryTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MBeanProxyFactoryTest.java	30 Aug 2003 20:19:03 -0000	1.1
  +++ MBeanProxyFactoryTest.java	30 Aug 2003 20:38:46 -0000	1.2
  @@ -137,18 +137,18 @@
           assertEquals(targetObject.setPoorlyNameOperation(), value);
       }
       
  -    public void testMBeanProxy() throws Exception
  +    public void testMBeanProxyContext() throws Exception
       {
           MockObjectMBean bean = (MockObjectMBean)
               MBeanProxyFactory.create(MockObjectMBean.class, server, target);
           assertNotNull(bean);
           
  -        assertTrue(bean instanceof MBeanProxyFactory.MBeanProxy);
  +        assertTrue(bean instanceof MBeanProxyContext);
           
  -        MBeanProxyFactory.MBeanProxy ctx = (MBeanProxyFactory.MBeanProxy)bean;
  -        assertNotNull(ctx.getMBeanProxyObjectName());
  -        assertEquals(target, ctx.getMBeanProxyObjectName());
  -        assertNotNull(ctx.getMBeanProxyMBeanServer());
  +        MBeanProxyContext ctx = (MBeanProxyContext)bean;
  +        assertNotNull(ctx.getObjectName());
  +        assertEquals(target, ctx.getObjectName());
  +        assertNotNull(ctx.getMBeanServer());
       }
       
       //
  
  
  

Mime
View raw message