Stateful EJB invocation always occurs on the same node. Even after a new session is created.
heyw Jun 23, 2012 11:18 AMIn the following client example application, the SFSB will always invoked on the same node of a local cluster with two nodes. After three calls, the session bean is removed and a new session bean is created by a lookup.
EJB remote client:
public class Main {
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
Context context = new InitialContext(props);
ClusteredStateless clusteredStatelessBeanProxy = (ClusteredStateless) context
.lookup("ejb:/cluster/ClusteredStatelessBean!de.akquinet.jbosscc.cluster.ClusteredStateless");
ClusteredStateful clusteredStatefulSession = getClusteredStatefulSession(context);
for (int i = 0; i < 100; i++) {
String nodeName = clusteredStatelessBeanProxy.getNodeName();
System.out.println("nodename: " + nodeName);
int counterValue = clusteredStatefulSession.getCounterValue();
System.out.println("Stateful session bean - counter value "
+ counterValue + " recieved from node: "
+ clusteredStatefulSession.getNodeName() + " proxy "
+ clusteredStatefulSession);
if (counterValue % 3 == 0) {
System.out.println("destroy stateful ejb on node: "
+ clusteredStatefulSession.getNodeName());
clusteredStatefulSession.destroy();
clusteredStatefulSession = getClusteredStatefulSession(context);
}
}
}
static ClusteredStateful getClusteredStatefulSession(final Context context)
throws Exception {
return (ClusteredStateful) context
.lookup("ejb:/cluster/ClusteredStatefulBean!de.akquinet.jbosscc.cluster.ClusteredStateful?stateful");
}
}
JBoss EJB client configuration:
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false remote.connections=one remote.connection.one.host=192.168.0.1 remote.connection.one.port=4447 remote.connection.one.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false 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 #remote.cluster.ejb.clusternode.selector=de.akquinet.jbosscc.cluster.RoundRobinClusterNodeSelector
Log:
23.06.2012 17:04:09 org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 1.1.0.Beta1-SNAPSHOT
23.06.2012 17:04:09 org.xnio.Xnio <clinit>
INFO: XNIO Version 3.0.3.GA
23.06.2012 17:04:09 org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.0.3.GA
23.06.2012 17:04:09 org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 3.2.7.GA
23.06.2012 17:04:09 org.jboss.ejb.client.remoting.VersionReceiver handleMessage
INFO: Received server version 1 and marshalling strategies [river]
23.06.2012 17:04:09 org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@6426d607, receiver=Remoting connection EJB receiver [connection=Remoting connection <788ab708>,channel=jboss.ejb,nodename=jb1]} on channel Channel ID e7e65166 (outbound) of Remoting connection 33589e56 to /192.168.0.1:4447
23.06.2012 17:04:09 org.jboss.ejb.client.ClusterContext registerEJBReceiver
INFO: Added a new EJB receiver in cluster context ejb for node jb1. Total nodes in cluster context = 1
23.06.2012 17:04:09 org.jboss.ejb.client.remoting.VersionReceiver handleMessage
INFO: Received server version 1 and marshalling strategies [river]
23.06.2012 17:04:09 org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@6426d607, receiver=Remoting connection EJB receiver [connection=Remoting connection <e4865ce>,channel=jboss.ejb,nodename=jb2]} on channel Channel ID 97031800 (outbound) of Remoting connection 39ed1b0b to /192.168.0.2:4447
23.06.2012 17:04:09 org.jboss.ejb.client.ClusterContext registerEJBReceiver
INFO: Added a new EJB receiver in cluster context ejb for node jb2. Total nodes in cluster context = 2
nodename: jb1
Stateful session bean - counter value 1 recieved from node: jb1 proxy Proxy for remote EJB StatefulEJBLocator{appName='', moduleName='cluster', distinctName='', beanName='ClusteredStatefulBean', view='interface de.akquinet.jbosscc.cluster.ClusteredStateful', sessionId='{[74, 113, 3, -98, -111, -95, 68, -126, -128, -69, 90, -5, 49, -43, 25, 82]}'}
nodename: jb1
Stateful session bean - counter value 2 recieved from node: jb1 proxy Proxy for remote EJB StatefulEJBLocator{appName='', moduleName='cluster', distinctName='', beanName='ClusteredStatefulBean', view='interface de.akquinet.jbosscc.cluster.ClusteredStateful', sessionId='{[74, 113, 3, -98, -111, -95, 68, -126, -128, -69, 90, -5, 49, -43, 25, 82]}'}
nodename: jb1
Stateful session bean - counter value 3 recieved from node: jb1 proxy Proxy for remote EJB StatefulEJBLocator{appName='', moduleName='cluster', distinctName='', beanName='ClusteredStatefulBean', view='interface de.akquinet.jbosscc.cluster.ClusteredStateful', sessionId='{[74, 113, 3, -98, -111, -95, 68, -126, -128, -69, 90, -5, 49, -43, 25, 82]}'}
destroy stateful ejb on node: jb1
nodename: jb1
Stateful session bean - counter value 1 recieved from node: jb1 proxy Proxy for remote EJB StatefulEJBLocator{appName='', moduleName='cluster', distinctName='', beanName='ClusteredStatefulBean', view='interface de.akquinet.jbosscc.cluster.ClusteredStateful', sessionId='{[-83, -62, 69, 37, 114, 4, 75, -119, -127, -116, 46, 34, -84, 29, -31, -36]}'}
nodename: jb2
Stateful session bean - counter value 2 recieved from node: jb1 proxy Proxy for remote EJB StatefulEJBLocator{appName='', moduleName='cluster', distinctName='', beanName='ClusteredStatefulBean', view='interface de.akquinet.jbosscc.cluster.ClusteredStateful', sessionId='{[-83, -62, 69, 37, 114, 4, 75, -119, -127, -116, 46, 34, -84, 29, -31, -36]}'}
nodename: jb1
Stateful session bean - counter value 3 recieved from node: jb1 proxy Proxy for remote EJB StatefulEJBLocator{appName='', moduleName='cluster', distinctName='', beanName='ClusteredStatefulBean', view='interface de.akquinet.jbosscc.cluster.ClusteredStateful', sessionId='{[-83, -62, 69, 37, 114, 4, 75, -119, -127, -116, 46, 34, -84, 29, -31, -36]}'}
destroy stateful ejb on node: jb1
nodename: jb1
Stateful session bean - counter value 1 recieved from node: jb1 proxy Proxy for remote EJB StatefulEJBLocator{appName='', moduleName='cluster', distinctName='', beanName='ClusteredStatefulBean', view='interface de.akquinet.jbosscc.cluster.ClusteredStateful', sessionId='{[113, 58, 100, 72, -47, -98, 65, -77, -122, -37, 5, 94, 23, -85, -33, 2]}'}
nodename: jb2
...
Even, if the custom cluster node selector is activated, the selector will only called for SLSB invocations.
Is it possible to configure a policy for load balancing of new SFSB invocations?