Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

ClassCastException in Notify container

I have an annotation-marked Notify container:

@EventDriven @Notify(performTakeOnNotify=true,ignoreEventOnNullTake=true) @Component public class MyClass { @SpaceDataEvent public void process(Clazz1 inData) { // do something } }

The intent is to take the object and process it, removing it from the space. A side-effect later on writes a different object (Clazz2 type) to the space. I get this exception:

[gsc][1/23699] 2011-03-31 10:58:04,998 xap-marketcetera [1] SEVERE [org.openspaces.events.notify.SimpleNotifyEventListenerContainer] - [xapOrderPicker] Execution of event listener failed; Caused by: org.openspaces.events.ListenerExecutionFailedException: Listener event method [process] of class [com.mycompany.MyClass] threw exception; nested exception is java.lang.ClassCastException: com.mycompany.Clazz2 cannot be cast to com.mycompany.Clazz1 [gsc][1/23699] at org.openspaces.events.adapter.AbstractReflectionEventListenerAdapter.onEventWithResult(AbstractReflectionEventListenerAdapter.java:178) [gsc][1/23699] at org.openspaces.events.adapter.AbstractResultEventListenerAdapter.onEvent(AbstractResultEventListenerAdapter.java:77) [gsc][1/23699] at org.openspaces.events.AbstractEventListenerContainer.invokeListener(AbstractEventListenerContainer.java:194) [gsc][1/23699] at org.openspaces.events.notify.AbstractNotifyEventListenerContainer.invokeListenerWithTransaction(AbstractNotifyEventListenerContainer.java:855) [gsc][1/23699] at org.openspaces.events.notify.SimpleNotifyEventListenerContainer$NotifyListenerDelegate.notify(SimpleNotifyEventListenerContainer.java:271) [gsc][1/23699] at com.j_spaces.core.client.NotifyDelegator.notify(NotifyDelegator.java:182) [gsc][1/23699] at com.j_spaces.core.client.RemoteEventListenerExporter$TransientDelegator.notify(RemoteEventListenerExporter.java:155) [gsc][1/23699] at com.gigaspaces.internal.lrmi.stubs.LRMIRemoteEventListener.notify(LRMIRemoteEventListener.java:96) [gsc][1/23699] at com.j_spaces.core.server.processor.RemoteEventBusPacket.notifyListener(RemoteEventBusPacket.java:124) [gsc][1/23699] at com.gigaspaces.events.SingleNotifyExecutor.execute(SingleNotifyExecutor.java:26) [gsc][1/23699] at com.j_spaces.core.Notifier.execute(Notifier.java:145) [gsc][1/23699] at com.j_spaces.core.server.processor.RemoteEventBusPacket.execute(RemoteEventBusPacket.java:106) [gsc][1/23699] at com.j_spaces.core.Notifier.dispatch(Notifier.java:69) [gsc][1/23699] at com.j_spaces.core.Notifier.dispatch(Notifier.java:33) [gsc][1/23699] at com.j_spaces.kernel.WorkingGroup$TaskWrapper.run(WorkingGroup.java:60) [gsc][1/23699] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [gsc][1/23699] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [gsc][1/23699] at java.lang.Thread.run(Thread.java:619) [gsc][1/23699] Caused by: java.lang.ClassCastException: com.mycompany.Clazz2 cannot be cast to com.mycompany.Clazz1 [gsc][1/23699] at com.mycompany.MyClassGigaspacesMethodinternalInvoke0.internalInvoke(Unknown Source) [gsc][1/23699] at com.gigaspaces.internal.reflection.fast.AbstractMethod.invoke(AbstractMethod.java:34) [gsc][1/23699] at org.openspaces.events.adapter.AbstractReflectionEventListenerAdapter.onEventWithResult(AbstractReflectionEventListenerAdapter.java:173) [gsc][1/23699] ... 17 more

I thought that MyClass would be notified only when classes of type Clazz1 are written to the space. I intend to have another container listening for objects of type Clazz2.

Am I way off-track?

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=3619]{quote}

asked 2011-03-31 13:14:23 -0500

updated 2013-08-08 09:52:00 -0500

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

I would advise not to the use the performTakeOnNotify. If you need to perform a take when a matching object is written into the space use the polling container.

When using this option the take operation might use non-indexed fields as part of the template object. If you would like to avoid this make sure all your Space class fields are indexed. Special care should be given to non-primitive fields (such as collections and user defined classes) to have their hashcode and equales methods implemented. This will make sure the matching of the template with the relevant object within the space will work correctly.

If your template is a Clazz1 type you might have Clazz1 or any other class that is a sub-class of Clazz1 passed into the process method.
See more:
http://www.gigaspaces.com/wiki/display/XAP8/TheGigaSpaceInterface#TheGigaSpaceInterface-TemplateMatching

Shay

answered 2011-03-31 14:29:17 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Comments

I removed the qualification to the @Notify annotation (it just says, "@Notify" now) - same results. I wanted notification vs. polling because it's very important to reduce latency in this execution path as much as possible. The behavior I am trying to create is that each object of type Clazz1 written to the space is processed by this method exactly once as quickly as possible.

The sample class listed above is complete: there is no template method at all. My reading of the documentation ( http://www.gigaspaces.com/wiki/displa... ) suggests to me that @SpaceDataEvent is sufficient. Is this correct? This would be my preferred approach.

If not, and I should implement an @EventTemplate, there is no particular attribute on the object that suggests whether it's been processed or not yet. Is it necessary to add one or is there an @EventTemplate implementation that could be suggested that would match on the type? Matching on Clazz1 or any subclass would be fine. Clearly, if I'm seeing a ClassCastException, Clazz2 is not a subclass of Clazz1. I'm trying to understand why a Clazz2 would be passed to this method at all.

cduplantis gravatar imagecduplantis ( 2011-03-31 14:44:37 -0500 )edit
  1. You need to specify an event template of the clazz1 class, other wise the container is listening for all object types (it registers with object template). i.e have @EventTemplate clazz1 getTemplate(){ return new clazz1; }

  2. In terms of latency polling container is a faster choice if you are doing perform take on notify, because now there are two operations in order to get the event instead of one, first a notification then a take operation. the polling container only performs take operations.

The above is true for a colocated event container (embedded space), if it is a remote space then the scenario may be different.

Eitan

eitany gravatar imageeitany ( 2011-03-31 15:01:26 -0500 )edit

Got it, thanks.

cduplantis gravatar imagecduplantis ( 2011-03-31 15:07:03 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2011-03-31 13:14:23 -0500

Seen: 274 times

Last updated: Mar 31 '11