geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject cvs commit: incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service GeronimoMBeanEndpointListener.java GeronimoMBean.java GeronimoMBeanEndpoint.java GeronimoMBeanEndpointConnection.java GeronimoMBeanInfo.java
Date Tue, 30 Dec 2003 08:25:32 GMT
djencks     2003/12/30 00:25:32

  Modified:    modules/kernel/src/java/org/apache/geronimo/kernel/deployment/service
                        MBeanMetadata.java
               modules/kernel/src/java/org/apache/geronimo/kernel/service
                        GeronimoMBean.java GeronimoMBeanEndpoint.java
                        GeronimoMBeanEndpointConnection.java
                        GeronimoMBeanInfo.java
  Added:       modules/kernel/src/java/org/apache/geronimo/kernel/service
                        GeronimoMBeanEndpointListener.java
  Log:
  Add endpoints based on listeners rather than collection valued attributes.  Also fix a serious
bug with adding endpoints before they were started if they are GeronimoMBeans
  
  Revision  Changes    Path
  1.6       +2 -3      incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/deployment/service/MBeanMetadata.java
  
  Index: MBeanMetadata.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/deployment/service/MBeanMetadata.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MBeanMetadata.java	16 Nov 2003 00:51:24 -0000	1.5
  +++ MBeanMetadata.java	30 Dec 2003 08:25:32 -0000	1.6
  @@ -56,12 +56,11 @@
   package org.apache.geronimo.kernel.deployment.service;
   
   import java.net.URI;
  -import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.HashSet;
  -import java.util.List;
   import java.util.Map;
   import java.util.Set;
  +
   import javax.management.ObjectName;
   
   import org.apache.geronimo.kernel.service.GeronimoMBeanInfo;
  
  
  
  1.11      +28 -22    incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBean.java
  
  Index: GeronimoMBean.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBean.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- GeronimoMBean.java	28 Dec 2003 19:28:58 -0000	1.10
  +++ GeronimoMBean.java	30 Dec 2003 08:25:32 -0000	1.11
  @@ -163,37 +163,20 @@
               // @todo there is an issue here with restarted deployments
               addManagedObjectMBeanInfo();
               mbeanInfo = new GeronimoMBeanInfo(mbeanInfo);
  -        } finally {
  -            Thread.currentThread().setContextClassLoader(oldClassLoader);
  -        }
  -        return this.objectName;
  -    }
  -
  -    public void postRegister(Boolean registrationDone) {
  -        if (!registrationDone.booleanValue()) {
  -            context = null;
  -            return;
  -        }
  -
  -        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
  -        try {
  -            // Set the class loader
  -            Thread.currentThread().setContextClassLoader(classLoader);
  -
               // build the attribute map
               Set attributes = mbeanInfo.getAttributeSet();
               for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
                   GeronimoAttributeInfo attributeInfo = (GeronimoAttributeInfo) iterator.next();
  -                final String name = attributeInfo.getName();
  -                attributeInfoMap.put(name, attributeInfo);
  +                final String attributeName = attributeInfo.getName();
  +                attributeInfoMap.put(attributeName, attributeInfo);
   
                   if (attributeInfo.isReadable()) {
                       String getterName = (attributeInfo.isIs() ? "is" : "get") +
  -                            Character.toUpperCase(name.charAt(0)) + name.substring(1);
  +                            Character.toUpperCase(attributeName.charAt(0)) + attributeName.substring(1);
                       operationInfoMap.put(new MBeanOperationSignature(getterName, null),
attributeInfo);
                   }
                   if (attributeInfo.isWritable()) {
  -                    String setterName = "set" + Character.toUpperCase(name.charAt(0)) +
name.substring(1);
  +                    String setterName = "set" + Character.toUpperCase(attributeName.charAt(0))
+ attributeName.substring(1);
                       operationInfoMap.put(new MBeanOperationSignature(setterName, new String[]{attributeInfo.getType()}),
attributeInfo);
                   }
               }
  @@ -220,6 +203,23 @@
                   GeronimoMBeanEndpoint endpoint = (GeronimoMBeanEndpoint) i.next();
                   endpoint.setMBeanContext(context);
               }
  +        } finally {
  +            Thread.currentThread().setContextClassLoader(oldClassLoader);
  +        }
  +        return this.objectName;
  +    }
  +
  +    public void postRegister(Boolean registrationDone) {
  +        if (!registrationDone.booleanValue()) {
  +            context = null;
  +            return;
  +        }
  +
  +        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
  +        try {
  +            // Set the class loader
  +            Thread.currentThread().setContextClassLoader(classLoader);
  +
               super.postRegister(registrationDone);
           } finally {
               Thread.currentThread().setContextClassLoader(oldClassLoader);
  @@ -527,6 +527,12 @@
           MBeanOperationSignature key = new MBeanOperationSignature(methodName, types);
           Object info = operationInfoMap.get(key);
           if (info == null) {
  +            log.info("Operation not found on mbean" + this.objectName + ", method: " +
methodName + ", paramtypes: " + types);
  +            log.info("MBeanInfo is immutable: " + mbeanInfo.immutable + " on mbeanInfo:
" + mbeanInfo);
  +            for (Iterator iterator = operationInfoMap.keySet().iterator(); iterator.hasNext();)
{
  +                MBeanOperationSignature mBeanOperationSignature = (MBeanOperationSignature)
iterator.next();
  +                log.info("Operation: " + mBeanOperationSignature);
  +            }
               throw new ReflectionException(new NoSuchMethodException("Unknown operation
" + key));
           }
   
  
  
  
  1.6       +64 -31    incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBeanEndpoint.java
  
  Index: GeronimoMBeanEndpoint.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBeanEndpoint.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- GeronimoMBeanEndpoint.java	16 Nov 2003 23:32:29 -0000	1.5
  +++ GeronimoMBeanEndpoint.java	30 Dec 2003 08:25:32 -0000	1.6
  @@ -63,6 +63,7 @@
   import java.util.Iterator;
   import java.util.Map;
   import java.util.Set;
  +
   import javax.management.AttributeNotFoundException;
   import javax.management.InstanceNotFoundException;
   import javax.management.JMException;
  @@ -121,12 +122,12 @@
       private final Class iface;
   
       /**
  -     * The object name patters for object to communicate with
  +     * The object name patterns for object(s) to communicate with
        */
       private Collection peers;
   
       /**
  -     * The connection to the other mbean
  +     * The connections to the other mbeans
        */
       private Map connections;
   
  @@ -153,11 +154,16 @@
   
       /**
        * Name of the setter method.
  -     * The default is "set" + name.  In the case of a defualt value we do a caseless search
for the name.
  +     * The default is "set" + name.  In the case of a default value we do a caseless search
for the name.
        */
       private String setterName;
   
       /**
  +     * Listener for endpoint add/remove events.
  +     */
  +    private GeronimoMBeanEndpointListener endpointListener;
  +
  +    /**
        * The object on which the getter and setter will be invoked
        */
       private final Object target;
  @@ -197,17 +203,25 @@
       public GeronimoMBeanEndpoint(String name, Class type, ObjectName pattern) {
           this(name, type.getName(), Collections.singleton(pattern), false);
       }
  -    
  +
  +    public GeronimoMBeanEndpoint(GeronimoMBeanEndpointListener endpointListener, Class
type, ObjectName pattern) {
  +        this(null, endpointListener, type.getName(), Collections.singleton(pattern), false,
null);
  +    }
  +
       public GeronimoMBeanEndpoint(String name, String type, ObjectName pattern, boolean
required) {
           this(name, type, Collections.singleton(pattern), required);
       }
   
       public GeronimoMBeanEndpoint(String name, Class type, ObjectName pattern, boolean required)
{
           this(name, type.getName(), Collections.singleton(pattern), required);
  -    }    
  -    
  -    public GeronimoMBeanEndpoint(String name, String type, ObjectName pattern, boolean
required, String target) {
  -        this(name, type, Collections.singleton(pattern), required, target);
  +    }
  +
  +    public GeronimoMBeanEndpoint(String name, String type, ObjectName pattern, boolean
required, String targetName) {
  +        this(name, type, Collections.singleton(pattern), required, targetName);
  +    }
  +
  +    public GeronimoMBeanEndpoint(GeronimoMBeanEndpointListener endpointListener, String
type, ObjectName pattern, boolean required, String targetName) {
  +        this(null, endpointListener, type, Collections.singleton(pattern), required, targetName);
       }
   
       public GeronimoMBeanEndpoint(String name, String type, Collection peers) {
  @@ -219,7 +233,12 @@
       }
   
       public GeronimoMBeanEndpoint(String name, String type, Collection peers, boolean required,
String targetName) {
  +        this(name, null, type, peers, required, targetName);
  +    }
  +
  +    public GeronimoMBeanEndpoint(String name, GeronimoMBeanEndpointListener endpointListener,
String type, Collection peers, boolean required, String targetName) {
           this.name = name;
  +        this.endpointListener = endpointListener;
           this.type = type;
           this.peers = new HashSet(peers);
           this.required = required;
  @@ -245,8 +264,8 @@
           //
   
           // name
  -        if (source.name == null) {
  -            throw new IllegalArgumentException("Source must have a name");
  +        if (source.name == null && source.endpointListener == null) {
  +            throw new IllegalArgumentException("Source must have a name or an endpoint
listener");
           }
           name = source.name;
   
  @@ -285,6 +304,7 @@
   
           name = source.name;
           description = source.description;
  +        endpointListener = source.endpointListener;
   
           //
           // Optional (derived)
  @@ -305,6 +325,11 @@
               }
           }
   
  +        //initialize endpoint listener
  +        if (endpointListener != null) {
  +            endpointListener.setTarget(target);
  +        }
  +
           // setter proxy
           Method[] methods = target.getClass().getMethods();
           Method setterJavaMethod = null;
  @@ -330,20 +355,25 @@
           }
   
           if (setterJavaMethod == null) {
  -            throw new IllegalArgumentException("Setter method not found on target:" +
  -                    " setterName=" + setterName +
  -                    " targetClass=" + target.getClass().getName());
  -        }
  -
  -        if (Collection.class == setterJavaMethod.getParameterTypes()[0]) {
  +            if (endpointListener == null) {
  +                throw new IllegalArgumentException("Setter method not found on target:"
+
  +                        " setterName=" + setterName +
  +                        " targetClass=" + target.getClass().getName());
  +            }
               singleValued = false;
  -        } else if (setterJavaMethod.getParameterTypes()[0].isAssignableFrom(iface)) {
  -            singleValued = true;
  +            setterMethod = null;
           } else {
  -            throw new IllegalArgumentException("Setter parameter must be Collection or
" + type);
  -        }
   
  -        setterMethod = parent.getTargetFastClass(targetName).getMethod(setterJavaMethod);
  +            if (Collection.class == setterJavaMethod.getParameterTypes()[0]) {
  +                singleValued = false;
  +            } else if (setterJavaMethod.getParameterTypes()[0].isAssignableFrom(iface))
{
  +                singleValued = true;
  +            } else {
  +                throw new IllegalArgumentException("Setter parameter must be Collection
or " + type);
  +            }
  +
  +            setterMethod = parent.getTargetFastClass(targetName).getMethod(setterJavaMethod);
  +        }
       }
   
       public String getName() {
  @@ -562,6 +592,7 @@
                   setEndpointProxy(connection.getProxy());
               }
           } else {
  +            //Is this really live?
               setEndpointProxy(Collections.unmodifiableCollection(proxies.values()));
           }
       }
  @@ -597,14 +628,16 @@
       }
   
       private synchronized void setEndpointProxy(Object proxy) {
  -        try {
  -            setterMethod.invoke(target, new Object[]{proxy});
  -        } catch (RuntimeException e) {
  -            throw e;
  -        } catch (Error e) {
  -            throw e;
  -        } catch (Throwable t) {
  -            throw new AssertionError(t);
  +        if (setterMethod != null) {
  +            try {
  +                setterMethod.invoke(target, new Object[]{proxy});
  +            } catch (RuntimeException e) {
  +                throw e;
  +            } catch (Error e) {
  +                throw e;
  +            } catch (Throwable t) {
  +                throw new AssertionError(t);
  +            }
           }
       }
   
  @@ -686,7 +719,7 @@
           }
   
           // create a connection
  -        final GeronimoMBeanEndpointConnection connection = new GeronimoMBeanEndpointConnection(iface,
context.getServer(), peer);
  +        final GeronimoMBeanEndpointConnection connection = new GeronimoMBeanEndpointConnection(iface,
context.getServer(), peer, endpointListener);
           connections.put(peer, connection);
   
           // update running state
  
  
  
  1.5       +14 -2     incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBeanEndpointConnection.java
  
  Index: GeronimoMBeanEndpointConnection.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBeanEndpointConnection.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- GeronimoMBeanEndpointConnection.java	14 Nov 2003 02:59:17 -0000	1.4
  +++ GeronimoMBeanEndpointConnection.java	30 Dec 2003 08:25:32 -0000	1.5
  @@ -88,6 +88,8 @@
        */
       private ObjectName objectName;
   
  +    private final GeronimoMBeanEndpointListener endpointListener;
  +
       /**
        * A factory to create instances
        */
  @@ -120,7 +122,7 @@
        * @param server the mbean server in which the component is registered
        * @param objectName the name of the component
        */
  -    public GeronimoMBeanEndpointConnection(Class iface, MBeanServer server, ObjectName
objectName) {
  +    public GeronimoMBeanEndpointConnection(Class iface, MBeanServer server, ObjectName
objectName, GeronimoMBeanEndpointListener endpointListener) {
           assert iface != null: "iface can not be null";
           assert server != null: "Server can not be null";
           assert objectName != null: "Object name can not be null";
  @@ -134,6 +136,7 @@
   
           this.server = server;
           this.objectName = objectName;
  +        this.endpointListener = endpointListener;
   
           MethodInterceptor dummyInterceptor = new MethodInterceptor() {
               public Object intercept(Object obj, Method method, Object[] args, MethodProxy
proxy) throws Throwable {
  @@ -149,6 +152,9 @@
                   if(Modifier.isStatic(method.getModifiers())) {
                       return Callbacks.NO_OP;
                   }
  +                if(Modifier.isFinal(method.getModifiers())) {
  +                    return Callbacks.NO_OP;
  +                }
                   return Callbacks.INTERCEPT;
               }
           });
  @@ -222,6 +228,9 @@
           methodInterceptor = new ConnectionMethodInterceptor(methodTable, server, objectName);
           proxy = factory.newInstance(methodInterceptor);
           open = true;
  +        if (endpointListener != null) {
  +            endpointListener.endpointAdded(proxy);
  +        }
       }
   
       /**
  @@ -230,6 +239,9 @@
       public synchronized void close() {
           if (!open) {
               throw new IllegalStateException("Connection is already closed");
  +        }
  +        if (endpointListener != null) {
  +            endpointListener.endpointRemoved(proxy);
           }
           methodInterceptor.invalidate();
           methodInterceptor = null;
  
  
  
  1.13      +18 -3     incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBeanInfo.java
  
  Index: GeronimoMBeanInfo.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBeanInfo.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- GeronimoMBeanInfo.java	26 Nov 2003 02:10:08 -0000	1.12
  +++ GeronimoMBeanInfo.java	30 Dec 2003 08:25:32 -0000	1.13
  @@ -104,7 +104,8 @@
       private static final MBeanConstructorInfo[] NO_CONSTRUCTORS = new MBeanConstructorInfo[0];
   
       private boolean autostart = false;
  -    private final boolean immutable;
  +    //private
  +    final boolean immutable;
       private final int hashCode = System.identityHashCode(this);
       private String name;
       private String description;
  @@ -480,6 +481,20 @@
       }
   
       public String toString() {
  -        return "[GeronimoMBeanInfo: name=" + name + " description=" + description + "]";
  +        StringBuffer result = new StringBuffer("[GeronimoMBeanInfo: id=").append(super.toString()).append("
name=").append(name).append(" description=").append(description).append(" immutable=").append(immutable);
  +        for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
  +            GeronimoAttributeInfo geronimoAttributeInfo = (GeronimoAttributeInfo) iterator.next();
  +            result.append("\n    attribute: ").append(geronimoAttributeInfo);
  +        }
  +        for (Iterator iterator = operations.iterator(); iterator.hasNext();) {
  +            GeronimoOperationInfo geronimoOperationInfo = (GeronimoOperationInfo) iterator.next();
  +            result.append("\n    operation: ").append(geronimoOperationInfo);
  +        }
  +        for (Iterator iterator = endpoints.iterator(); iterator.hasNext();) {
  +            GeronimoMBeanEndpoint geronimoMBeanEndpoint = (GeronimoMBeanEndpoint) iterator.next();
  +            result.append("\n    endpoint: ").append(geronimoMBeanEndpoint);
  +        }
  +        result.append("]");
  +        return result.toString();
       }
   }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBeanEndpointListener.java
  
  Index: GeronimoMBeanEndpointListener.java
  ===================================================================
  package org.apache.geronimo.kernel.service;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/12/30 08:25:32 $
   *
   * */
  public interface GeronimoMBeanEndpointListener {
  
      void setTarget(Object target);
  
      void endpointAdded(Object endpoint);
  
      void endpointRemoved(Object endpoint);
  
  }
  
  
  

Mime
View raw message