2 Replies Latest reply on Dec 8, 2010 3:33 PM by Dave Marion

    Filtering results during query or get()

    Dave Marion Newbie

      I am curious as to how I could filter results from the cache at runtime. An example cache entry would be a key that has multiple values associated with it and I only want to return the objects in the list that the caller is allowed to see.


        Cache<String, List<MyObject>> = CacheManager.getCache("myCache");


      I was looking at writing a custom interceptor to do this filtering. Manik suggested using a security context in a ThreadLocal variable in my program before calling cache.get(). I was under the impression that the get() command was sent to every node in the cluster and evaluated on each node. Is this correct, or do the interceptors get invoked on the client side? If server side, then I don't think the ThreadLocal variable would get propogated to the other nodes.


      Looking for any suggestions on how to solve this problem. Thanks...

        • 1. Re: Filtering results during query or get()
          Mircea Markus Master

          Are you using infinispan in client/server mode (e.g. through hotrod) or the client runs in same jvm with the infinispan node it queries?

          If it is local then:

          1. on node A client calls cache.ghet(k). This has security context associated

          2. caller's thread on A retrieves the List<MyObject> from another node B (rpc)

          3. this thread goes through a chain of interceptors. On the way back your custom interceptor filters out the result based on the security association

          4. then returns the result to the user.

          This is sub-optimal: everything is returned to the caller node (i.e. A) which filters out the data. A better approach would be to do the filtering remotlely, but it's not possible for now (ISPN-256  might overcome this limitation)

          Here is some doc in custom interceptors: http://community.jboss.org/wiki/InfinispanCustomInterceptors

          • 2. Re: Filtering results during query or get()
            Dave Marion Newbie

            Ultimately I would like to use client/server mode and have this functionality, but it does not seem to be there yet. So, I think I am forced to have the client run in the same VM as one of the Infinispan cache's in a cluster.


            I read the docs on the CustomInterceptor, it was initially unclear to me where they are executed. I think the problem lies in my understanding that when I run a cache locally in a VM, then I am NOT a client.


            I'll have to play around with it a little I think to understand the relationship between the cache and the client of the cache when in the same VM more. It just came to me that it depends on the local nodes' configuration, when I call cache.get() that the data may be retrieved from another node in the cluster, but the interceptors defined in my node will be executed. Does this mean that you could have several different node configurations working in the same cluster? Interesting...