You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by juanavelez <js...@gmail.com> on 2017/01/03 16:10:49 UTC
JCache and CacheManager.getCache
I am trying to obtain a Cache<Integer, MyObject> using JCache's
CacheManager.getCache("myCache", Integer.class, MyObject.class) but it fails
with a ClassCastException (can't convert from Object to Integer). The cache
is configured in an ignite configuration xml file, but I don't see a way to
set the types for the key and value. How is the correct way to obtain an
existing cache which has been configured using the spring/xml approach by
using the JCache api?
Thanks - J
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/JCache-and-CacheManager-getCache-tp9847.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: JCache and CacheManager.getCache
Posted by vkulichenko <va...@gmail.com>.
You don't need to provide types to get a cache. Just do this:
Cache<Integer, MyObject> cache = cacheManager.getCache("myCache");
-Val
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/JCache-and-CacheManager-getCache-tp9847p9851.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: JCache and CacheManager.getCache
Posted by Juan Velez <js...@gmail.com>.
public class Test {
public static void main(String[] args) throws IOException {
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(new ClassPathResource("ignite-config-simple.xml").getURI(), null);
Cache<Integer, MyObject> cache = cacheManager.getCache("myCache", Integer.class, MyObject.class);
}
}
Exception in thread "main" java.lang.ClassCastException
at org.apache.ignite.cache.CacheManager.getCache(CacheManager.java:203)
at Test.main(Test.java:15)
ignite-config-simple.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="metricsLogFrequency" value="0"/>
<property name="gridLogger">
<bean class="org.apache.ignite.logger.slf4j.Slf4jLogger"/>
</property>
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="myCache"/>
<property name="cacheMode" value="PARTITIONED"/>
<property name="atomicityMode" value="ATOMIC"/>
<property name="backups" value="1"/>
</bean>
</list>
</property>
</bean>
</beans>
> On 03 Jan, 2017, at 9:05 AM, vkulichenko <va...@gmail.com> wrote:
>
> Can you show the trace?
>
> -Val
>
>
>
> --
> View this message in context: http://apache-ignite-users.70518.x6.nabble.com/JCache-and-CacheManager-getCache-tp9847p9848.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: JCache and CacheManager.getCache
Posted by Juan Velez <js...@gmail.com>.
Ok, I see now, yes there is not “getter/setter” for types, so the only way is to programmatically call MutableConfiguration.setTypes().
I will use your suggested approach. Thanks - J
> On 03 Jan, 2017, at 11:33 AM, vkulichenko <va...@gmail.com> wrote:
>
> It is supported if you provide key and value classes in CacheConfiguration,
> but this is possible only in code, not in XML.
>
> -Val
>
>
>
> --
> View this message in context: http://apache-ignite-users.70518.x6.nabble.com/JCache-and-CacheManager-getCache-tp9847p9853.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: JCache and CacheManager.getCache
Posted by vkulichenko <va...@gmail.com>.
It is supported if you provide key and value classes in CacheConfiguration,
but this is possible only in code, not in XML.
-Val
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/JCache-and-CacheManager-getCache-tp9847p9853.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: JCache and CacheManager.getCache
Posted by Juan Velez <js...@gmail.com>.
So the CacheManager.getCache(String, Class<?>, Class<?>) is not supported then?
Thanks - J
> On 03 Jan, 2017, at 9:05 AM, vkulichenko <va...@gmail.com> wrote:
>
> Can you show the trace?
>
> -Val
>
>
>
> --
> View this message in context: http://apache-ignite-users.70518.x6.nabble.com/JCache-and-CacheManager-getCache-tp9847p9848.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: JCache and CacheManager.getCache
Posted by vkulichenko <va...@gmail.com>.
Can you show the trace?
-Val
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/JCache-and-CacheManager-getCache-tp9847p9848.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.