incubator-yoko-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r495536 - in /incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl: PortableRemoteObjectImpl.java RMIStubHandler.java RMIStubInitializer.java StubHandler.java
Date Fri, 12 Jan 2007 10:25:00 GMT
Author: rickmcguire
Date: Fri Jan 12 02:25:00 2007
New Revision: 495536

URL: http://svn.apache.org/viewvc?view=rev&rev=495536
Log:
YOKO-272 Implement a hook to allow openejb to intercept stub method calls.


Added:
    incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/StubHandler.java
  (with props)
Modified:
    incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/PortableRemoteObjectImpl.java
    incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/RMIStubHandler.java
    incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/RMIStubInitializer.java

Modified: incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/PortableRemoteObjectImpl.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/PortableRemoteObjectImpl.java?view=diff&rev=495536&r1=495535&r2=495536
==============================================================================
--- incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/PortableRemoteObjectImpl.java
(original)
+++ incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/PortableRemoteObjectImpl.java
Fri Jan 12 02:25:00 2007
@@ -23,14 +23,18 @@
 import java.lang.reflect.Method;
 import java.rmi.Remote;
 import java.rmi.RemoteException;
+import java.security.AccessController;
 import java.util.logging.Logger;
 
 import javax.rmi.CORBA.PortableRemoteObjectDelegate;
 import javax.rmi.CORBA.Tie;
+import javax.rmi.CORBA.Util;
 
 import org.apache.yoko.rmi.util.ClientUtil;
+import org.apache.yoko.rmi.util.GetSystemPropertyAction;
 import org.apache.yoko.rmi.util.stub.MethodRef;
 import org.apache.yoko.rmi.util.stub.StubClass;
+import org.apache.yoko.rmi.util.stub.StubInitializer;
 import org.omg.CORBA.BAD_INV_ORDER;
 import org.omg.CORBA.portable.ObjectImpl;
 
@@ -39,6 +43,12 @@
     static final Logger logger = Logger
             .getLogger(PortableRemoteObjectImpl.class.getName());
 
+    static {
+        // Initialize the stub handler factory when first loaded to ensure we have 
+        // class loading visibility to the factory. 
+        getRMIStubInitializer(); 
+    }
+
     private static TypeRepository getTypeRepository() {
         return RMIState.current().getTypeRepository();
     }
@@ -353,7 +363,7 @@
             getPackageName(type),
 
             /* provider of handlers */
-            RMIStubInitializer.instance);
+            getRMIStubInitializer());
         } catch (java.lang.NoClassDefFoundError ex) {
             /* Construct class! */
             clazz = StubClass.make(/* the class loader to use */
@@ -381,7 +391,7 @@
             getPackageName(type),
 
             /* provider of handlers */
-            RMIStubInitializer.instance);
+            getRMIStubInitializer());
 
         }
 
@@ -414,12 +424,13 @@
 
             // NYI: PrivilegedAction
             try {
-                poa_stub_invoke_method = (RMIStubHandler.class)
+                // get the interface method used to invoke the stub handler
+                poa_stub_invoke_method = (StubHandler.class)
                         .getDeclaredMethod("invoke", new Class[] {
                                 RMIStub.class, MethodDescriptor.class,
                                 Object[].class });
             } catch (NoSuchMethodException ex) {
-                throw new Error("cannot find method");
+                throw new Error("cannot find RMI Stub handler invoke method");
             }
 
         }
@@ -427,6 +438,7 @@
         return poa_stub_invoke_method;
 
     }
+    
 
     /*
      * private ClassLoader last_loader = null; private Class last_remote_type =
@@ -530,5 +542,27 @@
             throws java.rmi.NoSuchObjectException {
         javax.rmi.CORBA.Util.unexportObject(obj);
     }
-
+    
+    // the factory object used for creating stub initializers
+    static private StubInitializer initializer = null;
+    // the default stub handler, which is ours without overrides. 
+    private static final String defaultInitializer = "org.apache.yoko.rmi.impl.RMIStubInitializer";

+    
+    /**
+     * Get the RMI stub handler initializer to use for RMI invocation 
+     * stubs.  The Class in question must implement the StubInitializer method. 
+     * 
+     * @return The class used to create StubHandler instances. 
+     */
+    private static StubInitializer getRMIStubInitializer() {
+        if (initializer == null) {
+            String factory = (String)AccessController.doPrivileged(new GetSystemPropertyAction("org.apache.yoko.rmi.RMIStubInitializerClass",
defaultInitializer));
+            try {
+                initializer  = (StubInitializer)(Util.loadClass(factory, null, null).newInstance());
+            } catch (Exception e) {
+                throw new org.omg.CORBA.INITIALIZE("Can not create RMIStubInitializer: "
+ factory);
+            }
+        }
+        return initializer; 
+    }
 }

Modified: incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/RMIStubHandler.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/RMIStubHandler.java?view=diff&rev=495536&r1=495535&r2=495536
==============================================================================
--- incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/RMIStubHandler.java
(original)
+++ incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/RMIStubHandler.java
Fri Jan 12 02:25:00 2007
@@ -30,11 +30,11 @@
  * calls a remote method, this is translated to a call to the invoke() method in
  * this class.
  */
-public final class RMIStubHandler implements java.io.Serializable {
+public class RMIStubHandler implements StubHandler, java.io.Serializable {
     static final Logger logger = Logger.getLogger(RMIStubHandler.class
 	    .getName());
 
-    private RMIStubHandler() {
+    protected RMIStubHandler() {
 
     }
 
@@ -44,7 +44,7 @@
 	Class type = stub._descriptor.getJavaClass();
 	return new org.apache.yoko.rmi.impl.RMIPersistentStub(stub, type);
     }
-
+    
     public Object invoke(RMIStub stub, MethodDescriptor method, Object[] args)
 	    throws Throwable {
 

Modified: incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/RMIStubInitializer.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/RMIStubInitializer.java?view=diff&rev=495536&r1=495535&r2=495536
==============================================================================
--- incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/RMIStubInitializer.java
(original)
+++ incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/RMIStubInitializer.java
Fri Jan 12 02:25:00 2007
@@ -19,13 +19,11 @@
 package org.apache.yoko.rmi.impl;
 
 class RMIStubInitializer implements org.apache.yoko.rmi.util.stub.StubInitializer {
-    private RMIStubInitializer() {
+    public RMIStubInitializer() {
 
     }
-
-    static RMIStubInitializer instance = new RMIStubInitializer();
-
+    
     public Object getStubHandler() {
-        return RMIStubHandler.instance;
+        return RMIStubHandler.instance; 
     }
 }

Added: incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/StubHandler.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/StubHandler.java?view=auto&rev=495536
==============================================================================
--- incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/StubHandler.java
(added)
+++ incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/StubHandler.java
Fri Jan 12 02:25:00 2007
@@ -0,0 +1,58 @@
+/**
+*
+* 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.yoko.rmi.impl;
+
+import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.logging.Logger;
+
+import org.omg.CORBA.ORB;
+
+/**
+ * This class is the interface for instances of POAStub. When a client
+ * calls a remote method, this is translated to a call to the invoke() method in
+ * this class.
+ */
+public interface StubHandler {
+    /**
+     * Invocation method for an method call.  This 
+     * method catches the calls from the generated 
+     * stub method and handles the appropriate 
+     * argument and return value marshalling.
+     * 
+     * @param stub   The stub object used to catch the call.
+     * @param method The descriptor for the method being invoked.
+     * @param args   The arguments passed to the method.
+     * 
+     * @return The method return value (if any).
+     * @exception Throwable
+     */
+    public Object invoke(RMIStub stub, MethodDescriptor method, Object[] args) throws Throwable;
+    
+    /**
+     * Handle a writeReplace operation on a Stub. 
+     * 
+     * @param stub   The source RMIStub.
+     * 
+     * @return The replacement object for serialization.
+     */
+    public Object stubWriteReplace(RMIStub stub);
+}
+

Propchange: incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/StubHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/StubHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/StubHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message