8

Desidero eseguire il clustering con il progetto ear. Ho trovato una soluzione per eseguire autonomamente il clustering usando la configurazione standalone-ha.xml. Ho seguito l'articolo qui sotto. Funziona bene. Clustering in domain mode with wildfly9 Ma io voglio eseguire il progetto ERP che ha anche ejb di ear e stateful. Così eseguo il clustering in modalità standalone.In wildlfy9, come eseguire la replica della sessione ejb stateful con due nodi in modalità standalone (Clustering)

Ho due macchine che gli IP sono diversi ad es.

1.10.10.10.10 nodo1

  1. 20.20.20.20 node2

Sia macchina ho wildfly9 e a scopo di test ho creato un progetto di esempio stateful EJB con componente web.

mio comando per eseguire server è:

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

e

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

Il mio progetto ha Test.war stateful servlet e EJB e JSP. 1) Bank.java è ejb stateful che implementa remoto e locale interfaccia

@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 è 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 è iniziale pagina contiene sotto singola linea che reindirizza per servlet

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

4) operation.jsp che inoltrata dal servlet è:

<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 è

<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 
 
    {    \t 
 
    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()); 
 
    \t } 
 
\t } 
 
\t }catch(NumberFormatException numex){ 
 
\t \t \t out.println("Number is not valid");} 
 
\t } 
 
} 
 
else 
 
{out.print("Session is null"); } 
 
}catch(Exception ee){ 
 
\t System.out.println("in jsp exception"); 
 
\t ee.printStackTrace();} 
 
%> 
 
<hr/> 
 
<jsp:include page="operation.jsp"></jsp:include> 
 
</body>

5) web.xml contiene

<distributable/> 

tag per abilitare il clustering.

6) anche percorso classe ha 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 

Con tutte queste cose, ho schierato Test.war sia del server per l'accesso con apache_mode_cluster cioè 10.10.10.10/Test/ . Invoca ejb e mi dà l'output ma quando

1) Arresto il server 10.10.10.10 e aggiorna il browser (non cancella la cronologia del browser per il mantenimento della sessione), quella volta mi dà un errore come il contenitore distribuibile non si applica a identici applicazione.

2) 10.10.10.10 viene chiuso e si cancella la cronologia e di nuovo si accede all'URL 10.10.10.10/Test reindirizza al server 20.20.20.20, cioè al nodo2 ed eseguito correttamente. Ma la sessione non viene replicata.

Per favore aiutatemi. standalone-ha.xml - sottosistema infinispan è:

<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> 
+1

per favore pubblica il contenuto del sottosistema inifnispan '' dal tuo file 'standalone-ha.xml'. – Shiva

+1

Il tag [tag: cluster analysis] (aliasing da: clustering) fa riferimento all'attività di data mining, non al server [tag: load-balancing] o [tag: cluster-computing]. Si prega di prestare maggiore attenzione alla scelta dei tag appropriati e della loro descrizione. –

+1

SCRIPTLETS ????????? ò.ò –

risposta

0

Ho avuto problemi simili (post) e iniziato a guardare il tuo post. Dopo un po 'ho capito cosa lo causa.

Forse avete problemi simili. Controlla.