In wildlfy9, how to make stateful ejb session replication with two node in standalone mode(Clustering)
Asked Answered
P

1

8

I want to do clustering with ear project. I found one solution to run standalone in clustering using standalone-ha.xml configuration. I followed below article. It's working fine. Clustering in domain mode with wildfly9 But I want to run ERP project which has ear as well as stateful ejb's. So I run clustering in standalone mode.

I have two machines ip's are different e.g.

1.10.10.10.10 node1

  1. 20.20.20.20 node2

Both machine have wildfly9 and for testing purpose I have created one sample stateful ejb project with web component.

My command to run server is:

standalone.bat -c standalone-ha.xml -b 10.10.10.10 -u 230.0.0.4 -Djboss.node.name=node1

and

./standalone.sh -c standalone-ha.xml -b 20.20.20.20 -u 230.0.0.4 -Djboss.node.name=node2

My project Test.war has stateful ejb and servlet and jsp . 1)Bank.java is stateful ejb which implements Remote and local interface

@Stateful(passivationCapable=true)
public class Bank implements BankRemote,BankLocal {   

private int amount=0;   

@Override
public boolean withdraw(int amount) {
     if(amount<=this.amount){  
            this.amount-=amount;  
            return true;  
        }else{  
            return false;  
        }  
}
@Override
public void deposit(int amount) {
    this.amount+=amount;  

}
@Override
public int getBalance() {
     return amount;  
}}

2)OpenAccount.java is servlet

@WebServlet("/OpenAccount")
public class OpenAccount extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try{  
         HttpSession bankSession = request.getSession();
         BankRemote bank = (BankRemote) bankSession.getAttribute("remote");
         if(bank == null)
            {
                System.out.println("Session is Null So initialized with new session");
                Properties p = new Properties(); 
                /*p.put("jboss.naming.client.ejb.context", true);*/
                p.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
                InitialContext context=new InitialContext();                
                BankRemote b=(BankRemote)context.lookup("java:global/Test/Bank!com.ejb.BankRemote");                  
                request.getSession().setAttribute("remote",b);  
            }
            else
            {
                System.out.println("Session is present id is :["+bankSession.getId()+"]");
            }
            request.getRequestDispatcher("/operation.jsp").forward(request, response);
}
     catch(Exception e){System.out.println(e);}  

3)index.jsp is Home page contains below single line which redirects to servlet

<a href="OpenAccount">Open Account</a> 

4)operation.jsp which forwarded from servlet is:

<body>
<form action="operationprocess.jsp">  
Enter Amount:<input type="text" name="amount"/><br>       
Choose Operation:  
Deposit<input type="radio" name="operation" value="deposit"/>  
Withdraw<input type="radio" name="operation" value="withdraw"/>  
Check balance<input type="radio" name="operation" value="checkbalance"/>  
<br>  
<input type="submit" value="submit">  
</form> 
</body>

4)operationprocess.jsp is

<body>
<%  
try
{
BankRemote remote=(BankRemote)session.getAttribute("remote");  
String operation=request.getParameter("operation");  
String amount=request.getParameter("amount");      
if(remote != null)
{if(operation!=null){  
try{       
    if(operation.equals("deposit"))
    {  
        remote.deposit(Integer.parseInt(amount));  
        out.print("Amount successfully deposited!");  
    }
    else
    {            	
   if(operation.equals("withdraw")){  
       boolean status=remote.withdraw(Integer.parseInt(amount));  
        if(status){  
        out.print("Amount successfully withdrawn!"); }
         else{  
        out.println("Enter less amount"); }  
    }else{  
       out.println("Current Amount: "+remote.getBalance());  
  	}  
	}
	}catch(NumberFormatException numex){
			out.println("Number is not valid");}
	}
}
else
{out.print("Session is null"); }
}catch(Exception ee){
	System.out.println("in jsp exception");
	ee.printStackTrace();}
%>  
<hr/>  
<jsp:include page="operation.jsp"></jsp:include>  
</body>

5)web.xml contains

<distributable/>

tags for enable clustering.

6) also class path has jboss-ejb-client.properties

remote.clusters=ejb
remote.cluster.ejb.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.cluster.ejb.connect.options.org.xnio.Options.SSL_ENABLED=false

With all these things, I deployed Test.war in both server and try to access with apache_mode_cluster i.e. 10.10.10.10/Test/. It is invoking ejb and give me output but when

1) I shutdown 10.10.10.10 server and refresh browser(Not clear browser history for maintaining session) , that time it gives me error like the distributable container does not apply to identical application.

2) 10.10.10.10 is shut down and I clear history and again access url 10.10.10.10/Test it redirect to 20.20.20.20 server i.e. node2 and run successfully. But session is not replicated.

Please help me. standalone-ha.xml -- subsystem infinispan is:

 <cache-container name="server" default-cache="default" module="org.wildfly.clustering.server" aliases="singleton cluster">
            <transport lock-timeout="60000"/>
            <replicated-cache name="default" mode="SYNC">
                <transaction mode="BATCH"/>
            </replicated-cache>
        </cache-container>
        <cache-container name="web" default-cache="dist" module="org.wildfly.clustering.web.infinispan">
            <transport lock-timeout="60000"/>
            <distributed-cache name="dist" mode="ASYNC" owners="2" l1-lifespan="0">
                <locking isolation="REPEATABLE_READ"/>
                <transaction mode="BATCH"/>
                <file-store/>
            </distributed-cache>
        </cache-container>
        <cache-container name="ejb" default-cache="dist" module="org.wildfly.clustering.ejb.infinispan" aliases="sfsb">
            <transport lock-timeout="60000"/>
            <distributed-cache name="dist" mode="ASYNC" owners="2" l1-lifespan="0">
                <locking isolation="REPEATABLE_READ"/>
                <transaction mode="BATCH"/>
                <file-store/>
            </distributed-cache>
        </cache-container>
Provision answered 8/10, 2015 at 6:49 Comment(3)
please post the contents of inifnispan subsystem <subsystem xmlns="urn:jboss:domain:infinispan:3.0"> from your standalone-ha.xml file.Thi
The tag cluster-analysis (aliased from: clustering) refers to the data mining task, not to server load-balancing or cluster-computing. Please pay more attention to choosing the appropriate tags and their description.Millburn
SCRIPTLETS ????????? o.OFlying
G
0

I had similar problem (post) and started watching your post. After a while I got what causing it.

Maybe you have similar problem. Check it out.

Gangling answered 4/11, 2015 at 10:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.