1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.messaging;
16  
17  /**
18   * <a href="InvokerMessageListener.java.html"><b><i>View Source</i></b></a>
19   *
20   * @author Michael C. Han
21   */
22  public class InvokerMessageListener implements MessageListener {
23  
24      public InvokerMessageListener(MessageListener messageListener) {
25          this(
26              messageListener,
27              Thread.currentThread().getContextClassLoader());
28      }
29  
30      public InvokerMessageListener(
31          MessageListener messageListener, ClassLoader classLoader) {
32  
33          _messageListener = messageListener;
34          _classLoader = classLoader;
35      }
36  
37      public boolean equals(Object obj) {
38          InvokerMessageListener messageListenerInvoker =
39              (InvokerMessageListener)obj;
40  
41          return _messageListener.equals(
42              messageListenerInvoker.getMessageListener());
43      }
44  
45      public ClassLoader getClassLoader() {
46          return _classLoader;
47      }
48  
49      public MessageListener getMessageListener() {
50          return _messageListener;
51      }
52  
53      public int hashCode() {
54          return _messageListener.hashCode();
55      }
56  
57      public void receive(Message message) {
58          Thread currentThread = Thread.currentThread();
59  
60          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
61  
62          currentThread.setContextClassLoader(_classLoader);
63  
64          try {
65              _messageListener.receive(message);
66          }
67          finally {
68              currentThread.setContextClassLoader(contextClassLoader);
69          }
70      }
71  
72      private MessageListener _messageListener;
73      private ClassLoader _classLoader;
74  
75  }