Author: cschneider
Date: Wed Jul 29 12:11:25 2015
New Revision: 1693246
URL: http://svn.apache.org/r1693246
Log:
Logging improvements
Modified:
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxNamespaceHandler.java
aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java
Modified:
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java
URL:
http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java?rev=1693246&r1=1693245&r2=1693246&view=diff
==============================================================================
---
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java
(original)
+++
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java
Wed Jul 29 12:11:25 2015
@@ -37,8 +37,7 @@ import org.slf4j.LoggerFactory;
public class TxComponentMetaDataHelperImpl implements
TxComponentMetaDataHelper {
- private static final Logger LOGGER =
- LoggerFactory.getLogger(TxComponentMetaDataHelperImpl.class);
+ private static final Logger LOGGER =
LoggerFactory.getLogger(TxComponentMetaDataHelperImpl.class);
private static class TranData
{
@@ -178,8 +177,9 @@ public class TxComponentMetaDataHelperIm
}
}
- public synchronized void
setComponentTransactionData(ComponentDefinitionRegistry registry,
ComponentMetadata component, TransactionPropagationType value, String method)
+ public synchronized void
setComponentTransactionData(ComponentDefinitionRegistry registry,
ComponentMetadata component, TransactionPropagationType txType, String method)
{
+ LOGGER.debug("Parser setting comp trans data for bean {}, method {} to
{} ", component.getId(), method, txType);
TranData td = data.get(component);
if (td == null) {
@@ -193,76 +193,56 @@ public class TxComponentMetaDataHelperIm
if (method == null || method.length() == 0) {
method = "*";
}
- if(value == null) {
- value = TransactionPropagationType.Required;
+ if(txType == null) {
+ txType = TransactionPropagationType.Required;
}
String[] names = method.split("[, \t]");
for (int i = 0; i < names.length; i++) {
Pattern pattern = Pattern.compile(names[i].replaceAll("\\*", ".*"));
- td.add(pattern, value);
+ td.add(pattern, txType);
}
}
- public TransactionPropagationType
getComponentMethodTxAttribute(ComponentMetadata component, String methodName)
- {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Getting the txAttribute for the component {0} and
method {1}", component.getId(), methodName);
- }
+ public TransactionPropagationType
getComponentMethodTxAttribute(ComponentMetadata component, String methodName) {
TranData td = data.get(component);
TransactionPropagationType result = null;
if (td != null) {
- // bean level transaction always overwrite bundle wide transaction
+ // bean level transaction always overwrite bundle wide transaction
result = td.getAttribute(methodName);
- }
-
- if (result != null) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Return the txAttribute {0} for the component
and method", result);
- }
- return result;
- } else {
- /* check the bundle wide transaction configuration in the
following priority order from (high to low)
- * 1. top level tx w/ method + bean
- * 2. top level tx w/ bean
- * 3. top level tx w/ method
- * 4. top level tx w/ no other attribute
+ }
+
+ if (result == null) {
+ /*
+ * check the bundle wide transaction configuration in the
following priority order from (high to
+ * low) 1. top level tx w/ method + bean 2. top level tx w/ bean
3. top level tx w/ method 4. top
+ * level tx w/ no other attribute
*/
- //result = calculateBundleWideTransaction(component, methodName);
+ // result = calculateBundleWideTransaction(component, methodName);
ComponentDefinitionRegistry cdr =
getComponentDefinitionRegistry(component);
if (cdr == null) {
// no bundle wide transaction configuration avail
- result = null;
+ result = null;
} else {
List<BundleWideTxData> bundleData =
bundleTransactionMap.get(cdr);
result = BundleWideTxDataUtil.getAttribute(component.getId(),
methodName, bundleData);
}
}
-
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Return the txAttribute {0} for the component and
method", result);
- }
+ LOGGER.debug("Component {}.{} is txType {}.", component.getId(),
methodName, result);
return result;
}
- public void populateBundleWideTransactionData(ComponentDefinitionRegistry
cdr, TransactionPropagationType value,
+ public void populateBundleWideTransactionData(ComponentDefinitionRegistry
cdr, TransactionPropagationType txType,
String method, String bean) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Start populating bundle wide transaction data value
{0} method {1} bean {2} per component definition registry", new Object[]{value,
method, bean});
- }
-
- BundleWideTxData bundleWideTxData = new BundleWideTxData(value,
method, bean);
+ LOGGER.debug("Setting bundle wide tx data for bean {}, method {} to
{}", bean, method, txType);
+ BundleWideTxData bundleWideTxData = new BundleWideTxData(txType,
method, bean);
List<BundleWideTxData> bundleData = bundleTransactionMap.get(cdr);
if (bundleData == null) {
bundleData = new ArrayList<BundleWideTxData>();
bundleData.add(bundleWideTxData);
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Adding component definition registry and
bundleData to the bundleTransactionMap", new Object[]{cdr, bundleData});
- }
bundleTransactionMap.put(cdr, bundleData);
-
} else {
bundleData.add(bundleWideTxData);
}
Modified:
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
URL:
http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java?rev=1693246&r1=1693245&r2=1693246&view=diff
==============================================================================
---
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
(original)
+++
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
Wed Jul 29 12:11:25 2015
@@ -33,111 +33,100 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TxInterceptorImpl implements Interceptor {
- private static final Logger LOGGER =
- LoggerFactory.getLogger(TxInterceptorImpl.class);
+ private static final Logger LOGGER =
LoggerFactory.getLogger(TxInterceptorImpl.class);
private TransactionManager tm;
private Coordinator coordinator;
private TxComponentMetaDataHelper metaDataHelper;
- public int getRank()
- {
- return 1; // Higher rank than jpa interceptor to make sure transaction
is started first
- }
-
- public Object preCall(ComponentMetadata cm, Method m,
- Object... parameters) throws Throwable {
- final String methodName = m.getName();
- final TransactionPropagationType type =
metaDataHelper.getComponentMethodTxAttribute(cm, methodName);
-
- // attribute could be null here which means no transaction
- if (type == null) {
- return null;
- }
- TransactionAttribute txAttribute = TransactionAttribute.fromValue(type);
-
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Calling begin for method {} with tx strategy {}.", m,
txAttribute);
- }
- TransactionToken token = txAttribute.begin(tm);
- coordinator.begin("txInterceptor", 0);
- return token;
- }
-
- public void postCallWithException(ComponentMetadata cm, Method m,
- Throwable ex, Object preCallToken)
- {
- if (!(preCallToken instanceof TransactionToken))
- {
- return;
- }
- endCoordination();
- final TransactionToken token = (TransactionToken)preCallToken;
- try {
- Transaction tran = token.getActiveTransaction();
- if (tran != null && isRollBackException(ex)) {
- tran.setRollbackOnly();
- }
- token.getTransactionAttribute().finish(tm, token);
- }
- catch (Exception e)
- {
- // we do not throw the exception since there already is one, but we
need to log it
-
LOGGER.warn(Constants.MESSAGES.getMessage("exception.during.tx.cleanup"), e);
- }
- }
-
- public void postCallWithReturn(ComponentMetadata cm, Method m,
- Object returnType, Object preCallToken) throws Exception
- {
+
+ public int getRank() {
+ return 1; // Higher rank than jpa interceptor to make sure transaction
is started first
+ }
+
+ public Object preCall(ComponentMetadata cm, Method m, Object...
parameters) throws Throwable {
+ final String methodName = m.getName();
+ final TransactionPropagationType type =
metaDataHelper.getComponentMethodTxAttribute(cm, methodName);
+
+ // attribute could be null here which means no transaction
+ if (type == null) {
+ return null;
+ }
+ TransactionAttribute txAttribute =
TransactionAttribute.fromValue(type);
+
+ LOGGER.debug("PreCall for bean {}, method {} with tx strategy {}.",
getCmId(cm), m.getName(), txAttribute);
+ TransactionToken token = txAttribute.begin(tm);
+ coordinator.begin("txInterceptor", 0);
+ return token;
+ }
+
+ public void postCallWithException(ComponentMetadata cm, Method m,
Throwable ex, Object preCallToken) {
+ LOGGER.debug("PostCallWithException for bean {}, method {}.",
getCmId(cm), m.getName(), ex);
+ if (!(preCallToken instanceof TransactionToken)) {
+ return;
+ }
+ endCoordination();
+ final TransactionToken token = (TransactionToken)preCallToken;
+ try {
+ Transaction tran = token.getActiveTransaction();
+ if (tran != null && isRollBackException(ex)) {
+ tran.setRollbackOnly();
+ }
+ token.getTransactionAttribute().finish(tm, token);
+ } catch (Exception e) {
+ // we do not throw the exception since there already is one, but
we need to log it
+ LOGGER.warn("Exception during transaction cleanup", e);
+ }
+ }
+
+ private String getCmId(ComponentMetadata cm) {
+ return cm == null ? null : cm.getId();
+ }
+
+ public void postCallWithReturn(ComponentMetadata cm, Method m, Object
returnType, Object preCallToken)
+ throws Exception {
+ LOGGER.debug("PostCallWithReturn for bean {}, method {}.",
getCmId(cm), m);
// it is possible transaction is not involved at all
if (preCallToken == null) {
- return;
+ return;
}
endCoordination();
- if (preCallToken instanceof TransactionToken)
- {
- final TransactionToken token = (TransactionToken)preCallToken;
- try {
- token.getTransactionAttribute().finish(tm, token);
+ if (preCallToken instanceof TransactionToken) {
+ final TransactionToken token = (TransactionToken)preCallToken;
+ try {
+ token.getTransactionAttribute().finish(tm, token);
+ } catch (Exception e) {
+ // We are throwing an exception, so we don't error it out
+
LOGGER.debug(Constants.MESSAGES.getMessage("exception.during.tx.finish"), e);
+ throw new TransactionRollbackException(e);
+ }
+ } else {
+ // TODO: what now?
}
- catch (Exception e)
- {
- // We are throwing an exception, so we don't error it out
-
LOGGER.debug(Constants.MESSAGES.getMessage("exception.during.tx.finish"), e);
- throw new TransactionRollbackException(e);
- }
- }
- else {
- // TODO: what now?
- }
}
private void endCoordination() {
try {
- Coordination coord = coordinator.pop();
- coord.end();
- } catch (Exception e) {
- LOGGER.warn("Error ending coordination ", e);
- }
+ Coordination coord = coordinator.pop();
+ coord.end();
+ } catch (Exception e) {
+ LOGGER.warn("Error ending coordination ", e);
+ }
}
private boolean isRollBackException(Throwable ex) {
return ex instanceof RuntimeException || ex instanceof Error;
}
- public final void setTransactionManager(TransactionManager manager)
- {
- tm = manager;
- }
-
- public void setCoordinator(Coordinator coordinator)
- {
+ public final void setTransactionManager(TransactionManager manager) {
+ tm = manager;
+ }
+
+ public void setCoordinator(Coordinator coordinator) {
this.coordinator = coordinator;
}
- public final void setTxMetaDataHelper(TxComponentMetaDataHelper
transactionEnhancer)
- {
- this.metaDataHelper = transactionEnhancer;
+ public final void setTxMetaDataHelper(TxComponentMetaDataHelper
transactionEnhancer) {
+ this.metaDataHelper = transactionEnhancer;
}
}
Modified:
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java
URL:
http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java?rev=1693246&r1=1693245&r2=1693246&view=diff
==============================================================================
---
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java
(original)
+++
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java
Wed Jul 29 12:11:25 2015
@@ -70,7 +70,7 @@ public class AnnotationParser implements
}
if (shouldAssignInterceptor && !isInterceptorAssigned(beanData)) {
- LOGGER.debug("Adding transaction interceptor to {} with class
{}.", beanName, bean.getClass());
+ LOGGER.debug("Adding transaction interceptor to bean {} with class
{}.", beanName, bean.getClass());
cdr.registerInterceptorWithComponent(beanData, interceptor);
}
Modified:
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxNamespaceHandler.java
URL:
http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxNamespaceHandler.java?rev=1693246&r1=1693245&r2=1693246&view=diff
==============================================================================
---
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxNamespaceHandler.java
(original)
+++
aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxNamespaceHandler.java
Wed Jul 29 12:11:25 2015
@@ -77,11 +77,10 @@ public class TxNamespaceHandler implemen
private void parseElement(Element elt, ComponentMetadata cm, ParserContext
pc)
{
- LOGGER.debug("parser asked to parse .. " + elt);
+ LOGGER.debug("parser asked to parse element {} ", elt);
ComponentDefinitionRegistry cdr = pc.getComponentDefinitionRegistry();
if ("transaction".equals(elt.getLocalName())) {
- LOGGER.debug("parser adding interceptor for " + elt);
Bundle blueprintBundle = getBlueprintBundle(cdr);
// don't register components if we have no bundle (= dry parse)
@@ -89,15 +88,14 @@ public class TxNamespaceHandler implemen
registered.put(cdr, blueprintBundle);
TransactionPropagationType txType =
getType(elt.getAttribute(VALUE));
String method = elt.getAttribute(METHOD);
+ String beanAttr = elt.getAttribute(BEAN);
if (cm == null) {
// if the enclosing component is null, then we assume this
is the top element
-
- String bean = elt.getAttribute(BEAN);
- registerComponentsWithInterceptor(cdr, bean);
- metaDataHelper.populateBundleWideTransactionData(cdr,
txType, method, bean);
+ registerComponentsWithInterceptor(cdr, beanAttr);
+ metaDataHelper.populateBundleWideTransactionData(cdr,
txType, method, beanAttr);
} else {
cdr.registerInterceptorWithComponent(cm, interceptor);
- LOGGER.debug("parser setting comp trans data for " + txType
+ " " + method);
+
metaDataHelper.setComponentTransactionData(cdr, cm, txType,
method);
}
}
@@ -112,8 +110,6 @@ public class TxNamespaceHandler implemen
}
}
}
-
- LOGGER.debug("parser done with " + elt);
}
private Bundle getBlueprintBundle(ComponentDefinitionRegistry cdr) {
Modified:
aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java
URL:
http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java?rev=1693246&r1=1693245&r2=1693246&view=diff
==============================================================================
---
aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java
(original)
+++
aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java
Wed Jul 29 12:11:25 2015
@@ -50,7 +50,7 @@ public class InterceptorTest {
c.replay();
TransactionToken tt = new TransactionToken(tran, null,
TransactionAttribute.REQUIRED);
- sut.postCallWithException(null, null, th, tt);
+ sut.postCallWithException(null, this.getClass().getMethods()[0], th,
tt);
c.verify();
}