Oliver,
See: http://www.gigaspaces.com/wiki/display/SBP/Unit+Of+Work You can use our community edition for free. Shay Hassidim Deputy CTO GigaSpaces -----Original Message----- From: Oliver Plohmann [mailto:[email protected]] Sent: Wednesday, August 18, 2010 6:30 PM To: [email protected] Subject: Entry takeAny(Collection templates, Transaction, timeout) Hello, I need something like a JavaSpaces method with this signature: Entry takeAny(Collection templates, Transaction, timeout); A single entry is returned as soon as any entry written to the space matches one of the templates specified in the invocation of takeAny. The reason I would like to have things this way is that I want to use actors in conjunction with a tuple space. An actor supports a set of functions which are mapped by tuple space templates. Let's say some specific actor must only process messages A, B, and C. At the beginning any of these three messages may be consumed. From that point on the order A->B->C must be kept. So, when activated after startup the actor does a takeAny on A,B, and C. First, by chance, a B is consumed. Because of the execution order, the actor must only consume a C next. For that reason, after B has been processed, the actor does a takeAny with C as the single templates element. This is only a sample scenario to point out that after a message has been consumed by the actor, for the following call of takeAny the collection for the templates parameter must eventually be re-created by the actor. This is what creates the problem. Otherwise, one could use JavaSpaces05.registerForAvailabilityEvent or notify and things would be fine. My question is now how to solve this problem in an appropriate way. My first thought was to call takeIfExists in a loop. But what to do in case every call to takeIfExists in the loop returns null? Then I need to go with JavaSpaces05.registerForAvailabilityEvent. The actor simply ignores the event if it doesn't contain the template of the entry to be processed next. In that case I fear that the system would be flooded with event notifications degrading performance. To use Collection take(Collection tmpls, ...) would not be a good idea, because I would have to re-insert the entries that are not to be processed next. The best solution I have come up with so far is to call notify in a loop for all functions the actor supports when the actor is started. Whenever the specified RemoteEventListener is called, I decide according to the handback object whether the added entry is in the actor's current respondsTo function set. If not the event is ignored and some other actor may consume the entry. Again, I fear this may result in the system being flooded with event notifications creating an avalanche of events that plaster the network. Maybe some of the JavaSpaces professionals out there have a better idea how to do this or might know whether the fear of system performance degradation when using notify is exaggerated. Thanks a lot for any ideas. Cheers, Oliver Plohmann www.objectscape.org -- www.objectscape.org
