GridGain™ 2.1.0
Java API Specification

org.gridgain.grid
Class GridJexlNodeFilter

java.lang.Object
  extended by org.gridgain.grid.GridJexlNodeFilter
All Implemented Interfaces:
GridNodeFilter

public class GridJexlNodeFilter
extends Object
implements GridNodeFilter

Implementation of GridNodeFilter based on Apache JEXL expression language. The expression will be compiled only once, at the creation time, and all invocation will simply plugin the passed-in node into the compiled expression.

Example below shows how JEXL node filter can be used to get grid nodes.

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

 Collection<GridNode> nodes = grid.getNodes(filter);
 ...
 

Together with GridNodeFilterTopologySpi GridJexlNodeFilter 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%

 <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>
 




See Also:

  Documentation
  Email Support
  Online Forums
  Issue Tracking

Author:   2005-2008 Copyright © GridGain Systems. All Rights Reserved. ver. 2.1.0

 

Constructor Summary
GridJexlNodeFilter()
          Creates filter.
GridJexlNodeFilter(String expr)
          Creates filter.
 
Method Summary
 boolean accept(GridNode node)
          Tests if a specified grid node should be accepted.
 String getExpression()
          Gets expression.
 void setExpression(String expr)
          Sets expression.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GridJexlNodeFilter

public GridJexlNodeFilter()
Creates filter.


GridJexlNodeFilter

public GridJexlNodeFilter(String expr)
                   throws GridRuntimeException
Creates filter.

Throws:
GridRuntimeException - If JEXL boolean expression failed.
Parameters:
expr - JEXL boolean expression for filter.
Method Detail

getExpression

public String getExpression()
Gets expression.

Returns:
Expression.

setExpression

public void setExpression(String expr)
                   throws GridRuntimeException
Sets expression.

Throws:
GridRuntimeException - If JEXL boolean expression failed.
Parameters:
expr - JEXL boolean expression.

accept

public boolean accept(GridNode node)
               throws GridRuntimeException
Tests if a specified grid node should be accepted.

Specified by:
accept in interface GridNodeFilter
Throws:
GridRuntimeException
Parameters:
node - Node to check.
Returns:
True if node is accepted, false otherwise.

toString

public String toString()

Overrides:
toString in class Object

GridGain™ 2.1.0
Java API Specification

GridGain™ - Grid Computing Made Simple, ver. 2.1.0.19122008
2005-2008 Copyright © GridGain Systems. All Rights Reserved.