Class TMSCachedTileLoader

  • All Implemented Interfaces:
    org.openstreetmap.gui.jmapviewer.interfaces.CachedTileLoader, org.openstreetmap.gui.jmapviewer.interfaces.TileLoader
    Direct Known Subclasses:
    WMSCachedTileLoader

    public class TMSCachedTileLoader
    extends java.lang.Object
    implements org.openstreetmap.gui.jmapviewer.interfaces.TileLoader, org.openstreetmap.gui.jmapviewer.interfaces.CachedTileLoader
    Wrapper class that bridges between JCS cache and Tile Loaders
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.commons.jcs3.access.behavior.ICacheAccess<java.lang.String,​BufferedImageCacheEntry> cache  
      private static java.util.concurrent.ThreadPoolExecutor DEFAULT_DOWNLOAD_JOB_DISPATCHER
      separate from JCS thread pool for TMS loader, so we can have different thread pools for default JCS and for TMS imagery
      private java.util.concurrent.ThreadPoolExecutor downloadExecutor  
      static IntegerProperty HOST_LIMIT
      Limit definition for per host concurrent connections
      protected org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener listener  
      protected TileJobOptions options  
      static IntegerProperty THREAD_LIMIT
      overrides the THREAD_LIMIT in superclass, as we want to have separate limit and pool for TMS
    • Constructor Summary

      Constructors 
      Constructor Description
      TMSCachedTileLoader​(org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener listener, org.apache.commons.jcs3.access.behavior.ICacheAccess<java.lang.String,​BufferedImageCacheEntry> cache, TileJobOptions options)
      Constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancelOutstandingTasks()
      cancels all outstanding tasks in the queue.
      void clearCache​(org.openstreetmap.gui.jmapviewer.interfaces.TileSource source)  
      org.openstreetmap.gui.jmapviewer.interfaces.TileJob createTileLoaderJob​(org.openstreetmap.gui.jmapviewer.Tile tile)  
      java.util.concurrent.ThreadPoolExecutor getDownloadExecutor()
      Returns download executor that is used by this factory.
      static java.util.concurrent.ThreadPoolExecutor getNewThreadPoolExecutor​(java.lang.String name)
      Returns a new ThreadPoolExecutor.
      static java.util.concurrent.ThreadPoolExecutor getNewThreadPoolExecutor​(java.lang.String nameFormat, int workers)
      Returns a new ThreadPoolExecutor.
      static java.util.concurrent.ThreadPoolExecutor getNewThreadPoolExecutor​(java.lang.String nameFormat, int workers, int hostLimit)
      Returns a new ThreadPoolExecutor.
      java.lang.String getStats()
      Returns cache statistics as string.
      boolean hasOutstandingTasks()  
      void setDownloadExecutor​(java.util.concurrent.ThreadPoolExecutor downloadExecutor)
      Sets the download executor that will be used to download tiles instead of default one.
      void shutdown()
      Shutdown the job dispatcher provided that it's not the default one
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • listener

        protected final org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener listener
      • THREAD_LIMIT

        public static final IntegerProperty THREAD_LIMIT
        overrides the THREAD_LIMIT in superclass, as we want to have separate limit and pool for TMS
      • DEFAULT_DOWNLOAD_JOB_DISPATCHER

        private static final java.util.concurrent.ThreadPoolExecutor DEFAULT_DOWNLOAD_JOB_DISPATCHER
        separate from JCS thread pool for TMS loader, so we can have different thread pools for default JCS and for TMS imagery
      • downloadExecutor

        private java.util.concurrent.ThreadPoolExecutor downloadExecutor
    • Constructor Detail

      • TMSCachedTileLoader

        public TMSCachedTileLoader​(org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener listener,
                                   org.apache.commons.jcs3.access.behavior.ICacheAccess<java.lang.String,​BufferedImageCacheEntry> cache,
                                   TileJobOptions options)
        Constructor
        Parameters:
        listener - called when tile loading has finished
        cache - of the cache
        options - tile job options
    • Method Detail

      • getNewThreadPoolExecutor

        public static java.util.concurrent.ThreadPoolExecutor getNewThreadPoolExecutor​(java.lang.String nameFormat,
                                                                                       int workers)
        Returns a new ThreadPoolExecutor.
        Parameters:
        nameFormat - see Utils.newThreadFactory(String, int)
        workers - number of worker thread to keep
        Returns:
        new ThreadPoolExecutor that will use a @see HostLimitQueue based queue
      • getNewThreadPoolExecutor

        public static java.util.concurrent.ThreadPoolExecutor getNewThreadPoolExecutor​(java.lang.String nameFormat,
                                                                                       int workers,
                                                                                       int hostLimit)
        Returns a new ThreadPoolExecutor.
        Parameters:
        nameFormat - see Utils.newThreadFactory(String, int)
        workers - number of worker thread to keep
        hostLimit - number of concurrent downloads per host allowed
        Returns:
        new ThreadPoolExecutor that will use a @see HostLimitQueue based queue
      • getNewThreadPoolExecutor

        public static java.util.concurrent.ThreadPoolExecutor getNewThreadPoolExecutor​(java.lang.String name)
        Returns a new ThreadPoolExecutor.
        Parameters:
        name - name of threads
        Returns:
        new ThreadPoolExecutor that will use a HostLimitQueue based queue, with default number of threads
      • createTileLoaderJob

        public org.openstreetmap.gui.jmapviewer.interfaces.TileJob createTileLoaderJob​(org.openstreetmap.gui.jmapviewer.Tile tile)
        Specified by:
        createTileLoaderJob in interface org.openstreetmap.gui.jmapviewer.interfaces.TileLoader
      • clearCache

        public void clearCache​(org.openstreetmap.gui.jmapviewer.interfaces.TileSource source)
        Specified by:
        clearCache in interface org.openstreetmap.gui.jmapviewer.interfaces.CachedTileLoader
      • getStats

        public java.lang.String getStats()
        Returns cache statistics as string.
        Returns:
        cache statistics as string
      • cancelOutstandingTasks

        public void cancelOutstandingTasks()
        cancels all outstanding tasks in the queue. This rollbacks the state of the tiles in the queue to loading = false / loaded = false
        Specified by:
        cancelOutstandingTasks in interface org.openstreetmap.gui.jmapviewer.interfaces.TileLoader
      • hasOutstandingTasks

        public boolean hasOutstandingTasks()
        Specified by:
        hasOutstandingTasks in interface org.openstreetmap.gui.jmapviewer.interfaces.TileLoader
      • setDownloadExecutor

        public void setDownloadExecutor​(java.util.concurrent.ThreadPoolExecutor downloadExecutor)
        Sets the download executor that will be used to download tiles instead of default one. You can use getNewThreadPoolExecutor(java.lang.String, int) to create a new download executor with separate queue from default.
        Parameters:
        downloadExecutor - download executor that will be used to download tiles
      • getDownloadExecutor

        public java.util.concurrent.ThreadPoolExecutor getDownloadExecutor()
        Returns download executor that is used by this factory.
        Returns:
        download executor that is used by this factory
      • shutdown

        public void shutdown()
        Shutdown the job dispatcher provided that it's not the default one