You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geode.apache.org by Paul Perez <pa...@pymma.com> on 2020/08/20 21:36:31 UTC
Region containsKey and containsKeyOnServer
Hello All,
Region implements two similar methods containsKey and containsKeyOnServer.
We implement a cache client with a client-cache.xml
<?xml version="1.0" encoding="UTF-8"?>
<client-cache xmlns=http://geode.apache.org/schema/cache
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://geode.apache.org/schema/cache
http://geode.apache.org/schema/cache/cache-1.0.xsd"
version="1.0">
<pool name="client-pool" subscription-enabled="true">
<locator host="localhost" port="10334"/>
</pool>
<region name="myremoteregion" refid="PROXY"/>
<region name="mylocalregion" refid="LOCAL"/>
</client-cache>
If we use the method containsKey with the region myremoteregion, we get a
null value and we must use the method containsKeyOnServer.
On the other side if we use containsKeyOnServer with a local region we get
the exception UnsupportedOperationException
<https://docs.oracle.com/javase/8/docs/api/java/lang/UnsupportedOperationExc
eption.html?is-external=true>
So it is important to determine if a region is local or proxi.
I would like to get such code
boolean containsKey;
if (my region is proxy) {
containsKey = region.containsKeyOnServer(key);
} else {
containsKey = region.containsKey(key);
}
Question: Does someone know how can we find out if a region is proxy.
Thank you for your help
Best regards
Paul Perez Chief Architect
Pymma Consulting
--------------------------
Tel: +44 79 44 36 04 65
Skype ID : polperez
RE: Region containsKey and containsKeyOnServer
Posted by Paul Perez <pa...@pymma.com>.
Hello Alberto
Thank you for your support and sorry for the delay to reply to you.
I focused on another project this week.
I'll implement your advice and come back to you.
One again thank you.
Best regards
Paul Perez Chief Architect
Pymma Consulting
--------------------------
Tel: +44 79 44 36 04 65
Skype ID : polperez
From: Alberto Bustamante Reyes <al...@est.tech>
Sent: 21 August 2020 10:46
To: user@geode.apache.org; paul.perez@pymma.com
Subject: RE: Region containsKey and containsKeyOnServer
Hi Paul,
Im not sure if there is a better way, but if you call
"region.getAttributes().getDataPolicy();" on a PROXY region, it will return
"DataPolicy.EMPTY".
I have seen in GemFireCacheImpl.initializeClientRegionShortcuts method that
PROXY is the only region shortcut that uses that DataPolicy, so you could
use this to distinguish this kind of regions.
There is always the risk of a new region shortcut is added that uses the
same data policy (there is no a 1:1 mapping between region shortcuts and
data policy values), but I suppose its minimum.
Other option is to catch the UnsupportedOperationException, and call
containsKey in that case.
BR/
Alberto B.
_____
De: Paul Perez <paul.perez@pymma.com <ma...@pymma.com> >
Enviado: jueves, 20 de agosto de 2020 23:36
Para: user@geode.apache.org <ma...@geode.apache.org>
<user@geode.apache.org <ma...@geode.apache.org> >
Asunto: Region containsKey and containsKeyOnServer
Hello All,
Region implements two similar methods containsKey and containsKeyOnServer.
We implement a cache client with a client-cache.xml
<?xml version="1.0" encoding="UTF-8"?>
<client-cache xmlns=http://geode.apache.org/schema/cache
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://geode.apache.org/schema/cache
http://geode.apache.org/schema/cache/cache-1.0.xsd
<http://geode.apache.org/schema/cache%20http:/geode.apache.org/schema/cache/
cache-1.0.xsd> "
version="1.0">
<pool name="client-pool" subscription-enabled="true">
<locator host="localhost" port="10334"/>
</pool>
<region name="myremoteregion" refid="PROXY"/>
<region name="mylocalregion" refid="LOCAL"/>
</client-cache>
If we use the method containsKey with the region myremoteregion, we get a
null value and we must use the method containsKeyOnServer.
On the other side if we use containsKeyOnServer with a local region we get
the exception UnsupportedOperationException
<https://docs.oracle.com/javase/8/docs/api/java/lang/UnsupportedOperationExc
eption.html?is-external=true>
So it is important to determine if a region is local or proxi.
I would like to get such code
boolean containsKey;
if (my region is proxy) {
containsKey = region.containsKeyOnServer(key);
} else {
containsKey = region.containsKey(key);
}
Question: Does someone know how can we find out if a region is proxy.
Thank you for your help
Best regards
Paul Perez Chief Architect
Pymma Consulting
--------------------------
Tel: +44 79 44 36 04 65
Skype ID : polperez
RE: Region containsKey and containsKeyOnServer
Posted by Alberto Bustamante Reyes <al...@est.tech>.
Hi Paul,
Im not sure if there is a better way, but if you call "region.getAttributes().getDataPolicy();" on a PROXY region, it will return "DataPolicy.EMPTY".
I have seen in GemFireCacheImpl.initializeClientRegionShortcuts method that PROXY is the only region shortcut that uses that DataPolicy, so you could use this to distinguish this kind of regions.
There is always the risk of a new region shortcut is added that uses the same data policy (there is no a 1:1 mapping between region shortcuts and data policy values), but I suppose its minimum.
Other option is to catch the UnsupportedOperationException, and call containsKey in that case.
BR/
Alberto B.
________________________________
De: Paul Perez <pa...@pymma.com>
Enviado: jueves, 20 de agosto de 2020 23:36
Para: user@geode.apache.org <us...@geode.apache.org>
Asunto: Region containsKey and containsKeyOnServer
Hello All,
Region implements two similar methods containsKey and containsKeyOnServer.
We implement a cache client with a client-cache.xml
<?xml version="1.0" encoding="UTF-8"?>
<client-cache xmlns=http://geode.apache.org/schema/cache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd"
version="1.0">
<pool name="client-pool" subscription-enabled="true">
<locator host="localhost" port="10334"/>
</pool>
<region name="myremoteregion" refid="PROXY"/>
<region name="mylocalregion" refid="LOCAL"/>
</client-cache>
If we use the method containsKey with the region myremoteregion, we get a null value and we must use the method containsKeyOnServer.
On the other side if we use containsKeyOnServer with a local region we get the exception UnsupportedOperationException<https://docs.oracle.com/javase/8/docs/api/java/lang/UnsupportedOperationException.html?is-external=true>
So it is important to determine if a region is local or proxi.
I would like to get such code
boolean containsKey;
if (my region is proxy) {
containsKey = region.containsKeyOnServer(key);
} else {
containsKey = region.containsKey(key);
}
Question: Does someone know how can we find out if a region is proxy.
Thank you for your help
Best regards
Paul Perez Chief Architect
Pymma Consulting
--------------------------
Tel: +44 79 44 36 04 65
Skype ID : polperez