From 3874196efea2670c26982559158ed4c09034635d Mon Sep 17 00:00:00 2001 From: Gytis Trikleris Date: Tue, 11 Jul 2017 15:15:07 +0200 Subject: [PATCH 1/2] Simplify retrieval of Narayana XARecoveryModule See gh-9725 --- .../narayana/NarayanaRecoveryManagerBean.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/jta/narayana/NarayanaRecoveryManagerBean.java b/spring-boot/src/main/java/org/springframework/boot/jta/narayana/NarayanaRecoveryManagerBean.java index 3bbb47356b..58be823528 100644 --- a/spring-boot/src/main/java/org/springframework/boot/jta/narayana/NarayanaRecoveryManagerBean.java +++ b/spring-boot/src/main/java/org/springframework/boot/jta/narayana/NarayanaRecoveryManagerBean.java @@ -16,8 +16,6 @@ package org.springframework.boot.jta.narayana; -import com.arjuna.ats.arjuna.recovery.RecoveryManager; -import com.arjuna.ats.arjuna.recovery.RecoveryModule; import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule; import com.arjuna.ats.jbossatx.jta.RecoveryManagerService; import com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper; @@ -53,20 +51,17 @@ public class NarayanaRecoveryManagerBean implements InitializingBean, Disposable this.recoveryManagerService.destroy(); } - void registerXAResourceRecoveryHelper( - XAResourceRecoveryHelper xaResourceRecoveryHelper) { - getXARecoveryModule(RecoveryManager.manager()) - .addXAResourceRecoveryHelper(xaResourceRecoveryHelper); + void registerXAResourceRecoveryHelper(XAResourceRecoveryHelper xaResourceRecoveryHelper) { + getXARecoveryModule().addXAResourceRecoveryHelper(xaResourceRecoveryHelper); } - private XARecoveryModule getXARecoveryModule(RecoveryManager recoveryManager) { - for (RecoveryModule recoveryModule : recoveryManager.getModules()) { - if (recoveryModule instanceof XARecoveryModule) { - return (XARecoveryModule) recoveryModule; - } + private XARecoveryModule getXARecoveryModule() { + XARecoveryModule xaRecoveryModule = XARecoveryModule.getRegisteredXARecoveryModule(); + if (xaRecoveryModule == null) { + throw new IllegalStateException( + "XARecoveryModule is not registered with recovery manager"); } - throw new IllegalStateException( - "XARecoveryModule is not registered with recovery manager"); + return xaRecoveryModule; } } From 2925f1b86a9cc8119911e04b3e6b56f034726468 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 28 Jul 2017 07:31:32 +0100 Subject: [PATCH 2/2] Polish "Simplify retrieval of Narayana XARecoveryModule" Closes gh-9725 --- .../narayana/NarayanaRecoveryManagerBean.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/jta/narayana/NarayanaRecoveryManagerBean.java b/spring-boot/src/main/java/org/springframework/boot/jta/narayana/NarayanaRecoveryManagerBean.java index 58be823528..25f6ed1635 100644 --- a/spring-boot/src/main/java/org/springframework/boot/jta/narayana/NarayanaRecoveryManagerBean.java +++ b/spring-boot/src/main/java/org/springframework/boot/jta/narayana/NarayanaRecoveryManagerBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,17 +51,19 @@ public class NarayanaRecoveryManagerBean implements InitializingBean, Disposable this.recoveryManagerService.destroy(); } - void registerXAResourceRecoveryHelper(XAResourceRecoveryHelper xaResourceRecoveryHelper) { + void registerXAResourceRecoveryHelper( + XAResourceRecoveryHelper xaResourceRecoveryHelper) { getXARecoveryModule().addXAResourceRecoveryHelper(xaResourceRecoveryHelper); } private XARecoveryModule getXARecoveryModule() { - XARecoveryModule xaRecoveryModule = XARecoveryModule.getRegisteredXARecoveryModule(); - if (xaRecoveryModule == null) { - throw new IllegalStateException( - "XARecoveryModule is not registered with recovery manager"); + XARecoveryModule xaRecoveryModule = XARecoveryModule + .getRegisteredXARecoveryModule(); + if (xaRecoveryModule != null) { + return xaRecoveryModule; } - return xaRecoveryModule; + throw new IllegalStateException( + "XARecoveryModule is not registered with recovery manager"); } }