views:

242

answers:

1

Assume a single application server instance that has two EARs deployed. The first EAR invokes EJBs from the second EAR using remote EJB interfaces.

It is rumored that even if the invokation is implemented using remote interfaces, the application server knows that everything is within the same JVM and internally uses the remote interface with local interface mechanics, namely it does not call methods through RMI, does not open any sockets, and does not serialize/deserialize objects.

Is this true? If anybody has feedback on the behaviour of Weblogic 10.3.2 and OC4j 10.1.3 regarding this issue, it would be much appreciated.

+1  A: 

No, it is not true. If the ORB implements local object optimization (sometimes "collocated objects"), then it will not open any sockets, but it will perform serialization/deserialization, which is typically faster than marshalling. The extra object copies are made to avoid violating the programming model.

Generated stubs enable this optimization. Here is an example interface:

public interface a extends Remote {
  public ArrayList test(ArrayList in1, ArrayList in2) throws RemoteException;
}

Here is the result of rmic -iiop -keep a:

public ArrayList test(ArrayList arg0, ArrayList arg1) throws java.rmi.RemoteException {
    if (!Util.isLocal(this)) {
        /* ... trim remote code ... */
    } else {
        ServantObject so = _servant_preinvoke("test",a.class);
        if (so == null) {
            return test(arg0, arg1);
        }
        try {
            Object[] copies = Util.copyObjects(new Object[]{arg0,arg1},_orb());
            ArrayList arg0Copy = (ArrayList) copies[0];
            ArrayList arg1Copy = (ArrayList) copies[1];
            ArrayList result = ((a)so.servant).test(arg0Copy, arg1Copy);
            return (ArrayList)Util.copyObject(result,_orb());
        } catch (Throwable ex) {
            Throwable exCopy = (Throwable)Util.copyObject(ex,_orb());
            throw Util.wrapException(exCopy);
        } finally {
            _servant_postinvoke(so);
        }
    }
}

When a stub is connected to a local object, it calls ObjectImpl._servant_preinvoke to locate a servant (an EJB wrapper in your case) within the same JVM. Then, it makes a copy of the input arguments (simulating marshalling), calls the method, and makes a copy of the result object (again simulating marshalling).

I am not a WebLogic expert. That said, this document implies that WebLogic performs the collocated object optimization:

http://download.oracle.com/docs/cd/E13222_01/wls/docs61/cluster/object.html#1007328

bkail