0

我们正在将应用程序从较旧的 gridgain 4 代码库迁移到 gridgain 6。在旧应用程序中,我们使用 GridJexlPredicate2 绑定到一个监视器方法,该方法确定节点是否应该运行特定的作业(基本上,检查节点是否包含特定的属性值)。

在 gridgain 6 中,我怀疑我们应该使用 GridBiPredicate 类。但是,是否有基于表达式语言的 GridJexlPredicate2 类的替代品,或者我应该考虑不同的编程/声明性方法?

谢谢

/**
* 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);
}
4

1 回答 1

1

另一种方法是使用带有过滤器的 GridProjection

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();
于 2014-04-12T03:04:25.700 回答