Class Cache


  • public abstract class Cache
    extends java.lang.Object
    This class implements a cache for rendered data. The typical usage is:
    
    
     Properties props = new Properties();
     props.put( "report", "report1.rpt" );
     props.put( "prompt0", "abc" );
    
     Cache cache = Cache.getCache();
     ReportCacheKey key = cache.getKey(props);
     cache.getPageAndWait( key, 12, 5 * 60 * 1000 );
    
     
    Since:
    4.0
    • Field Detail

      • TYPE_MEMORY

        public static final int TYPE_MEMORY
        Use memory as cache medium (default cache type).
        Since:
        6.0
        See Also:
        Constant Field Values
      • TYPE_DATABASE

        public static final int TYPE_DATABASE
        Use a database as cache medium. (i-net Clear Reports Plus only).
        Since:
        6.0
        See Also:
        Constant Field Values
      • TYPE_HARDDISK

        public static final int TYPE_HARDDISK
        Use harddisk as cache medium. (i-net Clear Reports Plus only).
        Since:
        6.0
        See Also:
        Constant Field Values
    • Constructor Detail

      • Cache

        protected Cache()
        package Constructor
        Since:
        4.0
    • Method Detail

      • getCache

        public static Cache getCache()
        Returns the singleton Cache instance.
        Returns:
        the current Cache
        Since:
        4.0
      • shutdown

        public static void shutdown()
        FOR INTERNAL USE ONLY Shuts down the started cache and writer Threads.
      • setEngineFactory

        public static void setEngineFactory​(EngineFactory engineFactory)
        You can override the default EngineFactory. An EngineFactory you can use if you want to create or modify the Engine via RDC at runtime. The default implementation is loading a template from a *.rpt file.
        Parameters:
        engineFactory - the EngineFactory to set.
        Throws:
        java.lang.IllegalArgumentException - If the supplied EngineFactory is null.
        Since:
        4.0
        See Also:
        EngineFactory, getEngineFactory()
      • getPropertiesChecker

        public static PropertiesChecker getPropertiesChecker()
        Get the current PropertiesChecker.
        Returns:
        the PropertiesChecker currently set for the cache.
        Since:
        17.0
        See Also:
        PropertiesChecker
      • getKey

        public ReportCacheKey getKey​(java.util.Properties props)
                              throws ReportException
        Create a ReportCacheKey and start rendering if report does not exist in the Cache. The Cache needs the ReportCacheKey to find the report in the Cache. If you are using the default EngineFactory, every property in Properties is used to make the ReportCacheKey. The default EngineFactory needs the parameter "report". To render the report in a special format e.g. "pdf", set the "export_fmt" property. The supported output formats are listed in the class Engine. Internal work:
        • call EngineFactory.getKey(Properties)
        • search whether the key exists in the cache
        • if it does not exist then call EngineFactory.createEngine(Properties) and start rendering
        Parameters:
        props - The default Engine Factory need the parameter "report"
        Returns:
        a unique key for the report
        Throws:
        ReportException - e.g. if the reportfile does not exist
        Since:
        4.0
        See Also:
        setEngineFactory(EngineFactory), EngineFactory, ReportCacheKey, Engine
      • getKey

        public ReportCacheKey getKey​(java.util.Properties props,
                                     PropertiesChecker checker,
                                     java.lang.Object req)
                              throws ReportException
        Create a ReportCacheKey and start rendering if report does not exist in the Cache. The Cache needs the ReportCacheKey, to find the report in the Cache. If you are using the default EngineFactory, every property in Properties is used to make the ReportCacheKey. The default EngineFactory needs the parameter "report". To render the report in a special format e.g. "pdf", set the "export_fmt" property. The supported output formats are listed in the class Engine. Internal work:
        • call PropertiesChecker.checkProperties(Properties, Object)
        • create ReportCacheKey with EngineFactory.getKey(Properties)
        • check if the key exists in the cache
        • if it does not exist then call EngineFactory.createEngine(Properties)
        • call PropertiesChecker.checkProperties(Engine, Properties, Object)
        • start rendering
        Parameters:
        props - The default Engine Factory needs the parameter "report"
        checker - an implementation of PropertiesChecker for validate the Properties. Can be null.
        req - The HTTP servlet request, either null or HttpServletRequest
        Returns:
        a unique key for the report
        Throws:
        ReportException - e.g. if the reportfile does not exist
        Since:
        4.0
        See Also:
        setEngineFactory(EngineFactory), EngineFactory, ReportCacheKey, PropertiesChecker
      • getKey

        public abstract ReportCacheKey getKey​(java.util.Properties props,
                                              PropertiesChecker checker,
                                              EngineFactory factory,
                                              java.lang.Object req)
                                       throws ReportException
        Create a ReportCacheKey and start rendering if report does not exist in the Cache. The Cache needs the ReportCacheKey, to find the report in the Cache. If you are using the default EngineFactory, every property in Properties is used to make the ReportCacheKey. The default EngineFactory needs the parameter "report". To render the report in a special format e.g. "pdf", set the "export_fmt" property. The supported output formats are listed in the class Engine. Internal work:
        • call PropertiesChecker.checkProperties(Properties, Object)
        • create ReportCacheKey with EngineFactory.getKey(Properties)
        • check if the key exists in the cache
        • if it does not exist then call EngineFactory.createEngine(Properties)
        • call PropertiesChecker.checkProperties(Engine, Properties, Object)
        • start rendering
        This method allows you to provide your own EngineFactory instance to be used instead of the system-wide instance set in setEngineFactory(EngineFactory).
        Parameters:
        props - The default Engine Factory needs the parameter "report"
        checker - an implementation of PropertiesChecker for validate the Properties. Can be null.
        factory - EngineFactory instance to use instead of the system-wide one set in setEngineFactory(EngineFactory).
        req - The HTTP servlet request, either null or HttpServletRequest
        Returns:
        a unique key for the report
        Throws:
        ReportException - e.g. if the reportfile does not exist
        Since:
        9.2
        See Also:
        setEngineFactory(EngineFactory), EngineFactory, ReportCacheKey, PropertiesChecker
      • getPageAndWait

        public final byte[] getPageAndWait​(ReportCacheKey key,
                                           int page)
                                    throws PageOutOfRangeException,
                                           KeyNotFoundException,
                                           ReportException
        The method returns the binary data of pages of a report. Set the ReportCacheKey to define the report from that the data have to received ans set the page number to specify the page. How many pages a report has depends on the report and on the export format. The first page has index 1. The last page is the value return form getPageCountAndWait(ReportCacheKey, int)
        If the page is not available yet then this method will wait until the page is available.

        If executing the report failed because of an fatal error, this method will return a serialized Exception Object. The method Cache.isFailedReport(ReportCacheKey) will give the information whether report execution failed
        Parameters:
        key - the unique key to find the report in the Cache
        page - the page number of the page, from which the binary data are returned. The first page has page number 1.
        Returns:
        the binary data for the Java Report Viewer or the bytes of the exported file (page). In case of a failed report the binary data contain a serialized Exception Object.
        Throws:
        PageOutOfRangeException - If the page is out of range after the report is finish rendered.
        KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
        ReportException - e.g. if using DBCache and something went wrong with database connection
        Since:
        4.0
        See Also:
        getKey(Properties), getKey(Properties, PropertiesChecker, Object), getPageAndWait(ReportCacheKey, int, int), isFailedReport(ReportCacheKey)
      • getPageAndWait

        public abstract byte[] getPageAndWait​(ReportCacheKey key,
                                              int page,
                                              int timeout)
                                       throws PageOutOfRangeException,
                                              KeyNotFoundException,
                                              ReportException
        The method returns the binary data of pages of a report. Set the ReportCacheKey to define the report from that the data have to received ans set the page number to specify the page. How many pages a report has depends on the report and on the export format. The first page has index 1. The last page is the value return form getPageCountAndWait(ReportCacheKey, int)
        If the page is not available yet then this method will wait until the page is available.

        If executing the report failed because of an fatal error, this method will return a serialized Exception Object. The method Cache.isFailedReport(ReportCacheKey) will give the information whether report execution failed
        Parameters:
        key - the unique key to find the report in the Cache
        page - the page number of the page, from which the binary data are returned. The first page has page number 1.
        timeout - the maximum time that is wait in milli seconds, 0 means unlimited wait.
        Returns:
        the binary data for the Java Report Viewer or the bytes of the exported file (page). In case of a failed report the binary data contain a serialized Exception Object.
        Throws:
        PageOutOfRangeException - If the page is out of range after the report is finish rendered.
        KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
        ReportException - e.g. if using DBCache and something went wrong with database connection
        Since:
        9.0
        See Also:
        getKey(Properties), getKey(Properties, PropertiesChecker, Object), isFailedReport(ReportCacheKey)
      • getGroupTreeAndWait

        public final byte[] getGroupTreeAndWait​(ReportCacheKey key,
                                                int groupNumber,
                                                int requestType)
                                         throws KeyNotFoundException,
                                                ReportException
        FOR INTERNAL USE ONLY Returns the group tree which can be send to the java viewer bean. The type can either be 2 or 3 and should correspond to the viewer parameter requestType=<requestType>. The value 2 is a request for an individual node where requestID describes the position of the node, value 3 is a request for the whole group tree. For the root of the tree specify a requestID -1.
        Parameters:
        key - the key for that the grooup tree info is requested
        groupNumber - -1 for complete group tree data.
        requestType - 2 or 3
        Returns:
        a bytearray of the group tree info
        Throws:
        KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
        ReportException - e.g. if using DBCache and something went wrong with database connection
        Since:
        4.0
      • getGroupTreeAndWait

        public byte[] getGroupTreeAndWait​(ReportCacheKey key,
                                          int groupNumber,
                                          int requestType,
                                          int timeout)
                                   throws KeyNotFoundException,
                                          ReportException
        FOR INTERNAL USE ONLY Returns the group tree which can be send to the java viewer bean. The type can either be 2 or 3 and should correspond to the viewer parameter requestType=<requestType>. The value 2 is a request for an individual node where requestID describes the position of the node, value 3 is a request for the whole group tree. For the root of the tree specify a requestID -1.
        Parameters:
        key - the key for that the grooup tree info is requested
        groupNumber - -1 for complete group tree data.
        requestType - 2 or 3
        timeout - the maximum time that is wait in milli seconds, 0 means unlimited wait.
        Returns:
        a bytearray of the group tree info
        Throws:
        KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
        ReportException - e.g. if using DBCache and something went wrong with database connection
        Since:
        9.0
      • getPageCountAndWait

        public final int getPageCountAndWait​(ReportCacheKey key)
                                      throws KeyNotFoundException,
                                             ReportException
        Returns the total count of pages and blocks until the rendering is finished.
        Parameters:
        key - the key of the report
        Returns:
        the numbers of pages of a report
        Throws:
        KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
        ReportException - e.g. if using DBCache and something went wrong with database connection
        Since:
        4.0
        See Also:
        getPageAndWait(ReportCacheKey, int, int)
      • getPageCountAndWait

        public abstract int getPageCountAndWait​(ReportCacheKey key,
                                                int timeout)
                                         throws KeyNotFoundException,
                                                ReportException
        Returns the total count of pages and blocks until the rendering is finished.
        Parameters:
        key - the key of the report
        timeout - the maximum time that is wait in milli seconds, 0 means unlimited wait.
        Returns:
        the numbers of pages of a report
        Throws:
        KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
        ReportException - e.g. if using DBCache and something went wrong with database connection
        Since:
        9.0
        See Also:
        getPageAndWait(ReportCacheKey, int, int)
      • getTotalPageSizeAndWait

        public abstract int getTotalPageSizeAndWait​(ReportCacheKey key,
                                                    int timeout)
                                             throws KeyNotFoundException,
                                                    ReportException
        Returns the total size of all pages in bytes and blocks until the rendering is finished.
        Parameters:
        key - the key of the report
        timeout - the maximum time that is wait in milli seconds, 0 means unlimited wait.
        Returns:
        the size of all pages from the report together
        Throws:
        KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
        ReportException - e.g. if using DBCache and something went wrong with database connection
        Since:
        9.0
        See Also:
        getPageAndWait(ReportCacheKey, int, int), getPageCountAndWait(ReportCacheKey,int)
      • isPageLimitExceeded

        public abstract boolean isPageLimitExceeded​(ReportCacheKey key)
                                             throws KeyNotFoundException,
                                                    ReportException
        Check if the rendering of the report ran into a page limit. This means does not all possible pages exist.
        Parameters:
        key - the key of the report
        Returns:
        true, if there is a limit and the report is finish
        Throws:
        KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
        ReportException - e.g. if using DBCache and something went wrong with database connection
        Since:
        10.0
      • lock

        public abstract void lock​(ReportCacheKey key)
                           throws KeyNotFoundException,
                                  ReportException
        Lock the data in the cache and prevent it from modification. This is required if you stream a document like *.pdf in multiple parts.
        Parameters:
        key - the key of the report
        Throws:
        KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
        ReportException - e.g. if using DBCache and something went wrong with database connection
        Since:
        4.0
        See Also:
        unlock(ReportCacheKey)
      • clear

        public abstract void clear()
                            throws ReportException
        Removes all of the entries from this cache. The cache will be empty after this call returns.
        Throws:
        ReportException - - e.g. if using DBCache and something went wrong with database connection
        Since:
        15.1
      • addEngine

        public abstract void addEngine​(Engine engine,
                                       ReportCacheKey key)
                                throws ReportException
        Save a rendered Engine in the cache. This method can be used if you have created an Engine outside of the cache. A typical use is:
        
         Cache cache = Cache.getCache();
         ReportCacheKey key = cache.createKey(props);
        
         if(!cache.exists(key)){
           Engine engine = new Engine( Engine.NO_EXPORT );
           engine.setReportName( props.get( "report" );
           engine.execute();
           cache.addEngine( engine, key );
         }
        
         cache.getPageAndWait( key, 12 );
         
        Parameters:
        engine - the executed engine
        key - the key created for that report
        Throws:
        ReportException - e.g. if there already exists a report in the cache for the key. Possible solution is to call Cache.createKey() with an additional Property or call Cache.delete() with reportname.
        Since:
        4.0
      • createKey

        public ReportCacheKey createKey​(java.util.Properties props,
                                        PropertiesChecker checker,
                                        java.lang.Object req)
                                 throws ReportException
        This method is calling the method getKey() of the current EngineFactory only. It is not starting a render job. If the property "cache.clearOnRequest" is true, the cache will be cleared first.
        Parameters:
        props - Properties for the report
        checker - an implementation of PropertiesChecker for validate the Properties. Can be null.
        req - The HTTP servlet request, either null or HttpServletRequest
        Returns:
        the created key to use with the cache
        Throws:
        ReportException - If an error occurred while checking the supplied properties by the PropertiesChecker or while creating the key in the EngineFactory of the cache.
        Since:
        7.0
        See Also:
        getKey(Properties, PropertiesChecker, Object), EngineFactory
      • delete

        public abstract void delete​(java.lang.String report)
                             throws ReportException
        Delete all reports with the name from the cache. If one or more of the reports are locked the method will not return until it has deleted all of the reports. The deletion will be done sequentially, with no guaranteed ordering.
        Parameters:
        report - name of the report
        Throws:
        ReportException - e.g. if using DBCache and something went wrong with database connection
        Since:
        6.0
      • containsInRAM

        @Deprecated
        public abstract boolean containsInRAM​(ReportCacheKey key)
        Deprecated.
        As of i-net Clear Reports 16.1
        FOR INTERNAL USE ONLY
      • getMemoryUsage

        public abstract int getMemoryUsage​(ReportCacheKey key)
        Get the size a report uses in memory.
        Parameters:
        key - the report key
        Returns:
        size in bytes, zero if not in memory.
        Since:
        i-net Clear Reports 14.0
      • getSwapSize

        public abstract long getSwapSize​(ReportCacheKey key)
        Get the memory size a report uses on an external cache media.
        Parameters:
        key - the report key
        Returns:
        size in bytes, zero if only in memory.
        Since:
        i-net Clear Reports 16.3
      • getSwapSize

        public abstract long getSwapSize()
        Get the total amount of bytes used on an external cache media.
        Returns:
        size in bytes, zero if only in memory.
        Since:
        i-net Clear Reports 16.3
      • getReports

        public abstract ReportCacheKey[] getReports()
                                             throws ReportException
        Returns all reports that are currently listed in the Cache.
        Returns:
        all reports that are currently listed in the Cache.
        Throws:
        ReportException - If an error has occurred during cache request
        Since:
        6.0
      • isFinishWrittenToStore

        @Deprecated
        public abstract boolean isFinishWrittenToStore​(ReportCacheKey key)
                                                throws ReportException,
                                                       KeyNotFoundException
        Deprecated.
        As of i-net Clear Reports 16.1
        Asserts, whether the report is completly written into the store of the cache or not.
        This method is only relevant if you're using DatabaseCache or Harddiskcache. The MemoryCache
        does not have a store.
        It's only necessary to wait on true if you want to skip your application after writing a report in the cache.
        Parameters:
        key - The ReportCacheKey for the report
        Returns:
        true if the report for that key is completely written into the store or an error occur.
        Throws:
        KeyNotFoundException - will be thrown if no report for that key exists in the cache.
        ReportException - e.g. if using DBCache and something went wrong with database connection
        Since:
        4.0
        See Also:
        isFinished(ReportCacheKey), isFailedReport(ReportCacheKey)
      • isFailedReport

        public abstract boolean isFailedReport​(ReportCacheKey key)
                                        throws ReportException
        Returns whether the report was rendered without errors. Call this method after the report rendering has been finished.
        If report execution failed, you can receive the exception object calling getFailureCause(ReportCacheKey).
        Parameters:
        key - The key belongs to the report.
        Returns:
        If the report was rendered without errors.
        Throws:
        ReportException - If there is no respective report in the cache.
        Since:
        6.0
      • getFailureCause

        public java.lang.Throwable getFailureCause​(ReportCacheKey key)
                                            throws ReportException
        Returns the cause for the failure of the report. This method should be called after the report rendering has been finished. If the report execution failed this will return the cause for the failure. If the report execution finished without any error this will return null.
        Parameters:
        key - The key identifying the report.
        Returns:
        The failure cause of the report execution or null if the report rendered successfully.
        Throws:
        ReportException - If there is no respective report in the cache.
        Since:
        8.0
      • getType

        public abstract int getType()
        Returns the defined Cache type. Possible return values are:
        0 - Memory Cache
        1 - Database Cache
        2 - Harddisk Cache


        The type of cache is defined in the configuration.
        The parameter that define the cache type is cache.type
        Returns:
        the defined Cache type.
        Since:
        6.0
        See Also:
        TYPE_MEMORY, TYPE_DATABASE, TYPE_HARDDISK
      • getMemoryUsage

        public abstract int getMemoryUsage()
        Get the amount of bytes used for cached reports in memory.
        Returns:
        the number of bytes used for cached reports, can be zero.
        Since:
        i-net Clear Reports 14.0
      • resetCacheTimeout

        public abstract void resetCacheTimeout​(ReportCacheKey key)
        Causes the timeout for the entry behind this key to be manually restarted. This method should be used to communicate that the cache entry behind the given key is still needed and should not yet be removed from the cache.

        If there is no entry associated with the given key, this will not restart creation of the entry.

        Parameters:
        key - Key of the entry whose cache timeout is to be reset.
        Since:
        7.0
      • getEngine

        @Nullable
        public abstract ReportGenerator getEngine​(ReportCacheKey key)
        Returns the engine for the specified key in the specified cache if active rendering.
        Parameters:
        key - the key
        Returns:
        the engine or null if not found
        Since:
        16.1