1 Reply Latest reply: Nov 25, 2011 12:23 PM by André Simões RSS

EJB3 Injection

André Simões Newbie

Hi.

 

Imagine the following scenario:

 

One JBoss cluster with web apps

Other JBoss cluster with Ejb, jms, etc..

The clusters are isolated by a DMZ.

 

From the web app cluster, I need to inject some EJB's from the other cluster.

The only way (that I realize) to do it is with some code like this:

 

static public TestFacade assfac(){

    if( Facade._assfac ==null ) {
        
        try {
            Context ctx = new InitialContext(getProperties());
            Facade._assfac =  (TestFacade) ctx.lookup("TestFacade/remote");
        } catch (Exception e) {
            Facade._assfac = null;
            log.error(e.getMessage());
        }        
    }        
    return Facade._assfac;
}    

//pass cluster urls for injection
//Ex: facadeurls="192.168.0.1,192.168.0.2"
private static Properties getProperties() {
    String facadeurls = System.getProperty("FacadeUrls", ""); 
    Properties p = System.getProperties();

    if (facadeurls.length()> 1)    {//Got property on path
        p.put(Context.PROVIDER_URL, facadeurls);    
    }
    
    return p;
}

 

This approach works, but do not work well!

 

1º It tends to always inject from the first ip found on properties.

 

2º If jboss node from first ip is offline, it injects from the next ip, but if jboss fails after injection, we have to inject again or we receive a connection refused.

 

There are some way to have some kind of load balancing/failure detection on ejb injection?

 

Do someone sugests another way to solve this problem?

 

Thanks.

  • 1. Re: EJB3 Injection
    André Simões Newbie

    As usual, no reply...

     

    In this case the solution seems to be quite easy.

     

    For the ones that some day will gonna be stuck on something like this, just annotate your beans implementation with the annotation @Clustered

     

    This will garantee that a external client accessing to a remote interface of a bean, in a cluster, with got load balancing and failure detection.

     

    In other words, if your client has a url connection for 192.168.0.1 and ip nodes are 192.168.0.1, 192.168.0.2. Even if node 192.168.0.1 shutdown, the client do not even notice!!!

     

     

    I do not know if this is the best implementation, but no one talks about this...