6 Replies Latest reply on Apr 27, 2005 10:07 AM by kkalmbach

    overriding LRUAlgorithm

    kkalmbach

      In my tinkering with the LRUAlgorithm, I often find myself wanting to change when a node is evicted (not just by how long it has been idle), but other than that, the LRUAlgorithm is fine. So, here is a small change to the LRU Algorithm I have been using that might be usable by someone else.

      Basically it takes the logic of looking at the idle time on a node and comparing it to the region's timeout and moves that logic into a method called shouldEvictNode. All my algorithms have to do is override "shouldEvictNode (usually calling super.shouldEvictNode), then do whatever other eviction I have set up.

      I hope it is useful to someone else.

      242a243,248
      > protected boolean shouldEvictNode(NodeEntry entry, Region region, long currentTime) {
      > if(region.getTimeToLiveSeconds() == 0) return false; // no time limit
      > long idleTime = currentTime -entry.getModifiedTimeStamp();
      > return (idleTime >= (region.getTimeToLiveSeconds() *1000) );
      > }
      >
      294d299
      < if(region_.getTimeToLiveSeconds() == 0) return; // no time limit
      298,301c303,304
      < Fqn fqn = cursor.getFqn();
      < long idleTime = currentTime -cursor.getModifiedTimeStamp();
      < cursor = cursor.getNext();
      < if(idleTime >= (region_.getTimeToLiveSeconds() *1000) ) {
      ---
      > if(shouldEvictNode(cursor, region_, currentTime)) {
      > Fqn fqn = cursor.getFqn();
      307a311
      > cursor = cursor.getNext();
      


        • 1. Re: overriding LRUAlgorithm
          kkalmbach

          One more thing I did. Most of the Algorithms I use are in our own packages, so methods with pacakge scope are not visable. Since I pass in the NodeEntry to shouldEvictNode, I modified NodeEntry to allow other packages to read some info..

          32c32
          < long getModifiedTimeStamp()
          ---
          > public long getModifiedTimeStamp()
          62c62
          < Fqn getFqn()
          ---
          > public Fqn getFqn()
          



          If these could get merged into the real code, it would help out my modifications a lot.

          -Kevin

          • 2. Re: overriding LRUAlgorithm

            Kevin,

            Let me look at your change once 1.2.1 is out to see if it makes sense.

            Thanks,

            -Ben

            • 3. Re: overriding LRUAlgorithm
              kkalmbach

              Any word yet on getting this these changes in the code?

              Thanks
              -Kevin

              • 4. Re: overriding LRUAlgorithm

                Kevin,

                Sorry that I have dropped the ball. :-)

                I have just applied the patch and check them into the latest JBossCache (note not under jboss-head, though).

                Please allow one day and check them out to verify.

                Thanks,

                -ben

                • 5. Re: overriding LRUAlgorithm
                  kkalmbach

                  Everything looks great. Thanks for doing that.

                  You do anything but "drop the ball". This is probably the most responsive forum I have ever run across. Quick, correct answers, super fast code fixes etc.

                  You guys are the best. Thanks again.
                  -Kevin

                  • 6. Re: overriding LRUAlgorithm
                    kkalmbach

                    I finally got around to looking at the changes you put in and I found one small problem.
                    In NodeEntry.java, you changed the access level from package to public on
                    getModifiedTimeStamp() and
                    setModifiedTimeStamp(long)

                    Can you make getFQN() public as well.

                    I'm not sure right off if the setModifiedTimestamp needs to be public or not, but the 2 get's make sense to me.

                    Thanks again for all your work.
                    -Kevin