Click on Javadoc link to open Javadoc documentation.
Package
org.gridgain.grid.spi.collision.priorityqueue Javadoc![]()
Description
GridPriorityQueueCollisionSpi ![]()
Note that if parallelJobsNumber configuration parameter is not set, then this SPI will allow all concurrent jobs to proceed without interruptions. Make sure to set parallelJobNumber ![]()
GridTask Code Example
Here is an example of a grid tasks that uses priority collision SPI is configured. Note that priority collision resolution is absolutely transparent to the user and is simply a matter of proper grid configuration. Also, priority may be defined only for task (it can be defined within the task, not at a job level). All split jobs will be started with priority declared in their owner task.
This example demonstrates how urgent task may be declared with a higher priority value. Priority SPI guarantees (see its configuration in example below, where number of parallel jobs is set to 1) that all jobs from MyGridUrgentTask will most likely be activated first (one by one) and jobs from MyGridUsualTask with lowest priority will wait. Once higher priority jobs complete, lower priority jobs will be scheduled.
public class MyGridUrgentTask extends GridTaskSplitAdapter<Object, Object> { public static final int SPLIT_COUNT = 5; @GridTaskSessionResource private GridTaskSession taskSes = null; @Override protected Collection<? extends GridJob> split(int gridSize, Object arg) throws GridException { ... // Set high task priority (note that attribute name is used by the SPI // and should not be changed). taskSes.setAttribute("grid.task.priority", 10); Collection<GridJob> jobs = new ArrayList<GridJob>(SPLIT_COUNT); for (int i = 1; i <= SPLIT_COUNT; i++) { jobs.add(new GridJobAdapter<Integer>(i) { ... }); } ... } }
and
public class MyGridUsualTask extends GridTaskSplitAdapter<Object, Object> { public static final int SPLIT_COUNT = 20; @GridTaskSessionResource private GridTaskSession taskSes = null; @Override protected Collection<? extends GridJob> split(int gridSize, Object arg) throws GridException { ... // Set low task priority (note that attribute name is used by the SPI // and should not be changed). taskSes.setAttribute("grid.task.priority", 5); Collection<GridJob> jobs = new ArrayList<GridJob>(SPLIT_COUNT); for (int i = 1; i <= SPLIT_COUNT; i++) { jobs.add(new GridJobAdapter<Integer>(i) { ... }); } ... }
Configuration
The following configuration parameters can be used to configure GridPriorityQueueCollisionSpi
| Setter Method | Description | Optional | Default |
|---|---|---|---|
| setDefaultPriority(int) |
Sets default priority used if job does not have job priority attribute set in the context. | Yes | 0 specified in GridPriorityQueueCollisionSpi.DFLT_PRIORITY |
| setParallelJobsNumber(int) |
Sets upper liimit for a number of jobs that will proceed without interruptions. | Yes | 95, specified in GridPriorityQueueCollisionSpi.DFLT_PARALLEL_JOBS_NUM |
| setPriorityAttributeKey(String) |
This key will be used to look up job priorities from job context (GridJobContext.getAttribute(String) |
Yes | Value "grid.job.priority", specified in GridPriorityQueueCollisionSpi.DFLT_PRIORITY_ATTRIBUTE_KEY |
Examples
As any GridGain SPI, GridPriorityQueueCollisionSpi ![]()
![]()
GridPriorityQueueCollisionSpi colSpi = new GridPriorityQueueCollisionSpi(); // Execute all jobs sequentially by setting parallel job number to 1. colSpi.setParallelJobsNumber(5); GridConfigurationAdapter cfg = new GridConfigurationAdapter(); // Override default collision SPI. cfg.setCollisionSpi(colSpi); // Start grid. GridFactory.start(cfg);
or from Spring configuration file
<bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfigurationAdapter" singleton="true"> ... <property name="collisionSpi"> <bean class="org.gridgain.grid.spi.collision.priorityqueue.GridPriorityQueueCollisionSpi"> <property name="parallelJobsNumber" value="5"/> </bean> </property> ... </bean>

For more information about using Spring framework for configuration click here.
