it.geosolutions.jaiext.scheduler
Class JAIExtTileScheduler

java.lang.Object
  extended by it.geosolutions.jaiext.scheduler.JAIExtTileScheduler
All Implemented Interfaces:
javax.media.jai.TileScheduler

public class JAIExtTileScheduler
extends Object
implements javax.media.jai.TileScheduler

This is another implementation of the javax.media.jai.TileScheduler interface. It provides a mechanism for scheduling tile calculation. Multi-threading is used whenever possible.

See Also:
TileScheduler

Field Summary
static Logger LOGGER
          Logger associated to the scheduler
 
Constructor Summary
JAIExtTileScheduler()
          Constructor.
JAIExtTileScheduler(int parallelism, int priority, int prefetchParallelism, int prefetchPriority)
          Constructor.
 
Method Summary
 void cancelTiles(javax.media.jai.TileRequest request, Point[] tileIndices)
          Issues an advisory cancellation request to the TileScheduler stating that the indicated tiles of the specified image should not be processed.
protected  void finalize()
          Queue WorkerThread.TERMINATEs to all workers.
 int getParallelism()
          Returns the degree of parallelism of the scheduler.
 int getPrefetchParallelism()
          Identical to getParallelism() but applies only to prefetchTiles().
 int getPrefetchPriority()
          Identical to getPriority() but applies only to prefetchTiles().
 int getPriority()
          Returns the priority of scheduleTiles() processing.
 void prefetchTiles(javax.media.jai.PlanarImage owner, Point[] tileIndices)
          Prefetchs a list of tiles of an image.
 Raster scheduleTile(javax.media.jai.OpImage owner, int tileX, int tileY)
          Schedules a single tile for computation.
 Raster[] scheduleTiles(javax.media.jai.OpImage owner, Point[] tileIndices)
          Schedules multiple tiles of an image for computation.
 javax.media.jai.TileRequest scheduleTiles(javax.media.jai.PlanarImage target, Point[] tileIndices, javax.media.jai.TileComputationListener[] tileListeners)
          Schedule a list of tiles for computation.
 void setParallelism(int parallelism)
          Suggests to the scheduler the degree of parallelism to use in processing invocations of scheduleTiles().
 void setPrefetchParallelism(int parallelism)
          Identical to setParallelism() but applies only to prefetchTiles().
 void setPrefetchPriority(int priority)
          Identical to setPriority() but applies only to prefetchTiles().
 void setPriority(int priority)
          Suggests to the scheduler the priority to assign to processing effected by scheduleTiles().
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

public static final Logger LOGGER
Logger associated to the scheduler

Constructor Detail

JAIExtTileScheduler

public JAIExtTileScheduler(int parallelism,
                           int priority,
                           int prefetchParallelism,
                           int prefetchPriority)
Constructor.

Parameters:
parallelism - The number of worker threads to do tile computation. If this number is less than 1, no multi-threading is used.
priority - The priority of worker threads.
prefetchParallelism - The number of threads to do prefetching. If this number is less than 1, no multi-threading is used.
prefetchPriority - The priority of prefetch threads.

JAIExtTileScheduler

public JAIExtTileScheduler()
Constructor. Processing and prefetch queues are created and all parallelism and priority values are set to default values.

Method Detail

scheduleTile

public Raster scheduleTile(javax.media.jai.OpImage owner,
                           int tileX,
                           int tileY)
Schedules a single tile for computation.

Specified by:
scheduleTile in interface javax.media.jai.TileScheduler
Parameters:
owner - The image the tiles belong to.
tileX - The tile's X index.
tileY - The tile's Y index.
Returns:
The computed tile
Throws:
IllegalArgumentException - if owner is null.

scheduleTiles

public Raster[] scheduleTiles(javax.media.jai.OpImage owner,
                              Point[] tileIndices)
Schedules multiple tiles of an image for computation.

Specified by:
scheduleTiles in interface javax.media.jai.TileScheduler
Parameters:
owner - The image the tiles belong to.
tileIndices - An array of tile X and Y indices.
Returns:
An array of computed tiles.

scheduleTiles

public javax.media.jai.TileRequest scheduleTiles(javax.media.jai.PlanarImage target,
                                                 Point[] tileIndices,
                                                 javax.media.jai.TileComputationListener[] tileListeners)
Schedule a list of tiles for computation. The supplied listeners will be notified after each tile has been computed. This method ideally should be non-blocking. If the TileScheduler implementation uses multithreading, it is at the discretion of the implementation which thread invokes the TileComputationListener methods.

Specified by:
scheduleTiles in interface javax.media.jai.TileScheduler

cancelTiles

public void cancelTiles(javax.media.jai.TileRequest request,
                        Point[] tileIndices)
Issues an advisory cancellation request to the TileScheduler stating that the indicated tiles of the specified image should not be processed. The handling of this request is at the discretion of the scheduler which may cancel tile processing in progress and remove tiles from its internal queue, remove tiles from the queue but not terminate current processing, or simply do nothing.

In this implementation of TileScheduler the second tile cancellation option is implemented, i.e., tiles are removed from the internal queue but computation already in progress is not terminated. If there is at least one worker thread this method should be non-blocking. Any tiles allowed to complete computation subsequent to this call are complete and will be treated as if they had not been cancelled, e.g., with respect to caching, notification of registered listeners, etc. Furthermore, canceling a tile request in no way invalidates the tile as a candidate for future recomputation.

Specified by:
cancelTiles in interface javax.media.jai.TileScheduler

prefetchTiles

public void prefetchTiles(javax.media.jai.PlanarImage owner,
                          Point[] tileIndices)
Prefetchs a list of tiles of an image.

Specified by:
prefetchTiles in interface javax.media.jai.TileScheduler
Parameters:
owner - The image the tiles belong to.
tileIndices - An array of tile X and Y indices.

setParallelism

public void setParallelism(int parallelism)
Suggests to the scheduler the degree of parallelism to use in processing invocations of scheduleTiles(). For example, this might set the number of threads to spawn. It is legal to implement this method as a no-op.

In this implementation of TileScheduler this method sets the number of worker threads actually used for tile computation. Ideally this number should equal the number of processors actually available on the system. It is the responsibility of the application to set this value as the number of processors is not available via the virtual machine. A parallelism value of zero indicates that all tile computation will be effected in the primary thread. A parallelism value of N indicates that there will be N worker threads in addition to the primary scheduler thread. In JAI the parallelism defaults to a value of 2 unless explicity set by the application.

Specified by:
setParallelism in interface javax.media.jai.TileScheduler
Parameters:
parallelism - The suggested degree of parallelism.
Throws:
IllegalArgumentException - if parallelism is negative.

getParallelism

public int getParallelism()
Returns the degree of parallelism of the scheduler.

Specified by:
getParallelism in interface javax.media.jai.TileScheduler

setPrefetchParallelism

public void setPrefetchParallelism(int parallelism)
Identical to setParallelism() but applies only to prefetchTiles().

Specified by:
setPrefetchParallelism in interface javax.media.jai.TileScheduler

getPrefetchParallelism

public int getPrefetchParallelism()
Identical to getParallelism() but applies only to prefetchTiles().

Specified by:
getPrefetchParallelism in interface javax.media.jai.TileScheduler

setPriority

public void setPriority(int priority)
Suggests to the scheduler the priority to assign to processing effected by scheduleTiles(). For example, this might set thread priority. Values outside of the accepted priority range will be clamped to the nearest extremum. An implementation may clamp the prefetch priority to less than the scheduling priority. It is legal to implement this method as a no-op.

In this implementation of TileScheduler this method sets the priority of the worker threads used for tile computation. Its initial value is Thread.NORM_PRIORITY.

Specified by:
setPriority in interface javax.media.jai.TileScheduler
Parameters:
priority - The suggested priority.

getPriority

public int getPriority()
Returns the priority of scheduleTiles() processing.

Specified by:
getPriority in interface javax.media.jai.TileScheduler

setPrefetchPriority

public void setPrefetchPriority(int priority)
Identical to setPriority() but applies only to prefetchTiles().

In this implementation of TileScheduler, this method sets the priority of any threads spawned to prefetch tiles. Its initial value is Thread.MIN_PRIORITY.

Specified by:
setPrefetchPriority in interface javax.media.jai.TileScheduler

getPrefetchPriority

public int getPrefetchPriority()
Identical to getPriority() but applies only to prefetchTiles().

Specified by:
getPrefetchPriority in interface javax.media.jai.TileScheduler

finalize

protected void finalize()
                 throws Throwable
Queue WorkerThread.TERMINATEs to all workers.

Overrides:
finalize in class Object
Throws:
Throwable


Copyright © 2006–2015 GeoSolutions. All rights reserved.