An interesting question:
"…I can use a local interface to access EJB locally (from another EJB for example) and remote interface to access it remotely (using standalone client, appclient client). I have a question about those in a cluster. I'm using Glassfish 3.1.1. Let's say I have a application with two EJB's (EJB_A and EJB_B) and an appclient. I can use remote interface in my appclient to access EJB_A. Right? From EJB_A I use local interface to access EJB_B, right? What If I run the same application in a cluster? Will EJB_A and EJB_B will always be accessible locally? Can it happen that EJB_A and EJB_B will be on different machines?…"And the answers:
- Only remote EJBs are clusterable. The proxy (synthetic implementation of bean's remote interface) cares about clustering. It is often called: "smart stub".
- It is a good idea to expose a single, coarse grained remote interface (e.g. ServiceFacade), and perform everything else locally behind this boundary (e.g. take a look on x-ray). Behind a boundary every call should be performed locally. One of my most important "patterns" is: "Don't Distribute!"
- @Local EJB interfaces have "call by reference" semantics. There are no smart-stubs or any clustering functionality between local calls. It would break the semantics...
Online workshop: Java EE 7 Bootstrap