I'm trying to create a simple clustered Singleton
on Wildfly 8.2. I've configured 2 Wildfly instances, running in a standalone clustered configuration. My app is deployed to both, and I'm able to access it with no problem.
My clustered EJB looks like this:
@Named
@Clustered
@Singleton
public class PeekPokeEJB implements PeekPoke {
/**
* Logger for this class
*/
private static final Logger logger = Logger
.getLogger(PeekPokeEJB.class);
private static final long serialVersionUID = 2332663907180293111L;
private int value = -1;
@Override
public void poke() {
if (logger.isDebugEnabled()) {
logger.debug("poke() - start"); //$NON-NLS-1$
}
Random rand = new SecureRandom();
int newValue = rand.nextInt();
if (logger.isDebugEnabled()) {
logger.debug("poke() - int newValue=" + newValue); //$NON-NLS-1$
}
this.value = newValue;
if (logger.isDebugEnabled()) {
logger.debug("poke() - end"); //$NON-NLS-1$
}
}
@Override
public void peek() {
if (logger.isDebugEnabled()) {
logger.debug("peek() - start"); //$NON-NLS-1$
}
if (logger.isDebugEnabled()) {
logger.debug("peek() - value=" + value); //$NON-NLS-1$
}
if (logger.isDebugEnabled()) {
logger.debug("peek() - end"); //$NON-NLS-1$
}
}
}
...and I've written a very simple RESTful service to let me call these methods through the browser...
@Path("/test")
@Named
public class TestRS extends AbstractRestService {
/**
* Logger for this class
*/
private static final Logger logger = Logger.getLogger(TestRS.class);
@Inject
private PeekPoke ejb = null;
@GET
@Path("/poke")
public void poke() {
if (logger.isDebugEnabled()) {
logger.debug("poke() - start"); //$NON-NLS-1$
}
this.ejb.poke();
if (logger.isDebugEnabled()) {
logger.debug("poke() - end"); //$NON-NLS-1$
}
}
@GET
@Path("/peek")
public void peek() {
if (logger.isDebugEnabled()) {
logger.debug("peek() - start"); //$NON-NLS-1$
}
this.ejb.peek();
if (logger.isDebugEnabled()) {
logger.debug("peek() - end"); //$NON-NLS-1$
}
}
}
I'm able to call both the peek
and poke
methods from a single Wildfly instance and get the expected value. However, if I attempt to call poke from one instance, and peek from another I see that the values are not being replicated across the EJBs.
I was under the impression that a clustered singleton would replicate the value of 'value
' across both application servers, providing the same value regardless of which host I made the peek
call from. Is this not correct? Is there something I'm missing that still needs to be added to this code?
I'd appreciate any help you can give me! Thanks!