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

Ask Your Question
0

Do polling containers send the same object over and over again?

If I create an @EventTemplate function for a polling container that returns the value null, that will match every object in the space. Let's say I have 10,000 objects in the space. I originally thought that only when each object is first written to the space will my @SpaceDataEvent function be called to process that object. So the @SpaceDataEvent function should be called 10,000 times, and never again. But then I found the function was being called with the 10,000 objects, then again with the 10,000 objects, and again and again. My new understanding of polling containers is that they loop through all the objects in the space repeatedly, and send events for any of the objects that match the template in the @EventTemplate function. So a polling container will loop through all 10,000 objects, see that they match the template, and send them to my @SpaceDataEvent function. Then the polling container will again loop through the 10,000 objects, see that the match the template, and send them again to the @SpaceDataEvent function. This will keep happening until my space is shut down. Is my new understanding of how polling containers work correct? Is there a loop involved that goes through ALL the objects in the space, repeatedly, and checks which ones match the template? Is the only way to process an object in the space one time to put a special field in that object, say a boolean called isProcessed, and specify a value of false in the template, then when the object is processed, set that field to true, so it will not match the template the next time the polling container loops through all the space objects?

asked 2014-06-05 07:50:59 -0500

LexLuthor gravatar image
edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

Are you writing the object back to the space after receiving it? If so, you are adding an object that matches the template you specified, so your event handler will be triggered.

The use of null as your template is unusual. What are you trying to accomplish, at a high level?

answered 2014-06-05 09:56:26 -0500

Patrick gravatar image
edit flag offensive delete link more
0

Both my @EventTemplate and @SpaceDataEvent functions return null, and I perform reads, not takes. So I never write anything back to the space. In a situation like that, what is the behavior of the polling container? If I have 10,000 objects in my space, should the @SpaceDataEvent function be called exactly 10,000 times, or over and over, far exceeding 10,000 times, until I shut down my space? I'm trying to understand how polling works. I'm assuming there is a loop somewhere that, on a periodic basis, goes through all objects in the space, and checks if they match the template. For those that do, it calls the @SpaceDataEvent function. Since this is a loop that goes on forever, I should receive 10,000 calls to my @SpaceDataEvent function every time the loop runs.

Imagine that I have 10,000 stock order objects in my space. One order might be for 100 shares of GOOG. When my @SpaceDataEvent function receives that order, it extracts the symbol "GOOG" from the order, obtains company information about GOOG, then stores it in the space as a CompanyInfo object. If another order is sent to my @SpaceDataEvent function for the same symbol "GOOG", I see that CompanyInfo already exists in the space for that symbol, so I don't bother getting the information again. If the order is for another symbol that is not in the space, then I do get company information for that symbol, and store a CompanyInfo object in the space for it. Once I have processed an order, I don't have to process it again. What I saw was that I kept getting the same orders over and over again, even though I had processed them. My solution was to add a processed field to the order object, and have its initial value be false when the order object is first created. The template specifies a value of false for objects I am interested in. I return this from my @EventTemplate function, and in my @SpaceDataEvent function I set the order's processed field to true, then return that order from the function, which will write it to the space. It won't match the template anymore, so my @SpaceDataEvent function won't receive that order anymore. But I am curious as to whether there is a way to do this without having to add an extra field to my order objects. It seems like there is no way to do it, if polling involves looping and repeatedly going through all objects in the space.

answered 2014-06-05 10:43:33 -0500

LexLuthor gravatar image
edit flag offensive delete link more
0

The first code snippet in this example is preferred. Returning null from a @SpaceDataEvent will have the effect of deleting the object passed to the eventListener.

The algorithm you suggest is not the simplest for an event driven architecture. It relies a bit too heavily upon features of the GigaSpaces implementation that are not strictly guaranteed by the API.

answered 2014-06-09 22:38:17 -0500

jasonnerothin gravatar image

updated 2014-06-09 22:39:17 -0500

edit flag offensive delete link more

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: 2014-06-05 07:50:59 -0500

Seen: 267 times

Last updated: Jun 09 '14