Author: clebert.suconic(a)jboss.com
Date: 2011-11-01 21:16:08 -0400 (Tue, 01 Nov 2011)
New Revision: 11628
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientConsumerImpl.java
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java
Log:
Setting ClassLoader on MessageConsumers
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientConsumerImpl.java
===================================================================
---
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientConsumerImpl.java 2011-11-01
23:56:50 UTC (rev 11627)
+++
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientConsumerImpl.java 2011-11-02
01:16:08 UTC (rev 11628)
@@ -14,6 +14,8 @@
package org.hornetq.core.client.impl;
import java.io.File;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.Iterator;
import java.util.concurrent.Executor;
@@ -116,6 +118,8 @@
private final SessionQueueQueryResponseMessage queueInfo;
private volatile boolean ackIndividually;
+
+ private final ClassLoader contextClassLoader;
// Constructors
// ---------------------------------------------------------------------------------
@@ -130,7 +134,8 @@
final TokenBucketLimiter rateLimiter,
final Executor executor,
final Channel channel,
- final SessionQueueQueryResponseMessage queueInfo)
+ final SessionQueueQueryResponseMessage queueInfo,
+ final ClassLoader contextClassLoader)
{
this.id = id;
@@ -153,6 +158,8 @@
this.ackBatchSize = ackBatchSize;
this.queueInfo = queueInfo;
+
+ this.contextClassLoader = contextClassLoader;
}
// ClientConsumer implementation
@@ -861,7 +868,7 @@
{
return;
}
-
+
session.workDone();
// We pull the message from the buffer from inside the Runnable so we can ensure
priority
@@ -894,6 +901,8 @@
return;
}
+
+
boolean expired = message.isExpired();
flowControlBeforeConsumption(message);
@@ -906,8 +915,33 @@
{
ClientConsumerImpl.log.trace("Calling handler.onMessage");
}
- theHandler.onMessage(message);
+ final ClassLoader originalLoader = AccessController.doPrivileged(new
PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ ClassLoader originalLoader =
Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(contextClassLoader);
+
+ return originalLoader;
+ }
+ });
+ try
+ {
+ theHandler.onMessage(message);
+ }
+ finally
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(originalLoader);
+ return null;
+ }
+ });
+ }
+
if (ClientConsumerImpl.trace)
{
ClientConsumerImpl.log.trace("Handler.onMessage done");
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java
===================================================================
---
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java 2011-11-01
23:56:50 UTC (rev 11627)
+++
branches/Branch_2_2_EAP/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java 2011-11-02
01:16:08 UTC (rev 11628)
@@ -12,6 +12,8 @@
*/
package org.hornetq.core.client.impl;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -82,6 +84,7 @@
import org.hornetq.core.remoting.FailureListener;
import org.hornetq.spi.core.protocol.RemotingConnection;
import org.hornetq.spi.core.remoting.Connection;
+import org.hornetq.spi.core.remoting.ConnectorFactory;
import org.hornetq.utils.ConcurrentHashSet;
import org.hornetq.utils.IDGenerator;
import org.hornetq.utils.SimpleIDGenerator;
@@ -1779,7 +1782,8 @@
:
null,
executor,
channel,
- queueInfo);
+ queueInfo,
+ lookupTCCL());
addConsumer(consumer);
@@ -1849,7 +1853,19 @@
throw new HornetQException(HornetQException.OBJECT_CLOSED, "Session is
closed");
}
}
+
+ private ClassLoader lookupTCCL()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+
private void doCleanup(boolean failingOver)
{
if (remotingConnection == null)