From 777818d28332d67a9716d91b1dc8ec900d986b2d Mon Sep 17 00:00:00 2001 From: Patrick Linskey Date: Wed, 5 Mar 2008 00:24:45 +0000 Subject: [PATCH] OPENJPA-520. Committing on behalf of Qin Feng. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@633723 13f79535-47bb-0310-9956-ffa450edef68 --- .../event/JMSRemoteCommitProvider.java | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/event/JMSRemoteCommitProvider.java b/openjpa-kernel/src/main/java/org/apache/openjpa/event/JMSRemoteCommitProvider.java index 6b53d26a6..39ada6c18 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/event/JMSRemoteCommitProvider.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/event/JMSRemoteCommitProvider.java @@ -64,7 +64,8 @@ public class JMSRemoteCommitProvider private TopicConnection _connection; private TopicSession _session; private TopicPublisher _publisher; - + private ClassLoader _appClassLoader; + /** * Sets the JMS Topic name. Defaults to * topic/OpenJPACommitProviderTopic. @@ -151,6 +152,7 @@ public class JMSRemoteCommitProvider */ public void endConfiguration() { super.endConfiguration(); + _appClassLoader = Thread.currentThread().getContextClassLoader(); connect(); } @@ -204,29 +206,36 @@ public class JMSRemoteCommitProvider _topicName, m.getClass().getName())); return; } - - ObjectMessage om = (ObjectMessage) m; - Object o; + + ClassLoader saveCls = Thread.currentThread() + .getContextClassLoader(); try { - o = om.getObject(); + if (saveCls != _appClassLoader) + Thread.currentThread().setContextClassLoader( + _appClassLoader); + ObjectMessage om = (ObjectMessage) m; + Object o = om.getObject(); + + if (o instanceof RemoteCommitEvent) { + if (log.isTraceEnabled()) + log.trace(s_loc.get("jms-received-update", + _topicName)); + + RemoteCommitEvent rce = (RemoteCommitEvent) o; + fireEvent(rce); + } else { + if (log.isWarnEnabled()) + log.warn(s_loc.get("jms-receive-error-2", + o.getClass().getName(), _topicName)); + } } catch (JMSException jmse) { if (log.isWarnEnabled()) log.warn(s_loc.get("jms-receive-error-1"), jmse); - return; + } finally { + if (saveCls != _appClassLoader) + Thread.currentThread().setContextClassLoader(saveCls); } - if (o instanceof RemoteCommitEvent) { - if (log.isTraceEnabled()) - log.trace(s_loc.get("jms-received-update", - _topicName)); - - RemoteCommitEvent rce = (RemoteCommitEvent) o; - fireEvent(rce); - } else { - if (log.isWarnEnabled()) - log.warn(s_loc.get("jms-receive-error-2", - o.getClass().getName(), _topicName)); - } } }; }