I wrote https://github.com/infinispan/examples/blob/master/tutorial/clustered/src/main/java/org/infinispan/examples/tutorial/clustered/util/ClusterValidation.java a couple of weeks ago for this exact purpose - just call waitForClusterToForm with the relevant cluster size/node id and it should work.
According to my experience, your cache won't be usuable until it is fully started. This means:
- if configured as a cluster member, it waits until it has succesfully joined the cluster;
- if configured with stateRetrieval, it waits until the state is retrieved from other members;
This should be enough to guarantee that your first cache operation is made on a cache whose content is insync with the rest of the cluster. If not the case, I suspect a problem in your configuration.
On the other hand, Pete's proposed solution requires that you know the size of your cluster in advance and that all members are up and running before you can do anything... This seems to be against the HA behavior you want to achieve.
Stevenll, fyi, we're gonna be implementing an optional interceptor that basically stops invocations until a weak or strict clustering requirement has been fulfilled: - https://issues.jboss.org/browse/ISPN-928
This is similar to Pete's code with the benefit that it'll be just a config switch, without requiring any code from you.