GridTask And GridTaskSpis Annotation
Starting with GridGain 2.1 you can start multiple instances of GridTopologySpi, GridLoadBalancingSpi, GridFailoverSpi, and GridCheckpointSpi. If you do that, you need to tell a task which SPI to use (by default it will use the fist SPI in the list). Add @GridTaskSpis ![]()
Example
This example shows how to configure different SPI's for different tasks. Let's assume that you have two worker nodes, Node1 and Node2. Let's also assume that you configure Node1 to belong to SegmentA and Node2 to belong to SegmentB. Here is a sample configuration for Node1
<bean id="grid.cfg" class="org.gridgain.grid.GridConfigurationAdapter" scope="singleton"> <property name="userAttributes"> <map> <entry key="segment" value="A"/> </map> </property> </bean>
Node2 configuration looks similar to Node1 with 'segment' attribute set to 'B'.
<bean id="grid.cfg" class="org.gridgain.grid.GridConfigurationAdapter" scope="singleton"> <property name="userAttributes"> <map> <entry key="segment" value="B"/> </map> </property> </bean>
Now, if you have Task1 and Task2 starting from some master node NodeM, you can easily configure Task1 to only run on SegmentA and Task2 to only run on SegmentB. Here is how configuration on master node NodeM would look like:
<bean id="grid.cfg" class="org.gridgain.grid.GridConfigurationAdapter" scope="singleton"> <!-- Topology SPIs. We have two named SPIs: One picks up nodes that have attribute "segment" set to "A" and another one sees nodes that have attribute "segment" set to "B". --> <property name="topologySpi"> <list> <bean class="org.gridgain.grid.spi.topology.nodefilter.GridNodeFilterTopologySpi"> <property name="name" value="topologyA"/> <property name="filter"> <bean class="org.gridgain.grid.GridJexlNodeFilter"> <property name="expression" value="node.attributes['segment'] == 'A'"/> </bean> </property> </bean> <bean class="org.gridgain.grid.spi.topology.nodefilter.GridNodeFilterTopologySpi"> <property name="name" value="topologyB"/> <property name="filter"> <bean class="org.gridgain.grid.GridJexlNodeFilter"> <property name="expression" value="node.attributes['segment'] == 'B'"/> </bean> </property> </bean> </list> </property> </bean>
Then your Task1 and Task2 would look as follows (note the @GridTaskSpis annotation).
@GridTaskSpis(topologySpi="topologyA") public class GridSegmentATask extends GridTaskSplitAdapter<String, Integer> { ... }
and
@GridTaskSpis(topologySpi="topologyB") public class GridSegmentBTask extends GridTaskSplitAdapter<String, Integer> { ... }
