Bug 1264922

Summary: Cannot use CDI in Remote Listeners
Product: [JBoss] JBoss Data Grid 6 Reporter: Thomas Qvarnström <tqvarnst>
Component: EAP modulesAssignee: Sebastian Łaskawiec <slaskawi>
Status: CLOSED WONTFIX QA Contact: Martin Gencur <mgencur>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.5.1CC: dmehra, mgencur, rmarwaha, sjacobs, slaskawi
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-10-07 12:20:34 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Thomas Qvarnström 2015-09-21 13:18:15 UTC
Description of problem:
Class loading issues for custom java classes when using remote listeners using modules

Version-Release number of selected component (if applicable): 6.5.1


How reproducible:


Steps to Reproduce:
1. Install jboss-datagrid-6.5.1-server, jboss-eap-6.4.0 and jboss-datagrid-6.5.1-eap-modules-remote-java-client.zip 
2. Start the servers 
3. Create a WAR project
4. Create a remote message listener like this:
@ClientListener
public class MessageListener {
	
	private Logger logger = Logger.getLogger(MessageListener.class);
	
	@Inject @MessageCache
	RemoteCache<String,Message> mc;
	
	@ClientCacheEntryCreated
	public void handleCreated(ClientCacheEntryCreatedEvent<String> e) {
		String key = e.getKey();
		logger.info(String.format("Recieved Cache Entry Created of event type %s", e.getType().toString()));
		Message message = mc.get(key); //LINE 29
		logger.info(String.format("Key is %s, value is %s", key,message.getText()));
	}
}
4. Compile and Deploy everything
5. Add entries to the cache.

Actual results:
NPE
14:52:58,396 INFO  [com.redhat.middleware.jdg.chatdemo.test.MessageListener] (Client-Listener-641cb75cefa941e9) Recieved Cache Entry Created of event type CLIENT_CACHE_ENTRY_CREATED
14:52:58,397 ERROR [org.infinispan.client.hotrod.event.ClientListenerNotifier] (Client-Listener-641cb75cefa941e9) ISPN004038: Unexpected error consuming event ClientCacheEntryCreatedEvent(key=6c4aa092-297f-4bb2-8b29-aad68a384b07,dataVersion=1): org.infinispan.commons.CacheListenerException: ISPN004035: Caught exception [java.lang.reflect.InvocationTargetException] while invoking method [public void com.redhat.middleware.jdg.chatdemo.test.MessageListener.handleCreated(org.infinispan.client.hotrod.event.ClientCacheEntryCreatedEvent)] on listener instance: com.redhat.middleware.jdg.chatdemo.test.MessageListener@579d715a
	at org.infinispan.client.hotrod.event.ClientListenerNotifier$ClientListenerInvocation.invoke(ClientListenerNotifier.java:316) [infinispan-client-hotrod-6.3.1.Final-redhat-1.jar:6.3.1.Final-redhat-1]
	at org.infinispan.client.hotrod.event.ClientListenerNotifier$EventDispatcher.invokeCallbacks(ClientListenerNotifier.java:296) [infinispan-client-hotrod-6.3.1.Final-redhat-1.jar:6.3.1.Final-redhat-1]
	at org.infinispan.client.hotrod.event.ClientListenerNotifier$EventDispatcher.invokeClientEvent(ClientListenerNotifier.java:281) [infinispan-client-hotrod-6.3.1.Final-redhat-1.jar:6.3.1.Final-redhat-1]
	at org.infinispan.client.hotrod.event.ClientListenerNotifier$EventDispatcher.run(ClientListenerNotifier.java:238) [infinispan-client-hotrod-6.3.1.Final-redhat-1.jar:6.3.1.Final-redhat-1]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_71]
	at java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_71]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_71]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_71]
	at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_71]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_71]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_71]
	at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_71]
	at org.infinispan.client.hotrod.event.ClientListenerNotifier$ClientListenerInvocation.invoke(ClientListenerNotifier.java:314) [infinispan-client-hotrod-6.3.1.Final-redhat-1.jar:6.3.1.Final-redhat-1]
	... 8 more
Caused by: java.lang.NullPointerException
	at com.redhat.middleware.jdg.chatdemo.test.MessageListener.handleCreated(MessageListener.java:29) [classes:]
	... 13 more


Expected results:
A log message showing key and value of event


Additional info:
The exception is thrown because variable mc is null, e.g. CDI injection of the remote cache isn't not successful. One could probably work around the problem by not using CDI etc, but since the MessageListener is deploy as part of the WAR file this doesn't make sense to me.