Re: Pattern for One-Entry-Multiple-Workers Problem

Dan Creswell <[email protected]>
Newsgroups gmane.comp.java.sun.javaspaces
Message-ID <[email protected]>
Stefan Schulz wrote:
> Dan Creswell wrote:
>> So, I feel like I must be missing something because it looks to me like
>> you could achieve most of this with registerForAvailabilityEvent.
>>
>> Each worker interested would register for matches and would receive a
>> copy of the Entry in the event.  It could then process the Entry and
>> write back a new Entry.
>
> Yes, that is what I thought. So does a worker receive a copy of the
> entry or does it have to take it (manually) after notification? In the
> first case, this would be fine for my problem, in the second, would the
> space guarantee, which entry the worker gets?

I'm not sure we're working from the same set of assumptions. :(

Your client will only be notified of written Entry's which match the
template it specified when it registered.  At the basic level, you get
one event per match which means one event per write.

The availabilityEvent will have a copy of the Entry that matched,
contained within it (and obtained via getEntry).  For a read-only
scenario this should be sufficient and sounds like it's right for your case.

You would only follow up with a take to do some form of exclusive
processing.  And were you to do this, you're using standard matching
semantics which means you'll get any Entry (or no Entry) that matches
the template you pass (even if you use the Entry passed to you in the
event).

I'm confused as to why you're asking which Entry the worker would get
and why you're thinking you might need a take - still feel like I'm
missing something......

> As far as I understood the API, the event only returns the template
> provided and not the matching entry. Maybe I am wrong :)

I think you understood wrong :)

Checkout the JavaSpace05 and AvailabilityEvent JavaDoc.

>
>> (1)     A worker on startup might need to use contents to check for any
>> work
>> pre-existing in the space prior to registration.
>>
>> (2)     A worker might sometimes want to do contents if it's not seen any
>> events recently to ensure none have been lost.
>
> Yes, when doing a contents, checking and signing an entry becomes easy
> (take it, unmarshall it, test it, eventually process and sign it,
> marshall it, write it back).
>
> Thanks,
> Stefan
>
> ===========================================================================
> To unsubscribe, send email to [email protected] and include in the body
> of the message "signoff JAVASPACES-USERS".  For general help, send email to
> [email protected] and include in the body of the message "help".
>
> To view past JAVASPACES-USERS postings, please see:
> http://archives.java.sun.com/archives/javaspaces-users.html
>
> JDC members can download the JavaSpaces(tm) Technology from:
> http://developer.java.sun.com/developer/products/jini/
>

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff JAVASPACES-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

To view past JAVASPACES-USERS postings, please see:
http://archives.java.sun.com/archives/javaspaces-users.html

JDC members can download the JavaSpaces(tm) Technology from:
http://developer.java.sun.com/developer/products/jini/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.