ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Denis Magda <dma...@gridgain.com>
Subject Re: How to filter the CacheInterceptor for a certain cacheefficiently?
Date Mon, 09 Nov 2015 13:55:12 GMT
Hi Lin Lyu,

CacheInterceptor as many other parameters passed via CacheConfiguration 
is not supposed to be changed when a cache has already been created.

So once set the interceptor will be used till the cache is destroyed.

I highly recommend not to change the interceptor through the private API 
even if it works. It may lead to other issues that can happen here or 
there in runtime or the API can be changed at any time.

Regards,
Denis

On 11/9/2015 3:35 PM, Me wrote:
> Hi,
> I found that I can access the real CacheConfiguration object with a conversatation from
IgniteCache to IgniteCacheProxy.
> But is there any more graceful and less intrusive way to do the same thing?
> public void testForInterpectorModifyDynamically()throws Exception {
>      IgniteCache<Integer, Person> cache =ignite1.getOrCreateCache(cache_name);
> *// convert the cache object to IgniteCaceProxy and modify the config 
> in its context...*
> *((IgniteCacheProxy) cache).context().config().setInterceptor(new 
> PersonalInterceptor(1));*
>      cache.put(1,new Person("Lin","Lyu"));
>      System.out.println(cache.get(1));
>      assertEquals("LYU", cache.get(1).getLastName());
> }
> Regards,
> Lin Lyu
>
> ------------------ Original ------------------
> *From: * "Me";<me@linlyu.com>;
> *Date: * Mon, Nov 9, 2015 07:21 PM
> *To: * "user-ignite"<user@ignite.apache.org>;
> *Subject: * Re: How to filter the CacheInterceptor for a certain 
> cacheefficiently?
>
> Hi Val,
>
> Thank you for your nice reply. It works when I am creating one cache 
> with a certain CacheConfiguration with interceptor, But I don't know 
> how to changed the interceptor when the cache object is created.
>
> PS: here is the code on creating a cache with interceptor.
> public void testInterceptorWithConfigOnCreate()throws Exception {
>   CacheConfiguration cfg =new CacheConfiguration();cfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);//
required, but ATOMIC cfg.setName(cache_name);
>      cfg.setInterceptor(new PersonalInterceptor(1));// combined with given interceptor
ignite1.createCache(cfg);// create this cache with given name and interceptor.
> // NOTICE, the cfg will be cloned in the createCache/getOrCreateCache
> final IgniteCache<Integer, Person> cache =ignite1.cache(cache_name);
>      Person p =new Person("Jason","Green");
>      cache.put(1,p);
>      Person out = cache.get(1);
>      assertEquals(p.getLastName().toUpperCase(), out.getLastName());
> }
> As I known, the CacheConfiguration object in the cache object is 
> different from what I created, and I haven't found the right way to 
> update the interceptor dynamically.
> I have read some codes like 
> org/apache/ignite/internal/processors/cache/GridCacheOnCopyFlagAbstractSelfTest.java,

> I think the method */used only in test 
> cases/*org.apache.ignite.testframework.junits.GridAbstractTest#getConfiguration(java.lang.String)

> was hacked in 
> org.apache.ignite.internal.processors.cache.GridCacheOnCopyFlagAbstractSelfTest#cacheConfiguration,

> so the instance of CacheConfigurations are the same object.
> But I have no idea how to do this in a real production environment.
> Hopes for you reply.
> Thanks again.
> Regards,
> Lin Lyu.
>
>
> ------------------ Original ------------------
> *From: * "vkulichenko";<valentin.kulichenko@gmail.com>;
> *Date: * Sat, Nov 7, 2015 09:55 AM
> *To: * "user"<user@ignite.apache.org>;
> *Subject: * Re: How to filter the CacheInterceptor for a certain 
> cacheefficiently?
>
> Hi Lin Lyu,
>
> Cahe interceptor is configured per cache (see
> CacheConfiguration.setInterceptor() configuration property). So you don't
> need to do any additional filtering, just set this configuration only for
> one cache.
>
> -Val
>
>
>
> --
> View this message in context: 
> http://apache-ignite-users.70518.x6.nabble.com/How-to-filter-the-CacheInterceptor-for-a-certain-cache-efficiently-tp1864p1878.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.


Mime
View raw message