What kind of application WAR or EJB?
My application is EJB 3.
To give some more clarifications, I implemented the LoadBalancePolicy, and I have done the setup to use him in cluster-service.xml jboss, as follows:
In the ejb3-interceptors-aop.xml, I set the fallow rule:
<domain name="Stateless Bean">
@org.jboss.annotation.ejb.Clustered (loadBalancePolicy=my.package.loadbalance.SiopLoadBalancePolicy.class, partition="DefaultPartition")
I add theanotation @Clustered in EJB would like it to be "clustered".
@Stateless(mappedName = "RelatorioServico")
When I start the JBoss server, I notice that my class LoadBalance is being initiated, but it is just in no time the application "enters" the methods chooseTarget.
First of all, if you use stateless session beans, it makes no sense to be sticky to one server because after the method call of SLSB all states are lost (e.g. entities or resources).
If you try to calculate with a second SLSB call all must be recalculated.
Hum... I got it.
So, first should I change bean to Stateful?
It depends to what you want ;-)
ok, better as example:
If you call more than one methods against one SessionBean, prepare something and then calculate according to what you have prepared.
It will be an idea to implement this as a stateful session bean, other is to transport the result to client and back or persist it in DB (or other).
For SFSB you need to know that it is not fail save in case of the note will crash. But I think it is not necessary in your case to replicate the session state, you can live with the failure in case of exact this node crash during the processing.
Also you do not need to implement your own load balancing, each call to the SFSB will reach the same server.
Could make the redirection of URL's, but I use the mod_jk in Apache, to do load balancing among JBoss.
The configuration I did was to file worker.properties, and there arose a new problem: "the user's session is lost."
# Define list of workers that will be used for mapping requests worker.list=status,relatorio,sistema # TEMPLATE worker.template.port=8009 worker.template.type=ajp13 worker.template.socket_timeout=0 # Define Node1 worker.nodeSis.reference=worker.template worker.nodeSis.host=x.x.x.10 # Define Node2 worker.nodeRel.reference=worker.template worker.nodeRel.host=x.x.x.20 # Load-balancing behaviour worker.sistema.type=lb worker.sistema.balance_workers=nodeSis worker.sistema.sticky_session=1 # Status worker for managing load balancer worker.status.type=status # Relatorio behaviour worker.relatorio.type=lb worker.relatorio.balance_workers=nodeRel worker.relatorio.sticky_session=1
Just completing, redirection settings are on file mod_jk.conf.
Excerpt follows below:
(...) # Mount your applications JkMount /sistema sistema JkMount /sistema/* sistema JkMount /sistema/GeraRelatorio relatorio (...)