Product SiteDocumentation Site

2.6. Alternative to XAResourceRecovery

The iterator based approach used by XAResourceRecovery leads to a requirement for implementations to manage state, which makes them more complex than necessary.
As an alternative, starting with JBossTS 4.4, users may provide an implementation of the public interface
Example 2.4. XAResourceRecoveryHelper
public interface com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper	{
    public boolean initialise(String p) throws Exception;
    public XAResource[] getXAResources() throws Exception;
}

During each recovery sweep the getXAResources method will be called and recovery attempted on each element of the array. For the majority of resource managers it will be necessary to have only one XAResource in the array, as the recover() call on it can return multiple Xids.
Unlike XAResourceRecovery instances, which are configured via the xml properties file and instantiated by JBossTS, instances of XAResourceRecoveryHelper and constructed by the application code and registered with JBossTS by calling
XARecoveryModule.addXAResourceRecoveryHelper(...)
The initialize method is not called by JBossTS in the current implementation, but is provided to allow for the addition of further configuration options in later releases.
XAResourceRecoveryHelper instances may be deregistered, after which they will no longer be called by the recovery manager. Deregistration may block for a time if a recovery scan is in progress.
XARecoveryModule.removeXAResourceRecoveryHelper(...)
The ability to dynamically add and remove instances of XAResourceRecoveryHelper whilst the system is running makes this approach an attractive option for environments in which e.g. datasources may be deployed or undeployed, such as application servers. Care should be taken with classloading behaviour in such cases.