Predicates and IMap.entrySet()

88 views
Skip to first unread message

Thomas Hallgren

unread,
Jan 27, 2012, 3:04:47 AM1/27/12
to haze...@googlegroups.com
Hi,

I have a situation where I need to trust that the data that a Predicate used for filtering is the same data as I get
when I peruse the returned entry set.

Let's assume that I have a Predicate with an apply() method like:

public boolean apply(MapEntry<String, String> entry) {
return "some value".equals(entry.getValue());
}


and that I use the predicate in a for loop like so:

for(Map.Entry<String,String> entry : myMap.entrySet(myPredicate)) {
String value = entry.getValue();
...
}

What happens if some other thread or process is changing the value for a particular key sometime between the call to
predicate.apply() and when I obtain value for that key in the for loop? Will the value then be changed or is it somehow
guaranteed that the entrySet() returns the same entry unmodified?

- thomas

Fuad Malikov

unread,
Feb 22, 2012, 6:45:20 AM2/22/12
to haze...@googlegroups.com
Hi Thomas, 

Hazelcast can not guarantee it at the moment. It would be very costly to guarantee such a thing and would make queries a lot useless. Instead upon receiving you can apply the predicate yourself for double checking. 

-fuad






- thomas

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.


Thomas Hallgren

unread,
Feb 22, 2012, 7:01:27 AM2/22/12
to haze...@googlegroups.com
On 2012-02-22 12:45, Fuad Malikov wrote:
Hi Thomas, 

Hazelcast can not guarantee it at the moment. It would be very costly to guarantee such a thing and would make queries a lot useless. Instead upon receiving you can apply the predicate yourself for double checking. 

OK, thanks. Good to know.

- thomas


-fuad




On Fri, Jan 27, 2012 at 10:04 AM, Thomas Hallgren <tho...@tada.se> wrote:
Hi,

I have a situation where I need to trust that the data that a Predicate used for filtering is the same data as I get when I peruse the returned entry set.

Let's assume that I have a Predicate with an apply() method like:

 public boolean apply(MapEntry<String, String> entry) {
     return "some value".equals(entry.getValue());
 }


and that I use the predicate in a for loop like so:

 for(Map.Entry<String,String> entry : myMap.entrySet(myPredicate)) {
     String value = entry.getValue();
     ...
 }

What happens if some other thread or process is changing the value for a particular key sometime between the call to predicate.apply() and when I obtain value for that key in the for loop? Will the value then be changed or is it somehow guaranteed that the entrySet() returns the same entry unmodified?


- thomas

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages