3

I'm using a vanilla JBossAS 6 server with a couple of projects to test the functionality of clustered JBoss environments. The problem that I have is that if I transfer an EJB reference from one EJB (of another type) in a node, to an instance of the same type in another node, upon method invocation an exception is thrown, stating that the long_alphanumeric_key key for the specified bean is not registered in the cache (InfinispanStatefulCache).

The thing is that when using a Singleton annotation instead of a Stateful annotation on the object that I need to transfer, the transferred objects works flawlessly, succesfully invoking methods of the shared EJB on the server where it was created. The problem is that this case has the same flaw as the HA-Singleton. All transferred references where previously obtained via a lookup on the HA-JNDI tree.

Some insight on what I'm trying to achieve:

What I currently need is to share a single instance of a Stateful EJB between nodes, like a HA-Singleton. The reason for not using HA-Singleton is that the state of this type of singletons is mantained exclusively on the master node of the cluster, so if the node shutsdown or fails, the state of the instance is lost.

Using a Stateful bean would allow me to mantain the state on the cluster, thus preventing state loss upon failure on a node. I've yet to fully understand how does JBoss and Infinispan cache work, but as far as I've read, @Clustered annotated stateful beans' state is automatically replicated over the cluster.

We've been already warned of the problems of using Singletons and HA-Singletons in the current JBoss version, so any kind of document or pattern to aid solving this design change will be welcome.

Also, I would appreciate any documentation that can provide me insight on how does Infinispan cache and JBoss clustering work. So far the material I've been reading was mixed with older JBoss versions where JBossCache was used instead of Infinispan.

Thanks ind advance,
German

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194

1 Answers1

2

Unfortunately, JBoss AS6 or AS7 does not yet support clustered EJB Singletons - which is really what you're looking for, I think. HA-Singleton will make sure only one instance of some service is only ever started on a single node of the cluster. That doesn't seem like it fits your use case. It seems you really only need to distribute the state of an EJB singleton. Here's what I'd recommend, use a local EJB singleton, but use infinispan to store its distributed state: * For starters, I'd recommend you use AS7 instead of AS6, as the Infinispan integration is more mature. * In AS7, you can directly use an infinispan cache in your Singleton. e.g.

@Singleton
public class MySingleton {
  // This references the same infinispan cache container used for sfsb replication
  @Resource(lookup="java:jboss/infinispan/container/ejb")
  private CacheContainer container;
  private Cache<?, ?> cache;

  @PostContruct
  public void init() {
    // This will create a cache for use by this singleton
    // Any state to be distributed should be stored in the cache.
    this.cache = container.getCache(this.getClass().getName());
  }

  @PreDestroy
  public void destroy() {
    this.cache.stop();
  }
}