3


I want to have a bean Foo in host A which is injected, by the @EJB annotation to a bean Bar in host B.
Both these hosts are separate stand-alone instances of Glassfish-v3.
When reading the Glassfish docs I found a lot of info, some of it sounded a bit contradicting.
I understood that every bean has a global jndi named assigned to it and understood how it is constructed, What is the syntax for portable global JNDI names?. I also understood that the the declaration of Foo in Bar should be something of this sort (assuming FooRemote is the remote business interface of Foo and fooejb is the its module): @EJB(lookup=java:global/fooejb/FooRemote) FooRemote foo, this is based on this.
What I can't understand is where I tell host A and host B to get to know each other.
I saw a lot of examples for application clients and application servers but I wasn't able to find an example for such a scenario.
In this question a sun-web.xml and Global-JNDI is mentioned but I think that it's not EJB3.1 (since it's not Portable JNDI) and I don't understand where this sun-web.xml should reside (I'd like to avoid it if I can).
It is mainly different in two ways:

  1. There is no -Dorg.omg.CORBA.ORBInitialHost= param option (as far as I can see)
  2. Any solution should of course allow the inclusion of a third host C which both A and B communicate with for different purposes.

I have a strong feeling I'm missing something basic here and I'd really appreciate pointers to what I'm missing.
BTW, I'd like to avoid as much as possible from descriptor files and such and leave most info on annotations and only the host ip's to config in the server.

Edit:
I think another interesting aspect of this question is how load-balancing is used in this aspect, i.e. let's say I have A1 and A2 servers which are the same, how will load-balancing occur with respect to routing the request from B to either A1 or A2

Edit2:
I think this might be unrelated to ejb 3.1 but related to the basis on how to enable two application servers to see each other's jndi registry. I think this is unrelated to ejb 3.1 as it seems a similar problem exists in the 3.0 with the Global not portable jndi.
I would imagine some configuration in each app server would allow me to configure which other "neighbours" it should query for jndi remote beans.
Hope that gives a clue to someone out there.

Thanks,
Ittai

Ittai
  • 5,625
  • 14
  • 60
  • 97

3 Answers3

3

With regards to EJB Load balancing you might like to take a look at this blog:

http://www.techpost.info/2010/12/ejb-load-balancer_7304.html

JSS
  • 2,061
  • 1
  • 20
  • 26
2
AmanicA
  • 4,659
  • 1
  • 34
  • 49
  • Thanks for your answer. I'm not using a cluster; I have two hosts which are not homogenous (and as such are not a cluster). You can think of my question as how to connect between two clusters. The cross-app is something I've linked to but it refers to global (not portable) jndi and is using descriptors. In short, I don't see any new info here :( – Ittai Mar 24 '11 at 07:50
  • Vetle Roeim said the following on users@glassfish.java.net: "Take a look at the test case attached to this issue: http://java.net/jira/browse/GLASSFISH-15523 This example uses both lookup and injection, but hopefully you should be able to make sense of it." (I have not looked at it yet) – AmanicA Mar 24 '11 at 10:05
  • AmanicA, first of all thank you! I awarded you the bounty since between the time I posted the question and the time you posted the comment I've reached rock bottom with my attempts and your comment gave me an important lead (I downloaded the test case of that issue and as working with regards to it to understand my issue). Since it didn't really answer my question, and for the sake of others seeking the answer I will post my solution in a few days. BTW, I also upvoted you since you did help me :) Hope that's enough – Ittai Mar 29 '11 at 07:21
0

We are using remote EJBs and it works fine.

First you'll need the EJB on "Host A" wich implements an interface whose class is present on both hosts.

//For host A + B
public interface FooClass {
    public void theMethod();
}

//Only for host A
@Stateless
public class FooClassImpl implements FooClass {
    public void theMethod(){//Code goes here}
}

Then you'll need to create (on Host B) a glassfish-web.xml in your WEB-INF directory, where you specify where a remote EJB is located:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
  <ejb-ref>
    <ejb-ref-name>RemoteEJBName</ejb-ref-name>
    <jndi-name>corbaname:iiop:<servername or IP>:3700#java:global/<projectname>/FooClassImpl!com.test.foo.FooClass</jndi-name>
  </ejb-ref>
</glassfish-web-app>

At the injection point on Host B you'll need to inject the EJB like this:

@EJB(name = "RemoteEJBName")
private FooClass theFooClassInstance;

I hope this will do the trick.

McIntosh
  • 2,051
  • 1
  • 22
  • 34