First, this post has nothing to do with remote INTERFACE vs local. It's about a local JBoss speaking to a remote JBoss (non-clustered setup).
The local JBoss has a JMX Bean that acts as a client and a stateless session bean, let's call it WorkerBean. The second JBoss also has WorkerBean deployed on it.
Code in the JMX decides if it need to use the local WorkerBean or the one deployed on the remote server. This code creates a context object with the provider url pointing either to localhost, or the remote JBoss' address.
My problem is, I always get the local WorkerBean, even if I explicitly ask for the remote one. If I undeploy WorkerBean from the local server, I get the remote one. So it's NOT a communication problem to the remote server as it works, as long as the bean is not deployed locally.
I am probably missing something fundamental regarding using JNDI to get hold of my beans. I do not think this is JBoss specific (though I haven't tested on another server), but rather me doing something wrong - probably JNDI wise.
I have set up a test project that I can provide, replicating this problem.
Code in JMX bean that creates the context and looks up the bean:
I don't currently use JBoss, but I think this might be app server specific. The host portions of JNDI names tend to vary by app server. I'm going to move this to JBoss. The moderators there can move it back to EJB if I am wrong.