openejb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r543564 - in /incubator/openejb/trunk/openejb3/server: openejb-client/src/main/java/org/apache/openejb/client/ openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/
Date Fri, 01 Jun 2007 18:15:11 GMT
Author: dblevins
Date: Fri Jun  1 11:15:10 2007
New Revision: 543564

URL: http://svn.apache.org/viewvc?view=rev&rev=543564
Log:
Replace client-side proxies with IntraVM proxies upon entry to the server-side.

Added:
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/DefaultedThreadLocal.java
    incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ServerSideResolver.java
Modified:
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBHomeProxyHandle.java
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBMetaDataImpl.java
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectProxyHandle.java
    incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java
    incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java

Added: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/DefaultedThreadLocal.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/DefaultedThreadLocal.java?view=auto&rev=543564
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/DefaultedThreadLocal.java
(added)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/DefaultedThreadLocal.java
Fri Jun  1 11:15:10 2007
@@ -0,0 +1,33 @@
+/**
+ * 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.openejb.client;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DefaultedThreadLocal<T> extends ThreadLocal<T> {
+    private final T defaultValue;
+
+    public DefaultedThreadLocal(T defaultValue) {
+        this.defaultValue = defaultValue;
+    }
+
+    public T get() {
+        T value = super.get();
+        return (value == null)? defaultValue: value;
+    }
+}

Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBHomeProxyHandle.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBHomeProxyHandle.java?view=diff&rev=543564&r1=543563&r2=543564
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBHomeProxyHandle.java
(original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBHomeProxyHandle.java
Fri Jun  1 11:15:10 2007
@@ -24,6 +24,8 @@
 
 public class EJBHomeProxyHandle implements Externalizable {
 
+    public static ThreadLocal<Resolver> resolver = new DefaultedThreadLocal<Resolver>(new
ClientSideResovler());
+
     EJBHomeHandler handler;
 
     public EJBHomeProxyHandle() {
@@ -63,15 +65,21 @@
         ejb.deploymentCode = in.readShort();
 
         server.readExternal(in);
-
         handler = EJBHomeHandler.createEJBHomeHandler(ejb, server, client);
-//        handler.primaryKey = in.readObject();
-
-        handler.ejb.ejbHomeProxy = handler.createEJBHomeProxy();
     }
 
     private Object readResolve() throws ObjectStreamException {
-        return handler.ejb.ejbHomeProxy;
+        return resolver.get().resolve(handler);
     }
 
+    public static interface Resolver {
+        Object resolve(EJBHomeHandler handler);
+    }
+
+    public static class ClientSideResovler implements Resolver {
+        public Object resolve(EJBHomeHandler handler) {
+            handler.ejb.ejbHomeProxy = handler.createEJBHomeProxy();
+            return handler.ejb.ejbHomeProxy;
+        }
+    }
 }

Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java?view=diff&rev=543564&r1=543563&r2=543564
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java
(original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java
Fri Jun  1 11:15:10 2007
@@ -77,6 +77,22 @@
         this.primaryKey = primaryKey;
     }
 
+    public EJBMetaDataImpl getEjb() {
+        return ejb;
+    }
+
+    public ServerMetaData getServer() {
+        return server;
+    }
+
+    public ClientMetaData getClient() {
+        return client;
+    }
+
+    public Object getPrimaryKey() {
+        return primaryKey;
+    }
+
     protected static Method getMethod(Class c, String method, Class... params) {
         try {
             return c.getMethod(method, params);

Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBMetaDataImpl.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBMetaDataImpl.java?view=diff&rev=543564&r1=543563&r2=543564
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBMetaDataImpl.java
(original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBMetaDataImpl.java
Fri Jun  1 11:15:10 2007
@@ -47,7 +47,7 @@
 
     protected transient Class keyClass;
 
-    protected transient EJBHomeProxy ejbHomeProxy;
+    protected transient EJBHome ejbHomeProxy;
 
     public EJBMetaDataImpl() {
 
@@ -119,6 +119,18 @@
         ejbHomeProxy = home;
     }
 
+    public String getDeploymentID() {
+        return deploymentID;
+    }
+
+    public Class getHomeClass() {
+        return homeClass;
+    }
+
+    public List<Class> getBusinessClasses() {
+        return businessClasses;
+    }
+
     public void writeExternal(ObjectOutput out) throws IOException {
         out.writeObject(homeClass);
         out.writeObject(remoteClass);
@@ -137,7 +149,7 @@
         homeClass = (Class) in.readObject();
         remoteClass = (Class) in.readObject();
         keyClass = (Class) in.readObject();
-        ejbHomeProxy = (EJBHomeProxy) in.readObject();
+        ejbHomeProxy = (EJBHome) in.readObject();
         type = in.readByte();
         deploymentID = in.readUTF();
         deploymentCode = in.readShort();

Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectProxyHandle.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectProxyHandle.java?view=diff&rev=543564&r1=543563&r2=543564
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectProxyHandle.java
(original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectProxyHandle.java
Fri Jun  1 11:15:10 2007
@@ -24,6 +24,8 @@
 
 public class EJBObjectProxyHandle implements Externalizable {
 
+    public static ThreadLocal<Resolver> resolver = new DefaultedThreadLocal<Resolver>(new
ClientSideResovler());
+
     EJBObjectHandler handler;
 
     public EJBObjectProxyHandle() {
@@ -61,7 +63,16 @@
     }
 
     private Object readResolve() throws ObjectStreamException {
-        return handler.createEJBObjectProxy();
+        return resolver.get().resolve(handler);
+    }
+
+    public static interface Resolver {
+        Object resolve(EJBObjectHandler handler);
     }
 
+    public static class ClientSideResovler implements Resolver {
+        public Object resolve(EJBObjectHandler handler) {
+            return handler.createEJBObjectProxy();
+        }
+    }
 }

Modified: incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java?view=diff&rev=543564&r1=543563&r2=543564
==============================================================================
    (empty)

Modified: incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java?view=diff&rev=543564&r1=543563&r2=543564
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java
(original)
+++ incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java
Fri Jun  1 11:15:10 2007
@@ -30,10 +30,14 @@
 import org.apache.openejb.client.RequestMethodConstants;
 import org.apache.openejb.client.ResponseCodes;
 import org.apache.openejb.client.ThrowableArtifact;
+import org.apache.openejb.client.EJBHomeProxyHandle;
+import org.apache.openejb.client.EJBObjectProxyHandle;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.spi.SecurityService;
 
 class EjbRequestHandler {
+    public static final ServerSideResolver SERVER_SIDE_RESOLVER = new ServerSideResolver();
+
     private final EjbDaemon daemon;
 
     EjbRequestHandler(EjbDaemon daemon) {
@@ -42,6 +46,11 @@
     }
 
     public void processRequest(ObjectInputStream in, ObjectOutputStream out) {
+        // Setup the client proxy replacement to replace
+        // the proxies with the IntraVM proxy implementations
+        EJBHomeProxyHandle.resolver.set(SERVER_SIDE_RESOLVER);
+        EJBObjectProxyHandle.resolver.set(SERVER_SIDE_RESOLVER);
+
         EJBRequest req = new EJBRequest();
         EJBResponse res = new EJBResponse();
 
@@ -183,6 +192,9 @@
                 this.daemon.logger.fatal("Couldn't write EjbResponse to output stream", ie);
             }
             call.reset();
+            EJBHomeProxyHandle.resolver.set(null);
+            EJBObjectProxyHandle.resolver.set(null);
+
         }
     }
 

Added: incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ServerSideResolver.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ServerSideResolver.java?view=auto&rev=543564
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ServerSideResolver.java
(added)
+++ incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ServerSideResolver.java
Fri Jun  1 11:15:10 2007
@@ -0,0 +1,86 @@
+/**
+ * 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.openejb.server.ejbd;
+
+import org.apache.openejb.client.EJBHomeProxyHandle;
+import org.apache.openejb.client.EJBHomeHandler;
+import org.apache.openejb.client.EJBMetaDataImpl;
+import org.apache.openejb.client.EJBObjectProxyHandle;
+import org.apache.openejb.client.EJBObjectHandler;
+import org.apache.openejb.InterfaceType;
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.util.Logger;
+import org.apache.openejb.core.ivm.EjbHomeProxyHandler;
+import org.apache.openejb.core.ivm.EjbObjectProxyHandler;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+
+import java.util.ArrayList;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServerSideResolver implements EJBHomeProxyHandle.Resolver, EJBObjectProxyHandle.Resolver
{
+
+    private static Logger logger = Logger.getInstance("OpenEJB.server.remote", "org.apache.openejb.server.util.resources");
+
+    public Object resolve(EJBHomeHandler handler) {
+        try {
+            EJBMetaDataImpl ejb = handler.getEjb();
+
+            InterfaceType interfaceType = (ejb.getRemoteInterfaceClass() == null)? InterfaceType.BUSINESS_REMOTE_HOME
: InterfaceType.EJB_HOME;
+
+            ArrayList<Class> interfaces = new ArrayList<Class>();
+            if (interfaceType.isBusiness()){
+                interfaces.addAll(ejb.getBusinessClasses());
+            } else {
+                interfaces.add(ejb.getRemoteInterfaceClass());
+            }
+
+            ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
+            DeploymentInfo deploymentInfo = containerSystem.getDeploymentInfo(ejb.getDeploymentID());
+
+            return EjbHomeProxyHandler.createHomeProxy(deploymentInfo, interfaceType, interfaces);
+        } catch (Exception e) {
+            logger.error("ServerSideResolver.resolve() failed, falling back to ClientSideResolver:
"+e.getClass().getName()+": "+e.getMessage(), e );
+            return new EJBHomeProxyHandle.ClientSideResovler().resolve(handler);
+        }
+    }
+
+    public Object resolve(EJBObjectHandler handler) {
+        try {
+            EJBMetaDataImpl ejb = handler.getEjb();
+
+            InterfaceType interfaceType = (ejb.getRemoteInterfaceClass() == null)? InterfaceType.BUSINESS_REMOTE_HOME
: InterfaceType.EJB_HOME;
+
+            ArrayList<Class> interfaces = new ArrayList<Class>();
+            if (interfaceType.isBusiness()){
+                interfaces.addAll(ejb.getBusinessClasses());
+            } else {
+                interfaces.add(ejb.getRemoteInterfaceClass());
+            }
+
+            ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
+            DeploymentInfo deploymentInfo = containerSystem.getDeploymentInfo(ejb.getDeploymentID());
+
+            return EjbObjectProxyHandler.createProxy(deploymentInfo, handler.getPrimaryKey(),
interfaceType, interfaces);
+        } catch (Exception e) {
+            logger.error("ServerSideResolver.resolve() failed, falling back to ClientSideResolver:
"+e.getClass().getName()+": "+e.getMessage(), e );
+            return new EJBObjectProxyHandle.ClientSideResovler().resolve(handler);
+        }
+    }
+}



Mime
View raw message