geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r941340 - in /geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel: basic/BasicProxyManager.java classloader/DelegatingClassLoader.java
Date Wed, 05 May 2010 15:19:45 GMT
Author: gawor
Date: Wed May  5 15:19:44 2010
New Revision: 941340

URL: http://svn.apache.org/viewvc?rev=941340&view=rev
Log:
GERONIMO-5279: An attempt at making gbean proxies work. The remote operations like install-library
seems to be working now

Added:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/DelegatingClassLoader.java
  (with props)
Modified:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java?rev=941340&r1=941339&r2=941340&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java
Wed May  5 15:19:44 2010
@@ -27,6 +27,7 @@ import net.sf.cglib.proxy.Callback;
 import net.sf.cglib.proxy.Enhancer;
 import net.sf.cglib.proxy.MethodInterceptor;
 import net.sf.cglib.reflect.FastClass;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.geronimo.gbean.AbstractName;
@@ -34,6 +35,7 @@ import org.apache.geronimo.gbean.GBeanIn
 import org.apache.geronimo.kernel.ClassLoading;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.classloader.DelegatingClassLoader;
 import org.apache.geronimo.kernel.proxy.ProxyCreationException;
 import org.apache.geronimo.kernel.proxy.ProxyFactory;
 import org.apache.geronimo.kernel.proxy.ProxyManager;
@@ -85,44 +87,48 @@ public class BasicProxyManager implement
         try {
             // if the type is visible from the target's classloader use it
             // otherwise use the type's classloader
-            //TODO OSGI BUSTED
-            ClassLoader classLoader = null;
-            try {
-//                classLoader = kernel.getBundlerFor(target);
-                if (!type.equals(ClassLoading.loadClass(type.getName(), classLoader))) {
-                    classLoader = type.getClassLoader();
-                }
-            } catch (Exception ignored) {
-                classLoader = type.getClassLoader();
-            }
-
+            ClassLoader classLoader = type.getClassLoader();
+            
             // add any interface exposed by the gbean that is visible from the selected class
loader
-            List types = getVisibleInterfaces(target, classLoader, true);
-            if (types == null) types = new ArrayList();
+            List<Class> types = getVisibleInterfaces(target, classLoader, true);
+            if (types == null) {
+                types = new ArrayList<Class>();
+            }
             types.add(type);
 
-            return (T) createProxyFactory((Class[]) types.toArray(new Class[types.size()]),
classLoader).createProxy(target);
+            DelegatingClassLoader proxyClassLoader = new DelegatingClassLoader();
+            proxyClassLoader.addLoader(classLoader);
+            proxyClassLoader.addLoader(getClass()); // to be able to load GeronimoManagedBean
+            
+            return (T) createProxyFactory((Class[]) types.toArray(new Class[types.size()]),
proxyClassLoader).createProxy(target);
         } catch (GBeanNotFoundException e) {
             throw new IllegalArgumentException("Could not get GBeanInfo for target object:
" + target, e);
         }
     }
-
+    
     public Object createProxy(AbstractName target, ClassLoader classLoader) {
         if (target == null) throw new NullPointerException("target is null");
         if (classLoader == null) throw new NullPointerException("classLoader is null");
 
         try {
-            List types = getVisibleInterfaces(target, classLoader, true);
-            if (types == null) return null;
-            return createProxyFactory((Class[]) types.toArray(new Class[types.size()]), classLoader).createProxy(target);
+            List<Class> types = getVisibleInterfaces(target, classLoader, true);
+            if (types == null) {
+                return null;
+            }
+            
+            DelegatingClassLoader proxyClassLoader = new DelegatingClassLoader();
+            proxyClassLoader.addLoader(classLoader);
+            proxyClassLoader.addLoader(getClass()); // to be able to load GeronimoManagedBean
+            
+            return createProxyFactory((Class[]) types.toArray(new Class[types.size()]), proxyClassLoader).createProxy(target);
         } catch (GBeanNotFoundException e) {
             throw new IllegalArgumentException("Could not get GBeanInfo for target object:
" + target, e);
         }
     }
 
-    private List getVisibleInterfaces(AbstractName target, ClassLoader classLoader, boolean
shouldLog) throws GBeanNotFoundException {
+    private List<Class> getVisibleInterfaces(AbstractName target, ClassLoader classLoader,
boolean shouldLog) throws GBeanNotFoundException {
         GBeanInfo info = kernel.getGBeanInfo(target);
-        Set interfaces = info.getInterfaces();
+        Set<String> interfaces = info.getInterfaces();
         if(interfaces.size() == 0) {
             if (shouldLog) {
                 log.warn("No interfaces found for " + target + " ("+target+")");
@@ -130,10 +136,10 @@ public class BasicProxyManager implement
             return null;
         }
         String[] names = (String[]) interfaces.toArray(new String[0]);
-        List types = new ArrayList();
+        List<Class> types = new ArrayList<Class>();
         for (int i = 0; i < names.length; i++) {
             try {
-                Class type = classLoader.loadClass(names[i]);
+                Class<?> type = classLoader.loadClass(names[i]);
                 if (type.isInterface()) {
                     types.add(type);
                 }

Added: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/DelegatingClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/DelegatingClassLoader.java?rev=941340&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/DelegatingClassLoader.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/DelegatingClassLoader.java
Wed May  5 15:19:44 2010
@@ -0,0 +1,77 @@
+/**
+* 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.geronimo.kernel.classloader;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * ClassLoader implementation that delegates calls to multiple classloaders.
+ */
+public class DelegatingClassLoader extends ClassLoader {
+    
+    private Set<ClassLoader> loaders = new LinkedHashSet<ClassLoader>();
+
+    public void addLoader(ClassLoader loader) {
+        loaders.add(loader);
+    }
+
+    public void addLoader(Class<?> clazz) {
+        loaders.add(clazz.getClassLoader());
+    }
+
+    @Override
+    public Class<?> findClass(String name) throws ClassNotFoundException {
+        for (ClassLoader loader : loaders) {
+            try {
+                return loader.loadClass(name);
+            } catch (ClassNotFoundException cnfe) {
+                // Try next
+            }
+        }
+        throw new ClassNotFoundException(name);
+    }
+
+    @Override
+    public URL getResource(String name) {
+        for (ClassLoader loader : loaders) {
+            URL url = loader.getResource(name);
+            if (url != null) {
+                return url;
+            }
+        }
+        return null;
+    }
+    
+    @Override
+    public Enumeration<URL> getResources(String name) throws IOException {
+        List<URL> resources = new ArrayList<URL>();
+        for (ClassLoader loader : loaders) {
+            Enumeration<URL> e = loader.getResources(name);
+            while (e.hasMoreElements()) {
+                resources.add(e.nextElement());
+            }
+        }
+        return Collections.enumeration(resources);
+    }
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/DelegatingClassLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/DelegatingClassLoader.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/DelegatingClassLoader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message