Dashboard > GridGain User Guide > Table Of Contents > Developers Guide > SLAs And Grid Node Filters
SLAs And Grid Node Filters
Added by morpheus, last edited by morpheus on Jan 30, 2009  (view change)
Labels: 
(None)


Grid Node Filters

Starting with GridGain 2.1 you are able to filter nodes by providing your implementation of GridNodeFilter Javadoc interface. Instances of classes that implement this interface are used to filter grid nodes. These instances are used to filter nodes in method Grid.getNodes(GridNodeFilter) Javadoc . They are also used by GridNodeFilterTopologySpi to provide task topology based on user-defined node filters.

GridGain also comes with GridJexlNodeFilter Javadoc implementation which allows you to conveniently filter nodes based on Apache JEXL expression language. For information about specifics of JEXL expression language refer to Apache JEXL documentation.

Together with GridNodeFilterTopologySpi, GridJexlNodeFilter Javadoc allows for a fairly simple way to provide complex SLA-based task topology specifications. For example, expression below shows how the SPI can be configured with GridJexlNodeFilter to include all Windows XP nodes with more than one processor or core and that are not loaded over 50%.

GridNodeFilterTopologySpi topSpi = new GridNodeFilterTopologySpi();

GridNodeFilter filter = new GridJexlNodeFilter(
    "node.metrics.availableProcessors > 1 && " + 
    "node.metrics.averageCpuLoad < 0.5 && " + 
    "node.attributes['os.name'] == 'Windows XP'");

// Add filter.
topSpi.setFilter(filter);

GridConfigurationAdapter cfg = new GridConfigurationAdapter();

// Override topology SPI.
cfg.setTopologySpi(topSpi);

// Start grid.
GridFactory.start(cfg);

or from Spring configuration file:

<bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfigurationAdapter" singleton="true">
    ...
    <property name="topologySpi">
        <bean class="org.gridgain.grid.spi.topology.nodefilter.GridNodeFilterTopologySpi">
            <property name="filter">
                 <bean class="org.gridgain.grid.GridJexlNodeFilter">
                     <property name="expression">
                         <value>
                             <![CDATA[
                             node.metrics.availableProcessors > 1 &&
                             node.metrics.averageCpuLoad < 0.5 &&
                             node.attributes['os.name'] == 'Windows XP'
                             ]]>
                         </value>
                     </property>
                 </bean>
             </property>
        </bean>
    </property>
    ...
</bean>

Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.10 Build:#528 Nov 29, 2006) - Bug/feature request - Contact Administrators