Re: take()-s of two associated but distinct entries

Dan Creswell <[email protected]> Fri, 15 Sep 2006 11:43:48 +0100
Newsgroups gmane.comp.java.sun.javaspaces
Message-ID <[email protected]>
Hi,

Nirmalya Sengupta wrote:
> Hello all,
>
> Perhaps, this subject has been discussed before. If so, please point me
> to the thread.
>
> Suppose, there are three processes (could be threads too), interacting
> through a Space. Two of them (A and B) produce Entries,
> and the other (C) consumes the entries. Thorugh the Entries are
> produced by two disconnected producers, there is a close assoication
> betwevn them. Hence, the C need to take() the Entries together
> before using them.
>
> Producers may or may not produce entries (and write() into the space),
> simultaneously. In other words, there could be a discernible time-gap
> between two such write()-s. The Consumer has registered itself
> for notification, for both type of entries. Obviously, there will be a
> time-gap between two notifications that C gets from the Space.
>
> So, A produces an Entry named, AE1 and write()s into the Space. C gets
> the notification. Similarly, when B produces an Entry named, BE1 into
> the Space, C again gets the notification. Now, C has to take AE1
> and BE1.
>
> What should C do?
>
> a) Should C take() them under two different transactions?

That depends on what guarentees you need to maintain in respect of other
clients etc.

> b) Can C take() them under the same transactions? Will the same Txn
> object work across two separate take()-s?
>

This is my preferred option for most cases though it depends on what
other things your client might need to be doing and, as per above, what
other requirements you have for access to state in the space from the
point of view of other "users".

Re: will the same transaction work across two separate takes - that
question is answered in the JavaSpaces spec and the Transaction related
specs - but the simple answer is yes, it will work.

> In a slightly different scenario, let us assume that there are two
> instances of C (C1 and C2) running. A writes entries AE1 and AE2.
> Similarly, B writes entries BE1 and BE2 (don't forget the time-gap).
>
> Now, take() by either C1 or C2 has to happen in associated pairs;
> in other words, whosoever takes AE1, has to take BE1 (ditto for
> AE2 and BE2).
>
> What is the most common (and efficient) pattern to be followed in such a case?
>

Broadly the same solutions for the first case apply to this case but
it's likely you would need to introduce some slightly smarter code to
resolve conflicts.  Essentially you may need to do a bit of deadlock
avoidance but you can potentially get around this by stipulating that
all clients should try and take an "A" before trying to get the
corresponding "B".

> Will wait to hear from you.
>

And now you have ;)

I would like to understand why you are asking about all these
"theoretical cases".  In such circumstances, I would expect you to
determine these answers by reading the relevant specs however I'm
wondering if there's some practical experiment driving these questions
and, if there is, it would be useful to know what it is you're trying to
do as we may be able to provide better answers and maybe better solution
options.

Hope that helps,

Dan.

===========================================================================
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