geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel ConfigTest.java MockGBean.java
Date Thu, 15 Jan 2004 00:45:55 GMT
dain        2004/01/14 16:45:55

  Modified:    modules/kernel/src/java/org/apache/geronimo/gbean/jmx
                        AbstractManagedObject.java CollectionProxy.java
                        GBeanMBeanEndpoint.java ProxyMethodInterceptor.java
                        SingleProxy.java
               modules/kernel/src/test/org/apache/geronimo/kernel
                        ConfigTest.java MockGBean.java
  Log:
  Added dependency registration to SingleProxy
  SingleProxy will attempt a full start if it blocked the original start
  Fixed a bunch of bugs in ProxyMethodInterceptor around construction of the method table
  Got the start recurisve test in ConfigTest working
  
  Revision  Changes    Path
  1.2       +11 -1     incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java
  
  Index: AbstractManagedObject.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractManagedObject.java	12 Jan 2004 01:38:55 -0000	1.1
  +++ AbstractManagedObject.java	15 Jan 2004 00:45:54 -0000	1.2
  @@ -219,6 +219,14 @@
           return objectName.toString();
       }
   
  +    public final ObjectName getObjectNameObject() {
  +        return objectName;
  +    }
  +
  +    public DependencyService2MBean getDependencyService() {
  +        return dependencyService;
  +    }
  +
       public final boolean isStateManageable() {
           return true;
       }
  @@ -506,6 +514,7 @@
                       try {
                           doStart();
                       } catch (WaitingException e) {
  +                        log.debug("Waiting to start: objectName=\"" + objectName + "\"
reason=\"" + e.getMessage() + "\"");
                           return;
                       }
                       setStateInstance(State.RUNNING);
  @@ -576,6 +585,7 @@
                       try {
                           doStop();
                       } catch (WaitingException e) {
  +                        log.debug("Waiting to stop: objectName=\"" + objectName + "\" reason=\""
+ e.getMessage() + "\"");
                           return;
                       }
                       setStateInstance(State.STOPPED);
  
  
  
  1.3       +7 -16     incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/CollectionProxy.java
  
  Index: CollectionProxy.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/CollectionProxy.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CollectionProxy.java	14 Jan 2004 22:16:38 -0000	1.2
  +++ CollectionProxy.java	15 Jan 2004 00:45:54 -0000	1.3
  @@ -64,8 +64,8 @@
   import java.util.Set;
   import javax.management.ObjectName;
   
  -import org.apache.geronimo.kernel.jmx.InterfaceCallbackFilter;
   import org.apache.geronimo.gbean.WaitingException;
  +import org.apache.geronimo.kernel.jmx.InterfaceCallbackFilter;
   
   import net.sf.cglib.proxy.Enhancer;
   import net.sf.cglib.proxy.Factory;
  @@ -83,11 +83,6 @@
       private final GBeanMBean gmbean;
   
       /**
  -     * The proxy type
  -     */
  -    private final Class type;
  -
  -    /**
        * A map from object names to the proxy
        */
       private final Map proxies = new HashMap();
  @@ -109,7 +104,6 @@
   
       public CollectionProxy(GBeanMBean gmbean, Class type) {
           this.gmbean = gmbean;
  -        this.type = type;
           Enhancer enhancer = new Enhancer();
           enhancer.setSuperclass(Object.class);
           enhancer.setInterfaces(new Class[]{type});
  @@ -130,7 +124,7 @@
       public synchronized void addTarget(ObjectName target) {
           // if this is a new target...
           if (!proxies.containsKey(target)) {
  -            ProxyMethodInterceptor interceptor = new ProxyMethodInterceptor(type);
  +            ProxyMethodInterceptor interceptor = new ProxyMethodInterceptor(factory.getClass());
               interceptor.connect(gmbean.getServer(), target, proxy.isStopped());
               interceptors.put(target, interceptor);
               proxies.put(target, factory.newInstance(interceptor));
  @@ -138,13 +132,10 @@
       }
   
       public synchronized void removeTarget(ObjectName target) {
  -        // if this is one of our existing targets target...
  -        if (!proxies.containsKey(target)) {
  -            proxies.remove(target);
  -            ProxyMethodInterceptor interceptor = (ProxyMethodInterceptor) interceptors.remove(target);
  -            if (interceptor != null) {
  -                interceptor.disconnect();
  -            }
  +        proxies.remove(target);
  +        ProxyMethodInterceptor interceptor = (ProxyMethodInterceptor) interceptors.remove(target);
  +        if (interceptor != null) {
  +            interceptor.disconnect();
           }
       }
   
  
  
  
  1.2       +2 -2      incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanEndpoint.java
  
  Index: GBeanMBeanEndpoint.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanEndpoint.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GBeanMBeanEndpoint.java	14 Jan 2004 22:16:38 -0000	1.1
  +++ GBeanMBeanEndpoint.java	15 Jan 2004 00:45:54 -0000	1.2
  @@ -194,7 +194,7 @@
       public synchronized void online() throws ReflectionException {
           // create the proxy
           if (singleValued) {
  -            proxy = new SingleProxy(gmbean, name, type);
  +            proxy = new SingleProxy(gmbean, name, type, patterns);
           } else {
               proxy = new CollectionProxy(gmbean, type);
           }
  
  
  
  1.2       +5 -6      incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/ProxyMethodInterceptor.java
  
  Index: ProxyMethodInterceptor.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/ProxyMethodInterceptor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ProxyMethodInterceptor.java	12 Jan 2004 01:38:55 -0000	1.1
  +++ ProxyMethodInterceptor.java	15 Jan 2004 00:45:54 -0000	1.2
  @@ -117,6 +117,7 @@
           assert server != null && objectName != null;
           this.server = server;
           this.objectName = objectName;
  +        this.stopped = stopped;
           this.methodTable = ProxyMethodInterceptor.createMethodTable(server, objectName,
proxyType);
       }
   
  @@ -186,9 +187,8 @@
           Method[] methods = proxyType.getMethods();
           for (int i = 0; i < methods.length; i++) {
               Method method = methods[i];
  -            String superName = MethodProxy.getSuperName(proxyType, method);
  -            if (superName != null) {
  -                int index = fastClass.getIndex(superName, method.getParameterTypes());
  +            int index = getSuperIndex(fastClass, method);
  +            if (index >= 0) {
                   if (operations.containsKey(new MBeanOperationSignature(method))) {
                       methodTable[index] = new InvokeMBean(method, false, false);
                   } else if (method.getName().startsWith("get") && attributes.containsKey(method.getName().substring(3)))
{
  @@ -274,7 +274,6 @@
                   return enhancedClass.getIndex(name, parameterTypes);
               }
           }
  -        throw new IllegalArgumentException("Method not found on enhancedClass:" +
  -                " enhancedClass=" + enhancedClass.getJavaClass() + " method=" + method);
  +        return -1;
       }
   }
  
  
  
  1.3       +76 -17    incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/SingleProxy.java
  
  Index: SingleProxy.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/SingleProxy.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SingleProxy.java	14 Jan 2004 22:16:38 -0000	1.2
  +++ SingleProxy.java	15 Jan 2004 00:45:54 -0000	1.3
  @@ -55,17 +55,18 @@
    */
   package org.apache.geronimo.gbean.jmx;
   
  +import java.lang.reflect.Method;
   import java.util.HashSet;
   import java.util.Set;
   import javax.management.ObjectName;
   
  -import org.apache.geronimo.kernel.jmx.InterfaceCallbackFilter;
  -import org.apache.geronimo.kernel.management.State;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.gbean.WaitingException;
  -import org.apache.geronimo.gbean.jmx.GBeanMBean;
  -import org.apache.geronimo.gbean.jmx.Proxy;
  -import org.apache.geronimo.gbean.jmx.ProxyMethodInterceptor;
  +import org.apache.geronimo.kernel.management.State;
   
  +import net.sf.cglib.proxy.CallbackFilter;
  +import net.sf.cglib.proxy.Callbacks;
   import net.sf.cglib.proxy.Enhancer;
   import net.sf.cglib.proxy.Factory;
   import net.sf.cglib.proxy.SimpleCallbacks;
  @@ -76,6 +77,7 @@
    * @version $Revision$ $Date$
    */
   public class SingleProxy implements Proxy {
  +    private static final Log log = LogFactory.getLog(SingleProxy.class);
       /**
        * The GBeanMBean to which this proxy belongs.
        */
  @@ -87,6 +89,13 @@
       private final String name;
   
       /**
  +     * The ObjectName patterns to which this proxy could be connected.
  +     * This is used to block mbeans from starting that would match a
  +     * pattern while we are running.
  +     */
  +    private final Set patterns;
  +
  +    /**
        * A set of all targets matching the
        */
       private final Set targets = new HashSet();
  @@ -97,21 +106,31 @@
       private final Object proxy;
   
       /**
  +     * Is the GBeanMBean waitng for me to start?
  +     */
  +    private boolean waitingForMe = false;
  +
  +    /**
        * The interceptor for the proxy instance
        */
       private ProxyMethodInterceptor methodInterceptor;
   
  -    public SingleProxy(GBeanMBean gmbean, String name, Class type) {
  +    public SingleProxy(GBeanMBean gmbean, String name, Class type, Set patterns) {
           this.gmbean = gmbean;
           this.name = name;
  +        this.patterns = patterns;
           Enhancer enhancer = new Enhancer();
           enhancer.setSuperclass(Object.class);
           enhancer.setInterfaces(new Class[]{type});
  -        enhancer.setCallbackFilter(new InterfaceCallbackFilter(type));
  +        enhancer.setCallbackFilter(new CallbackFilter() {
  +            public int accept(Method method) {
  +                return Callbacks.INTERCEPT;
  +            }
  +        });
           enhancer.setCallbacks(new SimpleCallbacks());
           enhancer.setClassLoader(type.getClassLoader());
           Factory factory = enhancer.create();
  -        methodInterceptor = new ProxyMethodInterceptor(type);
  +        methodInterceptor = new ProxyMethodInterceptor(factory.getClass());
           proxy = factory.newInstance(methodInterceptor);
       }
   
  @@ -126,24 +145,59 @@
       public synchronized void addTarget(ObjectName target) {
           // if this is a new target...
           if (!targets.contains(target)) {
  +            if (targets.size() == 1) {
  +                // will be more then one target... remove the dependency
  +                ObjectName currentTarget = (ObjectName) targets.iterator().next();
  +                gmbean.getDependencyService().removeDependency(gmbean.getObjectNameObject(),
currentTarget);
  +            }
  +
               targets.add(target);
   
               // if we are running, we now have two valid targets, which is an illegal state
so we need to fail
               if (gmbean.getStateInstance() == State.RUNNING) {
                   gmbean.fail();
  +            } else if (targets.size() == 1) {
  +                // there is now just one target... add a dependency
  +                gmbean.getDependencyService().addDependency(gmbean.getObjectNameObject(),
target);
  +                if (waitingForMe) {
  +                    attemptFullStart();
  +                }
               }
  +
           }
       }
   
       public synchronized void removeTarget(ObjectName target) {
  -        // if this is a new target...
  -        if (!targets.contains(target)) {
  -            targets.remove(target);
  -
  -            // if we are running, we will no longer have a valid target, which is an illegal
state so we need to fail
  +        boolean wasTarget = targets.remove(target);
  +        if (wasTarget) {
               if (gmbean.getStateInstance() == State.RUNNING) {
  +                // we no longer have a valid target, which is an illegal state so we need
to fail
                   gmbean.fail();
  +            } else if (targets.size() == 1) {
  +                // we only have one target remaining... add a dependency
  +                ObjectName remainingTarget = (ObjectName) targets.iterator().next();
  +                gmbean.getDependencyService().addDependency(gmbean.getObjectNameObject(),
remainingTarget);
  +
  +                if (waitingForMe) {
  +                    attemptFullStart();
  +                }
  +            } else if (targets.isEmpty()) {
  +                // that was our last target... remove the dependency
  +                gmbean.getDependencyService().removeDependency(gmbean.getObjectNameObject(),
target);
               }
  +
  +        }
  +    }
  +
  +    private synchronized void attemptFullStart() {
  +        try {
  +            // there could be an issue with really badly written components holding up
a stop when the
  +            // component never reached the starting phase... then a target registers and
we automatically
  +            // attempt to restart
  +            waitingForMe = false;
  +            gmbean.attemptFullStart();
  +        } catch (Exception e) {
  +            log.warn("Exception occured while attempting to fully start: objetName=" +
gmbean.getObjectName());
           }
       }
   
  @@ -152,15 +206,20 @@
           // We must have exactally one running target
           //
           if (targets.size() == 0) {
  -            throw new WaitingException("No targets are running: endpointName=" + name);
  +            waitingForMe = true;
  +            throw new WaitingException("No targets are running for " + name + " endpoint");
           } else if (targets.size() > 1) {
  -            throw new WaitingException("More then one targets are running: endpointName="
+ name);
  +            waitingForMe = true;
  +            throw new WaitingException("More then one targets are running for " + name
+ " endpoint");
           }
  -
  +        waitingForMe = false;
  +        gmbean.getDependencyService().addStartHolds(gmbean.getObjectNameObject(), patterns);
           methodInterceptor.connect(gmbean.getServer(), (ObjectName) targets.iterator().next());
       }
   
       public synchronized void stop() {
  +        waitingForMe = false;
           methodInterceptor.disconnect();
  +        gmbean.getDependencyService().removeStartHolds(gmbean.getObjectNameObject(), patterns);
       }
   }
  
  
  
  1.5       +6 -4      incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java
  
  Index: ConfigTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConfigTest.java	14 Jan 2004 22:16:38 -0000	1.4
  +++ ConfigTest.java	15 Jan 2004 00:45:54 -0000	1.5
  @@ -103,13 +103,15 @@
           ObjectName configName = (ObjectName) mbServer.invoke(Kernel.KERNEL, "load", new
Object[]{config, null}, new String[]{GBeanMBean.class.getName(), URL.class.getName()});
           mbServer.invoke(configName, "startRecursive", null, null);
   
  -        assertEquals(new Integer(State.RUNNING.toInt()), mbServer.getAttribute(configName,
"state"));
  +        assertEquals(new Integer(State.RUNNING_INDEX), mbServer.getAttribute(configName,
"state"));
           assertNotNull(mbServer.getAttribute(configName, "ClassLoader"));
   
  -        assertEquals(new Integer(State.RUNNING.toInt()), mbServer.getAttribute(gbeanName1,
"state"));
  +        assertEquals(new Integer(State.RUNNING_INDEX), mbServer.getAttribute(gbeanName1,
"state"));
  +        Object state = mbServer.getAttribute(gbeanName2, "state");
  +        assertEquals(new Integer(State.RUNNING_INDEX), state);
           assertEquals("1234", mbServer.getAttribute(gbeanName1, "Value"));
           assertEquals("no endpoint", mbServer.invoke(gbeanName1, "checkEndpoint", null,
null));
  -        //assertEquals("endpointCheck", mbServer.invoke(gbeanName2, "checkEndpoint", null,
null));
  +        assertEquals("endpointCheck", mbServer.invoke(gbeanName2, "checkEndpoint", null,
null));
   
           mbServer.invoke(configName, "stop", null, null);
           try {
  
  
  
  1.3       +2 -1      incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java
  
  Index: MockGBean.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MockGBean.java	14 Jan 2004 20:41:56 -0000	1.2
  +++ MockGBean.java	15 Jan 2004 00:45:55 -0000	1.3
  @@ -86,6 +86,7 @@
           infoFactory.addAttribute(new GAttributeInfo("Value", true));
           infoFactory.addOperation(new GOperationInfo("checkResource", new String[]{"name"},
new String[]{"java.lang.String"}));
           infoFactory.addOperation(new GOperationInfo("checkEndpoint"));
  +        infoFactory.addOperation(new GOperationInfo("doSomething", new String[]{"name"},
new String[]{"java.lang.String"}));
           infoFactory.addEndpoint(new GEndpointInfo("MockEndpoint", MockEndpoint.class.getName()));
           infoFactory.setConstructor(new GConstructorInfo(Collections.singletonList("Name"),
Collections.singletonList(String.class)));
           GBEAN_INFO = infoFactory.getBeanInfo();
  
  
  

Mime
View raw message