GridGain™ 3.6.0e
Enterprise Edition

org.gridgain.grid.spi.collision.fifoqueue
Class GridFifoQueueCollisionSpi

java.lang.Object
  extended by org.gridgain.grid.spi.GridSpiAdapter
      extended by org.gridgain.grid.spi.collision.fifoqueue.GridFifoQueueCollisionSpi
All Implemented Interfaces:
GridFifoQueueCollisionSpiMBean, GridCollisionSpi, GridSpi, GridSpiJsonConfigurable, GridSpiManagementMBean

@GridSpiInfo(author="GridGain Systems",
             url="www.gridgain.com",
             email="support@gridgain.com",
             version="3.6.0e.13012012")
@GridSpiMultipleInstancesSupport(value=true)
public class GridFifoQueueCollisionSpi
extends GridSpiAdapter
implements GridCollisionSpi, GridFifoQueueCollisionSpiMBean

This class provides implementation for Collision SPI based on FIFO queue. Jobs are ordered as they arrived and only GridFifoQueueCollisionSpi.getParallelJobsNumber() number of jobs is allowed to execute in parallel. Other jobs will be buffered in the passive queue.

Configuration

Mandatory

This SPI has no mandatory configuration parameters.

Optional

This SPI has following optional configuration parameters:

Java Example

GridFifoQueueCollisionSpi can be configured as follows:
 GridFifoQueueCollisionSpi colSpi = new GridFifoQueueCollisionSpi();

 // Execute all jobs sequentially by setting parallel job number to 1.
 colSpi.setParallelJobsNumber(1);

 GridConfigurationAdapter cfg = new GridConfigurationAdapter();

 // Override default collision SPI.
 cfg.setCollisionSpi(colSpi);

 // Starts grid.
 G.start(cfg);
 

Spring Example

GridFifoQueueCollisionSpi can be configured from Spring XML configuration file:
 <bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfigurationAdapter" singleton="true">
       ...
       <property name="collisionSpi">
           <bean class="org.gridgain.grid.spi.collision.fifoqueue.GridFifoQueueCollisionSpi">
               <property name="parallelJobsNumber" value="1"/>
           </bean>
       </property>
       ...
 </bean>
 

Wiki & Forum:


Wiki
Forum

 

Field Summary
static int DFLT_PARALLEL_JOBS_NUM
          Default number of parallel jobs allowed (value is 95 which is slightly less same as default value of threads in the execution thread pool to allow some extra threads for system processing).
static int DFLT_WAIT_JOBS_NUM
          Default waiting jobs number.
 
Constructor Summary
GridFifoQueueCollisionSpi()
           
 
Method Summary
 int getCurrentActiveJobsNumber()
          Gets current number of jobs that are active, i.e.
 int getCurrentHeldJobsNumber()
          Gets number of currently 'held' jobs.
 int getCurrentRunningJobsNumber()
          
 int getCurrentWaitJobsNumber()
          Gets current number of jobs that wait for the execution.
 int getParallelJobsNumber()
          Gets number of jobs that can be executed in parallel.
 int getWaitingJobsNumber()
          Maximum number of jobs that are allowed to wait in waiting queue.
 void onCollision(GridCollisionContext ctx)
          This is a callback called when either new grid job arrived or executing job finished its execution.
 void setExternalCollisionListener(GridCollisionExternalListener lsnr)
          Listener to be set for notification of external collision events (e.g. job stealing).
 void setParallelJobsNumber(int parallelJobsNum)
          Sets number of jobs that are allowed to be executed in parallel on this node.
 void setWaitingJobsNumber(int waitJobsNum)
          Sets maximum number of jobs that are allowed to wait in waiting queue.
 void spiStart(String gridName)
          This method is called to start SPI.
 void spiStop()
          This method is called to stop SPI.
 String toString()
          
 
Methods inherited from class org.gridgain.grid.spi.GridSpiAdapter
assertParameter, checkConfigurationConsistency, configInfo, createSpiAttributeName, getAuthor, getConsistentAttributeNames, getGridGainHome, getLocalNodeId, getName, getNodeAttributes, getSpiContext, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion, injectables, onContextDestroyed, onContextInitialized, registerMBean, setJson, setName, startInfo, startStopwatch, stopInfo, unregisterMBean
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.gridgain.grid.spi.GridSpi
getName, getNodeAttributes, onContextDestroyed, onContextInitialized
 
Methods inherited from interface org.gridgain.grid.spi.GridSpiJsonConfigurable
setJson
 
Methods inherited from interface org.gridgain.grid.spi.GridSpiManagementMBean
getAuthor, getGridGainHome, getLocalNodeId, getName, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion
 

Field Detail

DFLT_PARALLEL_JOBS_NUM

public static final int DFLT_PARALLEL_JOBS_NUM
Default number of parallel jobs allowed (value is 95 which is slightly less same as default value of threads in the execution thread pool to allow some extra threads for system processing).

See Also:
Constant Field Values

DFLT_WAIT_JOBS_NUM

public static final int DFLT_WAIT_JOBS_NUM
Default waiting jobs number. If number of waiting jobs exceeds this number, jobs will be rejected. Default value is Integer.MAX_VALUE.

See Also:
Constant Field Values
Constructor Detail

GridFifoQueueCollisionSpi

public GridFifoQueueCollisionSpi()
Method Detail

setParallelJobsNumber

@GridSpiConfiguration(optional=true)
public void setParallelJobsNumber(int parallelJobsNum)
Sets number of jobs that are allowed to be executed in parallel on this node. If not provided, default value is {@link #DFLT_PARALLEL_JOBS_NUM}.

Parameters:
parallelJobsNum - Maximum number of jobs to be executed in parallel.

getParallelJobsNumber

public int getParallelJobsNumber()
Gets number of jobs that can be executed in parallel.

Specified by:
getParallelJobsNumber in interface GridFifoQueueCollisionSpiMBean
Returns:
Number of jobs that can be executed in parallel.

setWaitingJobsNumber

@GridSpiConfiguration(optional=true)
public void setWaitingJobsNumber(int waitJobsNum)
Sets maximum number of jobs that are allowed to wait in waiting queue. If number of jobs exceeds this number, jobs will be rejected. Default value is defined by GridFifoQueueCollisionSpi.DFLT_WAIT_JOBS_NUM constant.

Parameters:
waitJobsNum - Maximum waiting jobs number.

getWaitingJobsNumber

public int getWaitingJobsNumber()
Maximum number of jobs that are allowed to wait in waiting queue. If number of waiting jobs ever exceeds this number, excessive jobs will be rejected.

Specified by:
getWaitingJobsNumber in interface GridFifoQueueCollisionSpiMBean
Returns:
Maximum allowed number of waiting jobs.

getCurrentWaitJobsNumber

public int getCurrentWaitJobsNumber()
Gets current number of jobs that wait for the execution.

Specified by:
getCurrentWaitJobsNumber in interface GridFifoQueueCollisionSpiMBean
Returns:
Number of jobs that wait for execution.

getCurrentActiveJobsNumber

public int getCurrentActiveJobsNumber()
Gets current number of jobs that are active, i.e. 'running + held' jobs.

Specified by:
getCurrentActiveJobsNumber in interface GridFifoQueueCollisionSpiMBean
Returns:
Number of active jobs.

getCurrentRunningJobsNumber

public int getCurrentRunningJobsNumber()

Specified by:
getCurrentRunningJobsNumber in interface GridFifoQueueCollisionSpiMBean

getCurrentHeldJobsNumber

public int getCurrentHeldJobsNumber()
Gets number of currently 'held' jobs.

Specified by:
getCurrentHeldJobsNumber in interface GridFifoQueueCollisionSpiMBean
Returns:
Number of currently 'held' jobs.

spiStart

public void spiStart(String gridName)
              throws GridSpiException
This method is called to start SPI. After this method returns successfully kernel assumes that SPI is fully operational.

Specified by:
spiStart in interface GridSpi
Throws:
GridSpiException - Throws in case of any error during SPI start.
Parameters:
gridName - Name of grid instance this SPI is being started for (null for default grid).

spiStop

public void spiStop()
             throws GridSpiException
This method is called to stop SPI. After this method returns kernel assumes that this SPI is finished and all resources acquired by it are released.

Note that this method can be called at any point including during recovery of failed start. It should make no assumptions on what state SPI will be in when this method is called.

Specified by:
spiStop in interface GridSpi
Throws:
GridSpiException - Thrown in case of any error during SPI stop.

setExternalCollisionListener

public void setExternalCollisionListener(GridCollisionExternalListener lsnr)
Listener to be set for notification of external collision events (e.g. job stealing). Once grid receives such notification, it will immediately invoke collision SPI.

GridGain uses this listener to enable job stealing from overloaded to underloaded nodes. However, you can also utilize it, for instance, to provide time based collision resolution. To achieve this, you most likely would mark some job by setting a certain attribute in job context (see GridJobContext) for a job that requires time-based scheduling and set some timer in your SPI implementation that would wake up after a certain period of time. Once this period is reached, you would notify this listener that a collision resolution should take place. Then inside of your collision resolution logic, you would find the marked waiting job and activate it.

Note that most collision SPI's might not have external collisions. In that case, they should simply ignore this method and do nothing when listener is set.

Specified by:
setExternalCollisionListener in interface GridCollisionSpi
Parameters:
lsnr - Listener for external collision events.

onCollision

public void onCollision(GridCollisionContext ctx)
This is a callback called when either new grid job arrived or executing job finished its execution. When new job arrives it is added to the end of the wait list and this method is called. When job finished its execution, it is removed from the active list and this method is called (i.e., when grid job is finished it will not appear in any list in collision resolution).

Implementation of this method should act on all lists, each of which contains collision job contexts that define a set of operations available during collision resolution. Refer to GridCollisionContext and GridCollisionJobContext documentation for more information.

Specified by:
onCollision in interface GridCollisionSpi
Parameters:
ctx - Collision context which contains all collision lists.

toString

public String toString()

Overrides:
toString in class Object

GridGain™ 3.6.0e
Enterprise Edition

GridGain - Real Time Big Data
Enterprise Edition, ver. 3.6.0e.13012012
2012 Copyright © GridGain Systems
Follow us:   Follow GridGain on Github Follow GridGain on Facebook Join GridGain User Group Follow GridGain on Twitter Follow GridGain on YouTube