Discussion:
take vs. takeIfExists
Asaf Lahav
2008-11-18 08:24:46 UTC
Permalink
Hi everybody,

What is the difference between using take vs. takeIfExists in the following
cases:



entry = space.takeIfExists(tmpl, null, 0);

vs.

entry = space.take (tmpl, null, 0);



Thanks in advance.




--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
Unsubscribing: email "signoff JINI-USERS" to ***@java.sun.com
Richard Dallaway
2008-11-18 09:59:22 UTC
Permalink
Post by Asaf Lahav
What is the difference between using take vs. takeIfExists in the
entry = space.takeIfExists(tmpl, null, 0);
vs.
entry = space.take (tmpl, null, 0);
I'd be interested to know the answer too.

My understanding is that it makes no difference unless you're in a
transaction (which of course you're not). From p. 245 of JavaSpaces
Principles, Patterns and Practice I see: "In effect, a readIfExists
is able to 'peak inside' transactions: if a matching entry exists
within a transaction, then readIfExists will wait up until its timeout
value for a transaction to complete before it returns". (surely take
and read will behave the same way in this situation).

But I do wonder if there are some edge cases for an if exists query,
so it'd be good to know.

Richard

--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
Unsubscribing: email "signoff JINI-USERS" to ***@java.sun.com
John McClain
2008-11-18 14:35:29 UTC
Permalink
Post by Richard Dallaway
Post by Asaf Lahav
What is the difference between using take vs. takeIfExists in the
entry = space.takeIfExists(tmpl, null, 0);
vs.
entry = space.take (tmpl, null, 0);
I'd be interested to know the answer too.
My understanding is that it makes no difference unless you're in a
transaction (which of course you're not). From p. 245 of JavaSpaces
Principles, Patterns and Practice I see: "In effect, a readIfExists
is able to 'peak inside' transactions: if a matching entry exists
within a transaction, then readIfExists will wait up until its timeout
value for a transaction to complete before it returns". (surely take
and read will behave the same way in this situation).
It doesn't matter if the query is under a transaction or not - it
matters if the space is a participant in any active transactions.

All queries on a space will return without blocking if there is an
available (available == not locked by an active transaction) entry that
matches.

If there is no available matching entry then read and take will block
for up to their timeout, or until a matching entry becomes available,
which ever comes first.

The ifExists queries will always return immediately (even if the timeout
is non-zero) if there are no matching entires in the space they will
only block if there is an entry in the space that is not available -
that is the entry is locked by a conflicting transaction - in such cases
they will wait for up to the timeout for a matching entry to become
available or until there are no matching entries in the space.

read and talk obey the ACID properties, the ifExists queries break
isolation.

Does that help?

--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
Unsubscribing: email "signoff JINI-USERS" to ***@java.sun.com
Richard Dallaway
2008-11-18 16:00:05 UTC
Permalink
Post by John McClain
[...] My understanding is that it makes no difference unless you're
in a transaction [...]
It doesn't matter if the query is under a transaction or not - it
matters if the space is a participant in any active transactions.
OK, that makes sense. Thank you.
Post by John McClain
[...]
Does that help?
Absolutely. Thanks for taking the time to explain the process so
clearly.

Richard

--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
Unsubscribing: email "signoff JINI-USERS" to ***@java.sun.com
John McClain
2008-11-18 14:16:58 UTC
Permalink
Post by Asaf Lahav
Hi everybody,
What is the difference between using take vs. takeIfExists in the
entry = space.takeIfExists(tmpl, null, 0);
vs.
entry = space.take (tmpl, null, 0);
Thanks in advance…
In this case there is no difference. The difference between a std. query
and an ifExists is how they deal with non-zero timeouts.

--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
Unsubscribing: email "signoff JINI-USERS" to ***@java.sun.com
Loading...