Search code examples
xpageslotus-domino

What is the least expensive way to test if a View has been recycled?


I have a caching bean that I use to look up/store information about objects in an app. I want to do as few fetching of Views as possible as I would imagine each Database.getView comes at some cost.

What is the least expensive way to trigger "View has been recycled"?


Solution

  • After inspiration from Sven Hasselbach, I created this method:

    /*
    Classes that need to be imported:
    import java.lang.reflect.Method;
    import lotus.domino.Base;
    import lotus.domino.local.NotesBase;
    */
    
    public static boolean isRecycled( Base object ) {
        boolean isRecycled = true;
        if( ! ( object instanceof NotesBase ) ) { 
            // No reason to test non-NotesBase objects -> isRecycled = true
            return isRecycled;
        }
    
        try {
            NotesBase notesObject = (NotesBase) object;
            Method isDead = notesObject.getClass().getSuperclass().getDeclaredMethod( "isDead" );
            isDead.setAccessible( true );       
    
            isRecycled = (Boolean) isDead.invoke( notesObject );
        } catch ( Throwable exception ) {
            // Exception handling
        }
    
        return isRecycled;
    }
    

    Update: It seems using this method requires changes to java.policy. Specifically this line: notesObject.getClass().getSuperclass().getDeclaredMethod( "isDead" )