Clustering j boss7

21
Clustering JBoss AS 7 Página 1 de 2 En este artículo vamos a mostrar cómo configurar en pocas palabras JBoss AS 7 para clustsering. A continuación, vamos a desplegar una muestra de aplicaciones Java EE 6 en la parte superior de la misma. Usuarios de JBoss anteriores utilizados para iniciar una configuración de servidor en clúster alimentando el c-all los parámetros a la shell de arranque del servidor de aplicaciones. El AS 7 es muy diferente de otras versiones del servidor, ya que no contiene varios directorios de configuración del servidor (todo, por defecto, minimal ..). Es sólo contiene un conjunto de archivos de configuración de cada uno incluyendo un conjunto diferente de módulos de servidor. La función de archivo de configuración de cluster son standalone- ha.xml y standalone-full-ha.xml (este último incluido el apoyo Corba). Así que vamos a empezar una configuración de clúster de demostración compuesto por dos nodos en la misma máquina. Así descomprimir dos como 7 Distribución en el camino de su elección, por ejemplo: C: \ jboss-as-7.1.1.Final.NodoA C: \ jboss-as-7.1.1.Final.NodoB Para iniciar los nodos del clúster que debe proporcionar un nombre de nodo único y, ya está ejecutando varios servidores en la misma máquina especificar un port offset modo que usted no tiene conflictos de puertos entre los servidores de puerto. Así que vamos a poner en marcha NodoA con: standalone -c standalone-ha.xml -Djboss.node.name=nodoA y el nodo B con: standalone -c standalone-ha.xml -Djboss.socket.binding.port-offset=100 -Djboss.node.name=nodoB Fine. Pedido la página de bienvenida para ver que todo funciona correctamente: http://localhost:8080 (nodeA) y http://localhost:8180 (nodoB) Configuración del servidor Web Apache para llegar a JBoss AS 7 clúster Hay más de una opción disponible para conectar un servidor Web en frente de JBoss AS 7 clúster. Se puede elegir el viejo mod_jk que ofrece una

description

 

Transcript of Clustering j boss7

Page 1: Clustering j boss7

Clustering JBoss AS 7Página 1 de 2

En este artículo vamos a mostrar cómo configurar en pocas palabras JBoss AS 7 para clustsering. A continuación, vamos a desplegar una muestra de aplicaciones Java EE 6 en la parte superior de la misma.Usuarios de JBoss anteriores utilizados para iniciar una configuración de servidor en clúster alimentando el c-all los parámetros a la shell de arranque del servidor de aplicaciones.El AS 7 es muy diferente de otras versiones del servidor, ya que no contiene varios directorios de configuración del servidor (todo, por defecto, minimal ..). Es sólo contiene un conjunto de archivos de configuración de cada uno incluyendo un conjunto diferente de módulos de servidor.La función de archivo de configuración de cluster son standalone-ha.xml y standalone-full-ha.xml (este último incluido el apoyo Corba). Así que vamos a empezar una

configuración de clúster de demostración compuesto por dos nodos en la misma máquina. 

Así descomprimir dos como 7 Distribución en el camino de su elección, por ejemplo:  C: \ jboss-as-7.1.1.Final.NodoA C: \ jboss-as-7.1.1.Final.NodoBPara iniciar los nodos del clúster que debe proporcionar un nombre de nodo único y, ya está ejecutando varios servidores en la misma máquina especificar un port offset modo que usted no tiene conflictos de puertos entre los servidores de puerto.

Así que vamos a poner en marcha NodoA con: standalone -c standalone-ha.xml -Djboss.node.name=nodoA y el nodo B con: standalone -c standalone-ha.xml -Djboss.socket.binding.port-offset=100 -Djboss.node.name=nodoB Fine. Pedido la página de bienvenida para ver que todo funciona correctamente: http://localhost:8080 (nodeA) y http://localhost:8180 (nodoB)

Configuración del servidor Web Apache para llegar a JBoss AS 7 clústerHay más de una opción disponible para conectar un servidor Web en frente de JBoss AS 7 clúster. Se puede elegir el viejo mod_jk  que ofrece una visión estática del JBoss 7 en clúster o, como sugerencia, configurar mod_cluster que proporciona ventajas adicionales, tales como:

Configuración dinámica de los trabajadores httpd

Cálculo del factor de equilibrio de carga del lado del servidor

Granuralidad fina para el control de ciclo de vida de las aplicaciones Web

Page 2: Clustering j boss7

Bibliotecas Java Mod_cluster están incorporados en JBoss AS 7 de distribución por lo que no tiene que interrumpir la comunicación en el servidor. Por otra parte, es necesario añadir a su servidor Apache las bibliotecas nativas necesarias para llamadas de proxy a JBoss AS. Descargue la última mod_cluster binarios en: http://www.jboss.org/mod_cluster/downloads/1-2-0-Final

  Los módulos anteriores pueden encontrarse en la distribución mod_cluster bajo httpd / ruta de módulos. Hay que colocarlos en la carpeta de módulos de Apache.

Luego editamos httpd.conf. Hay que añadir los módulos:LoadModule slotmem_module modules/mod_slotmem.soLoadModule manager_module modules/mod_manager.soLoadModule proxy_cluster_module modules/mod_proxy_cluster.soLoadModule advertise_module modules/mod_advertise.so    Además, tenga en cuenta que debemos comentar: # LoadModule módulos proxy_balancer_module / mod_proxy_balancer.so   Éste entra en conflicto con módulo de clúster. Y luego tenemos que hacer httpd escuchar megafonía para poder hacer la prueba. Debido a que instalamos httpd en 192.168.1.0 anfitrión se utilizará el siguiente puerto disponible:   Escuchar 192.168.1.0:6666

<VirtualHost 192.168.1.0:6666> <Directory /> Orden negar, permitir Denegar de todos Dejar de 192.168.1. </ Directory>

KeepAliveTimeout 60 MaxKeepAliveRequests 0 ManagerBalancerName myCluster AdvertiseFrequency 5 </ VirtualHost> Ahora compruebe que la conexión JBoss Apache funciona correctamente tecleando: http://192.168.1.0:6666 

Page 3: Clustering j boss7

Clustering JBoss AS 7 - Creación de una aplicación en clúster en JBoss AS 7

Página 2 de 2

Ahora vamos a implementar una variante de nuestra aplicación web Java EE 6 , que se compone de los siguientes componentes:Componentes de aplicaciónUn bean con estado de EJB que se utiliza para almacenar una memoria caché de datos, mediante la exposición de una interfaz local Un JSF bean gestionado que actúa como una capa entre el EJB y la interfaz gráfica de usuario Una vista JSF que se utiliza para recopilar datos

Vamos a empezar con la codificación de la clase JSF Managed haba:01.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import java.io.Serializable;</span> java.io.Serializable importación;</span>

02.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import java.util.ArrayList;</span> java.util.ArrayList importación;</span>

03.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import java.util.List;</span> importar java.util.List;</span>

04. 

05.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">importjavax.enterprise.context.SessionScoped;</span>

importar javax.enterprise.context.SessionScoped;</span>

06.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import javax.inject.Inject;</span> importar javax.inject.Inject;</span>

07.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import javax.inject.Named;</span> importar javax.inject.Named;</span>

Page 4: Clustering j boss7

08. 

09.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import com.sample.ejb.StatefulData;</span> com.sample.ejb.StatefulData importación;</span>

10. 

11.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">@SessionScoped</span> @ SessionScoped</span>

12.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">@Named(value="manager")</span> @ Named (value

= "manager")</span>

13.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public class PropertyManager implementsSerializable {</span> PropertyManager clase pública implementa Serializable {</span>

14. 

15.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">@Inject</span> @ Inyectar</span>

16.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">StatefulData ejb;</span> StatefulData ejb;</span>

17. 

18.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">ArrayList cacheList = newArrayList ();</span> ArrayList

cacheList = new ArrayList ();</span>

19. 

20.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">private String key;</span> clave private String;</span>

21.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">private String value;</span> Valor de la cadena privada;</span>

Page 5: Clustering j boss7

22. 

23.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public String getKey() {</span>public String getKey () {</span>

24.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">return key;</span> clave de retorno;</span>

25.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

26. 

27.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public void setKey(String key) {</span> public void setKey (String key) {</span>

28.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">this.key = key;</span> this.key key =;</span>

29.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

30. 

31.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public String getValue() {</span> getValue public String () {</span>

32.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">return value;</span> valor de retorno;</span>

33.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

34. 

35.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public void setValue(String value) {</span> setValue public void (String value) {</span>

Page 6: Clustering j boss7

36.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">this.value = value;</span> this.value = valor;</span>

37.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

38. 

39.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public void save() {</span>public void save () {</span>

40.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">ejb.put(key, value);</span> ejb.put (clave, valor);</span>

41.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

42. 

43.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public void clear() {</span>public void clear () {</span>

44.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">ejb.delete();</span> ejb.delete ();</span>

45. 

46.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

47.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public List getCacheList() {</span> getCacheList Lista pública () {</span>

48.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">returnejb.getCache();</span> volver ejb.getCache ();</span>

49.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

Page 7: Clustering j boss7

50. 

51. 

52.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

Y esta es la clase Local Stateful EJB que está anotado como @ @ Stateful clúster @ SessionScoped 

01.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">package com.sample.ejb;</span> paquete com.sample.ejb;</span>

02. 

03.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import java.util.ArrayList;</span> java.util.ArrayList importación;</span>

04.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import java.util.List;</span> importar java.util.List;</span>

05. 

06.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import javax.annotation.PostConstruct;</span> importar javax.annotation.PostConstruct;</span>

07.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import javax.ejb.LocalBean;</span> importar javax.ejb.LocalBean;</span>

08. 

09.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import javax.ejb.Stateful;</span> javax.ejb.Stateful importación;</span>

10.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr;

Page 8: Clustering j boss7

text-align: left">importjavax.enterprise.context.SessionScoped;</span>

importar javax.enterprise.context.SessionScoped;</span>

11. 

12.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">importorg.jboss.ejb3.annotation.Clustered;</span>

importar org.jboss.ejb3.annotation.Clustered;</span>

13. 

14.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import com.sample.model.Property;</span> importar com.sample.model.Property;</span>

15. 

16.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">@Stateful</span> @ Stateful</span>

17.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">@Clustered</span> @ Clúster</span>

18.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">@SessionScoped</span> @ SessionScoped</span>

19.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">@LocalBean</span> @ LocalBean</span>

20.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public class LocalStatefulDataimplements StatefulData {</span> public class LocalStatefulData implementa StatefulData {</span>

21. 

22.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">private List<Property> cache;</span> cache <Property> Lista privado;</span>

23. 

Page 9: Clustering j boss7

24.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">@Override</span> @ Override</span>

25.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">@PostConstruct</span> @ PostConstruct</span>

26.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public void initCache(){</span> initCache public void () {</span>

27.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">this.cache = queryCache();</span> this.cache QueryCache =

();</span>

28.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">if (cache ==null) cache = new ArrayList<Property>();</span> if (caché == null) cache = new ArrayList <Property> ();</span>

29.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

30. 

31. 

32.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">@Override</span> @ Override</span>

33.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public void delete(){</span> delete public void () {</span>

34.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">this.cache.clear();</span> this.cache.clear ();</span>

35.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

36. 

Page 10: Clustering j boss7

37.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">@Override</span> @ Override</span>

38.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public void put(String key,String value){</span> put public void (String key, String value) {</span>

39.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">Property p =new Property();</span> Propiedad p = new inmueble ();</span>

40.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">p.setKey(key);</span> p.setKey (clave);</span>

41.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">p.setValue(value);</span> p.setValue (valor);</span>

42.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">this.cache.add(p);</span> this.cache.add (p);</span>

43.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

44. 

45.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">@Override</span> @ Override</span>

46.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public List<Property> getCache() {</span> Lista pública <Property> GetCache () {</span>

47.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">return cache;</span> volver caché;</span>

48.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

49. 

Page 11: Clustering j boss7

50.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">@Override</span> @ Override</span>

51.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public List<Property> queryCache(){</span> Lista pública <Property> QueryCache () {</span>

52. 

53.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">return cache;</span> volver caché;</span>         

54.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

55. 

56.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

Aviso ImportanteLa versión actual de JBoss Herramientas (3.3) no se incluye de forma predeterminada las bibliotecas donde se contiene la anotación @ clúster. Hasta que este problema se resuelve, usted tiene que incluir el jboss-ejb3-ext-api-2.0.0.jarmanualmente como se muestra en la siguiente imagen: 

En aras de la exhaustividad se incluye también la interfaz Stateful SB: 01.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">package com.sample.ejb;</span> paquete com.sample.ejb;</span>

02. 

Page 12: Clustering j boss7

03.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import java.util.List;</span> importar java.util.List;</span>

04.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import com.sample.model.Property;</span> importar com.sample.model.Property;</span>

05. 

06.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public interface StatefulData {</span> interfaz pública StatefulData {</span>

07. 

08.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align:

left">public abstract void delete();</span> public abstract void delete ();</span>

09.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public abstract void put(String key, String value);</span> public abstract void put (String key, String value);</span>

10.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public abstract List<Property> getCache();</span> public abstract Lista <Property> GetCache ();</span>

11.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public abstract List<Property> queryCache();</span> public abstract Lista <Property> QueryCache ();</span>

12. 

13.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

Entonces, esta es la clase de modelo que consiste en una simple POJO: 

Page 13: Clustering j boss7

01.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">package com.sample.model;</span> com.sample.model paquete;</span>

02. 

03.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">import java.io.Serializable;</span> java.io.Serializable importación;</span>

04. 

05.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public class Property implementsSerializable{</span> Propiedad clase pública implementa Serializable {</span>

06. 

07.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">private String key;</span> clave private String;</span>

08.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">private String value;</span> Valor de la cadena privada;</span>

09. 

10.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public String getKey() {</span>public String getKey () {</span>

11.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">return key;</span> clave de retorno;</span>

12.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

13. 

14.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public void setKey(String key) {</span> public void setKey (String key) {</span>

Page 14: Clustering j boss7

15.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">this.key = key;</span> this.key key =;</span>

16.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

17. 

18.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public String getValue() {</span> getValue public String () {</span>

19.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">return value;</span> valor de retorno;</span>

20.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

21. 

22.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">public void setValue(String value) {</span> setValue public void (String value) {</span>

23.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">this.value = value;</span> this.value = valor;</span>

24.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

25. 

26.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">}</span> }</span>

Última parte de la aplicación es la página JSF home.xhtml que se unchanghed de ninguna aplicación Java EE en clúster:01.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0

Page 15: Clustering j boss7

Transitional//EN"</span> <DOCTYPE HTML PUBLIC "- / / W3C / / DTD XHTML 1.0 Transitional / / EN"</span>

02.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-

transitional.dtd"></span> "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-

transitional.dtd"></span>

03.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left"><htmlxmlns="http://www.w3.org/1999/xhtml"</span>

<HTML xmlns = "http://www.w3.org/1999/xhtml"</span>

04.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">xmlns:ui="http://java.sun.com/jsf/facelets"</span> xmlns: ui

= "http://java.sun.com/jsf/facelets"</span>

05.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">xmlns:h="http://java.sun.com/jsf/html"</span> xmlns: h =

"http://java.sun.com/jsf/html"</span>

06.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">xmlns:f="http://java.sun.com/jsf/core"</span> xmlns: f =

"http://java.sun.com/jsf/core"</span>

07.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left">xmlns:c="http://java.sun.com/jsp/jstl/core"></span> xmlns: c

= "http://java.sun.com/jsp/jstl/core"></span>

08.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left"><h:head></span> <h:head></span>

09. 

10.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left"></h:head></span> </ H: head></span>

11.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left"><h:body></span> <h:body></span>

12.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-

Page 16: Clustering j boss7

align: left"><h2>Cluster demo on JBoss 7</h2></span> <h2> demostración

Cluster en JBoss 7 </ h2></span>

13.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left"><h:form id="jsfexample"></span> <h:form id="jsfexample"></span>

14.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><h:panelGridcolumns="2" styleClass="default"></span> <h:panelGrid columns="2" styleClass="default"></span>

15. 

16.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><h:outputText value="Enter key:" /></span> <h:outputText Value="Enter key:" /></span>

17.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><h:inputText value="#{manager.key}" /></span> <h:inputText value="#{manager.key}" /></span>

18. 

19.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><h:outputText value="Enter value:" /></span> <h:outputText Value="Enter value:" /></span>

20.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><h:inputText value="#{manager.value}" /></span> <h:inputText value="#{manager.value}"/></span>

21. 

22.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><h:commandButton actionListener="#{manager.save}"</span> <H: commandButtonactionListener = "# {manager.save}"</span>

23.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">styleClass="buttons" value="Save key/value" /></span>

styleClass = value "botones" = "Guardar clave / valor" /></span>

Page 17: Clustering j boss7

24.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><h:commandButton actionListener="#{manager.clear}"</span> <H: commandButtonactionListener = "# {manager.clear}"</span>

25.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">styleClass="buttons" value="Clear cache" /></span>

styleClass = value "botones" = "Borrar caché" /></span>

26. 

27.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><h:messages /></span> <h:messages /></span>

28. 

29.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"></h:panelGrid></span> </ H: panelGrid></span>

30. 

31. 

32.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><h:dataTablevalue="#{manager.cacheList}" var="item"</span> <H: valor dataTable = var = "item" "# {manager.cacheList}"</span>

33.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">styleClass="table" headerClass="table-header"</span>

styleClass = "mesa" headerClass = "table-header"</span>

34.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left">rowClasses="table-odd-row,table-even-row"></span> rowClasses

= "table-impar fila, tabla de equilibrio fila"></span>

35.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><h:column></span> <h:column></span>

36.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><f:facet name="header">Key</f:facet></span> <f:facet name="header"> clave </ f:faceta></span>

Page 18: Clustering j boss7

37.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><h:outputText value="#{item.key}" /></span> <h:outputText value="#{item.key}" /></span>

38.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"></h:column></span> </ H: column></span>

39.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><h:column></span> <h:column></span>

40.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><f:facet name="header">Value</f:facet></span> <f:facet name="header"> Valor </ f:faceta></span>

41.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"><h:outputText value="#{item.value}" /></span> <h:outputText value="#{item.value}"/></span>

42.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"></h:column></span> </ H: column></span>

43.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><spanclass="google-src-text notranslate" style="direction: ltr; text-align: left"></h:dataTable></span> </ H: dataTable></span>

44.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left"></h:form></span> </ H: form></span>

45.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left"></h:body></span> </ H: body></span>

46.<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text notranslate" style="direction: ltr; text-align: left"></html></span> </ Html></span>

Eso es todo. Recuerde que para agregar un archivo beans.xml vacío en la carpeta WEB-INF para que las dependencias de soldadura se activan de forma automática por AS 7. He aquí cómo el proyecto debería quedar así: 

Page 19: Clustering j boss7

Ahora abra su navegador y probar la aplicación Web, señalando al puerto mod_cluster que hemos configurado antes: http://192.168.1.0:6666   / as7clustersample/home.xhtml

Nota importante acerca de conmutación por error: JSF / CDI de conmutación por error sigue sin funcionar correctamente en un clúster. Si intenta acceder a la sesión replicado en el segundo nodo muestra la siguiente advertencia en los registros:

WARN [org.jboss.as.clustering.web.infinispan] (http - 127.0.2.1-8080-1)

Page 20: Clustering j boss7

JBAS010322: Problema para acceder a sesiones [9gzXvHZaf01gCVbeao-9-PL5]:

JBAS010334: No se pudo almacenar atributos de sesión para la sesión:

9gzXvHZaf01gCVbeao -9-PL5

Verifique el tema AS7-3746 se fija antes de comprometerse en la producción con una aplicación en clúster. <