take vs. takeIfExists

View: New views
5 Messages — Rating Filter:   Alert me  

take vs. takeIfExists

by Asaf Lahav-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

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 listserv@...

Re: take vs. takeIfExists

by Richard Dallaway-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 18 Nov 2008, at 08:24, Asaf Lahav wrote:
> 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);

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 listserv@...

Re: take vs. takeIfExists

by John McClain - Sun Microsystems, Inc. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Asaf Lahav wrote:

>
> 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…
>
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 listserv@...

Re: take vs. takeIfExists

by John McClain - Sun Microsystems, Inc. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Richard Dallaway wrote:

> On 18 Nov 2008, at 08:24, Asaf Lahav wrote:
>> 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);
>
> 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 listserv@...

Re: take vs. takeIfExists

by Richard Dallaway-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 18 Nov 2008, at 14:35, John McClain wrote:
> Richard Dallaway wrote:
>> [...] 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.

> [...]
>
> 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 listserv@...