0
votes

I have running two EAP 7.0 instances, both with standalone-full-ha.xml

One is started with:

/opt/jboss-eap-7.0/bin/standalone.sh -Djboss.node.name=node1 -Djboss.server.base.dir=/opt/node1 -Djboss.messaging.cluster.password=message -c standalone-full-ha.xml

The other one with:

/opt/jboss-eap-7.0/bin/standalone.sh -Djboss.node.name=node2 -Djboss.server.base.dir=/opt/node2 -Djboss.messaging.cluster.password=message -c standalone-full-ha.xml -Djboss.socket.binding.port-offset=4

Both start with success and I can see they join the cluster channel:

[org.infinispan.remoting.transport.jgroups.JGroupsTransport] (MSC service thread 1-6) ISPN000078: Starting JGroups channel ejb
...
[org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 72) WFLYCLINF0002: Started eap.war cache from ejb container

I have a stateful session bean:

import javax.ejb.Stateful;

@Stateful
public class Counter {

    int counter;

    public int getCounter() {
        ++counter;
        return counter;
    }
}

A JSF application scoped bean:

import java.io.Serializable;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;

@ApplicationScoped
@Named
public class IndexBean implements Serializable {

    @Inject
    transient Counter counter;

    public int getCounter() {
        return counter.getCounter();
    }
}

A JSF session scoped bean:

import java.io.Serializable;

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@SessionScoped
@Named
public class SessionBean implements Serializable {

    int counter;

    public int getCounter() {
        ++counter;
        return counter;
    }

}

Web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" metadata-complete="false" version="3.1">
<distributable/>
</web-app>

And index.xhtml:

<html
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
    <title>EAP 7</title>
</h:head>
<h:body>
<h:outputText value="#{indexBean.counter}"></h:outputText>
<br />
<br />
<h:outputText value="#{sessionBean.counter}"></h:outputText>
</h:body>
</html>

Now when I navigate to node1 on localhost:8080/index.xhtml I have a webppage with two counters starting with 1. And every time I refresh the page it counts up.

When I navigate to node2 on localhost:8084/index.xhtml I expect to see both last incremented values from node1, but the counter coming from the @Stateful bean doesn't increment on the value from node1.

Example: navigate to node1:

1
1

-> refresh node1

2
2

-> refresh node1

3
3

navigate to node2:

1
4

-> refresh node2

2
5

refresh again node1:

4
6

refresh again node2:

3
8

The two pages work independently, however the state between the stateful session beans should be replicated. I don't understand why it doesn't work. The state between the @SessionScoped beans is always replicated...

I was looking for some documentation and found this:

https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html/developing_ejb_applications/clustered_enterprise_javabeans#cluster_topology_communication

Here is stated in the end of section 8.2:

Starting JBoss EAP 7, if JBoss EAP is started using an HA profile, the state of your SFSBs will be replicated.

Is there more configuration needed for @Stateful beans?

1

1 Answers

0
votes

The issue with your code above is that the @ApplicationScoped SFSB reference isn't shared between node1 and node2, even though the state itself is replicated.