Question

We're migrating an application from an older gridgain 4 codebase to gridgain 6. In the old application, we used a GridJexlPredicate2 to tie into a monitor method that determined if a node should run a particular job (basically, checked if node contained a particular attribute value).

In gridgain 6, I suspect we should be using the GridBiPredicate class. However, is there a replacement for the expression language based GridJexlPredicate2 class or is there a different programatic / declarative approach I should be looking at?

Thanks

/**
* Creates the topology filter used to select nodes for processing.
* The expression string will have three variables that can be referenced:
* <dl>
* <dt><strong>node</strong></dt>
* <dd>The GridNode being tested</dd>
* <dt><strong>session</strong></dt>
* <dd>The GridTaskSession for the task being executed</dd>
* <dt><strong>monitor</strong></dt>
* <dd>The GridNodeMonitor monitoring nodes on the grid</dd>
* </dl>
*
* @param monitor The monitor instance to be bound into the expression
*context for use in the filter expression
* @return A {@link GridBiPredicate} used to filter nodes
*/
  public static GridJexlPredicate2<GridNode, GridComputeTaskSession>    createTopologyFilter(GridNodeMonitor monitor) {
    GridJexlPredicate2<GridNode, GridComputeTaskSession> filter = new GridJexlPredicate2<GridNode, GridComputeTaskSession>("monitor.canAcceptJobs(node)","node", "session");
    return filter.with("monitor", monitor);
}
Was it helpful?

Solution

The alternative is to use GridProjection with a filter

final MyNodeMonitor monitor = ...;

Grid grid = GridGain.gridI();

GridProjection prj = grid.forPredicate(new GridPredicate<GridNode>() {
    @Override public boolean apply(GridNode node) {
        return monitor.canAcceptJobs(node);
    }
});

GridComputeTaskFuture<?> fut = prj.compute().execute(new MyTask());

// Synchronous wait.
fut.get();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top