1 2 Previous Next 17 Replies Latest reply on Feb 24, 2016 8:59 AM by Tom Jenkinson

    How to enlist a custom XAResouce in the spring and start the recovery manager service

    Amos Feng Apprentice

      Hi,

       

      I currently use the following codes to enlist the custom XAResouce explictly

       

         
      @Service
      public class ExampleService {
      
          private JdbcTemplate jdbc;
      
          @Autowired
          private JtaTransactionManager transactionManager;
      
          @Autowired
          public ExampleService(JdbcTemplate jdbc) {
              this.jdbc = jdbc;
          }
      
          @Transactional
          public void testRecovery() throws Exception {
              Transaction transaction  = transactionManager.getTransactionManager().getTransaction();
              transaction.enlistResource(new DummyXAResource(DummyXAResource.faultType.HALT));
              jdbc.execute("insert into example values (1, 'test1')");
          }
      }
      

       

      I wonder that is there the way to inject the bean of DummyXAResouce and the spring can enlist it in the method with the annotation of Transactional automatically ?

       

      in term of starting the recovery manager service, it looks like the spring does not provide the way to integrate the recovery manager. So it need to setup and run the scanning manually in the application.

      I borrow some codes from the ArjunaJTA/recovery and it should work.

          if(args.length == 1) {
                  if (args[0].equals("-f")) {
                      BeanPopulator.getDefaultInstance(ObjectStoreEnvironmentBean.class).setObjectStoreDir(Util.recoveryStoreDir);
                      service.testRecovery();
                  } else if (args[0].equals("-r")) {
                      RecoverySetup.startRecovery();
                      try {
                          new DummyRecovery().waitForRecovery();
                          service.checkRecord();
                      } catch (RuntimeException e) {
                          System.err.println(e);
                      }
                      RecoverySetup.stopRecovery();
                  }
              }
      

       

      Thanks for the input,

      Amos

        1 2 Previous Next