-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JBTM-3273 -> Avoid implementing InvocationHandler in jtaLogger #1590
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.arjuna.ats.jta.logging; | ||
|
||
public class RecoveryRequired { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is your reasoning for naming the class as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought it would add meaning to the action, that user has to take after he gets the result. |
||
|
||
private static boolean recoveryProblems; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this is a flag which is used to mark if a recovery problem occurs and this flag could be accessed from different threads and value could be set from the different threads then the code has to(!) consider that. The property should be of type atomic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I missed this thought. Thanks for pointing this out. I will make it thread safe. |
||
|
||
public static boolean isRecoveryProblems() { | ||
return recoveryProblems; | ||
} | ||
|
||
public static void setRecoveryProblems(boolean recoveryProblems) { | ||
RecoveryRequired.recoveryProblems = recoveryProblems; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,47 +33,22 @@ | |
|
||
import org.jboss.logging.Logger; | ||
|
||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Proxy; | ||
|
||
public class jtaLogger implements InvocationHandler | ||
public class jtaLogger | ||
{ | ||
public static final Logger logger = Logger.getLogger("com.arjuna.ats.jta"); | ||
public static final jtaI18NLogger i18NLogger = (jtaI18NLogger) Proxy.newProxyInstance( | ||
jtaI18NLogger.class.getClassLoader(), | ||
new Class[] { jtaI18NLogger.class }, | ||
new jtaLogger(Logger.getMessageLogger(jtaI18NLogger.class, "com.arjuna.ats.jta"))); | ||
|
||
/** | ||
* For jtaI18NLogger, if any method, prefixed with <b>"warn_recovery"</b> is called then, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a good comment but I consider it should be put into the class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I will move the comments to jtaI18Logger |
||
* <b>RecoverRequired</b> class variable i.e. "recoveryProblem" should be set as <b>true</b>. | ||
* */ | ||
public static final jtaI18NLogger i18NLogger = Logger.getMessageLogger(jtaI18NLogger.class, "com.arjuna.ats.jta"); | ||
|
||
private jtaI18NLogger jtaI18NLoggerImpl; | ||
private static boolean recoveryProblems; | ||
|
||
private jtaLogger() { | ||
} | ||
|
||
private jtaLogger(jtaI18NLogger logger) { | ||
jtaI18NLoggerImpl = logger; | ||
} | ||
|
||
public static boolean isRecoveryProblems() { | ||
return recoveryProblems; | ||
} | ||
|
||
public static void setRecoveryProblems(boolean recoveryProblems) { | ||
jtaLogger.recoveryProblems = recoveryProblems; | ||
} | ||
|
||
@Override | ||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||
try { | ||
if (method.getName().startsWith("warn_recovery")) { | ||
recoveryProblems = true; | ||
} | ||
|
||
return method.invoke(jtaI18NLoggerImpl, args); | ||
} catch (InvocationTargetException e) { | ||
throw e.getCause() != null ? e.getCause() : e; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the placing the class under the
logging
package. As it informs about recovery processing it makes more sense to me to put it underrecovery
package. What was your reasoning about placing it here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this class is only used by jtaLogger for now, therefore I thought of placing it under
com.arjuna.ats.jta.logging
package would be fine for now. Maybe later if any other package requires it, then we could move it underrecovery
package?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will move it to
recovery
package