Search in sources :

Example 1 with ComputeTaskTimeoutCheckedException

use of org.apache.ignite.internal.compute.ComputeTaskTimeoutCheckedException in project ignite by apache.

the class GridifySetToValueAbstractAspect method execute.

/**
     * Execute method on grid.
     *
     * @param mtd Method.
     * @param compute {@link org.apache.ignite.IgniteCompute} instance.
     * @param cls Joint point signature class.
     * @param arg GridifyArgument with all method signature parameters.
     * @param nodeFilter Node filter.
     * @param threshold Parameter that defines the minimal value below which the
     *      execution will NOT be grid-enabled.
     * @param splitSize Size of elements to send in job argument.
     * @param timeout Execution timeout.
     * @return Result.
     * @throws IgniteCheckedException If execution failed.
     */
protected Object execute(Method mtd, IgniteCompute compute, Class<?> cls, GridifyRangeArgument arg, GridifyNodeFilter nodeFilter, int threshold, int splitSize, long timeout) throws IgniteCheckedException {
    long now = U.currentTimeMillis();
    long end = timeout == 0 ? Long.MAX_VALUE : timeout + now;
    // Prevent overflow.
    if (end < 0)
        end = Long.MAX_VALUE;
    Collection<?> res = null;
    while (true) {
        if (now > end)
            throw new ComputeTaskTimeoutCheckedException("Timeout occurred while waiting for completion.");
        GridifyRangeArgument taskArg = createGridifyArgument(arg, res);
        if (taskArg == null)
            return result(res);
        else if (taskArg.getInputSize() != UNKNOWN_SIZE && taskArg.getInputSize() <= threshold) {
            // Note, that we can't cancel by timeout locally started method.
            try {
                mtd.setAccessible(true);
                return mtd.invoke(arg.getTarget(), taskArg.getMethodParameters());
            } catch (IllegalAccessException | InvocationTargetException e) {
                throw new IgniteCheckedException("Failed to execute method locally.", e);
            }
        } else {
            res = compute.withTimeout(timeout == 0 ? 0L : (end - now)).execute(new GridifyDefaultRangeTask(cls, nodeFilter, threshold, splitSize, true), taskArg);
        }
        now = U.currentTimeMillis();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ComputeTaskTimeoutCheckedException(org.apache.ignite.internal.compute.ComputeTaskTimeoutCheckedException) GridifyRangeArgument(org.apache.ignite.internal.util.gridify.GridifyRangeArgument)

Example 2 with ComputeTaskTimeoutCheckedException

use of org.apache.ignite.internal.compute.ComputeTaskTimeoutCheckedException in project ignite by apache.

the class GridifySetToSetAbstractAspect method execute.

/**
     * Execute method on grid.
     *
     * @param compute {@link org.apache.ignite.IgniteCompute} instance.
     * @param cls Joint point signature class.
     * @param arg GridifyArgument with all method signature parameters.
     * @param nodeFilter Node filter.
     * @param threshold Parameter that defines the minimal value below which the
     *      execution will NOT be grid-enabled.
     * @param splitSize Size of elements to send in job argument.
     * @param timeout Execution timeout.
     * @return Result.
     * @throws IgniteCheckedException If execution failed.
     */
protected Object execute(IgniteCompute compute, Class<?> cls, GridifyRangeArgument arg, GridifyNodeFilter nodeFilter, int threshold, int splitSize, long timeout) throws IgniteCheckedException {
    long now = U.currentTimeMillis();
    long end = timeout == 0 ? Long.MAX_VALUE : timeout + now;
    // Prevent overflow.
    if (end < 0)
        end = Long.MAX_VALUE;
    if (now > end)
        throw new ComputeTaskTimeoutCheckedException("Timeout occurred while waiting for completion.");
    Collection<?> res = compute.withTimeout(timeout == 0 ? 0L : (end - now)).execute(new GridifyDefaultRangeTask(cls, nodeFilter, threshold, splitSize, false), arg);
    return result(arg.getMethodReturnType(), res);
}
Also used : ComputeTaskTimeoutCheckedException(org.apache.ignite.internal.compute.ComputeTaskTimeoutCheckedException)

Aggregations

ComputeTaskTimeoutCheckedException (org.apache.ignite.internal.compute.ComputeTaskTimeoutCheckedException)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 GridifyRangeArgument (org.apache.ignite.internal.util.gridify.GridifyRangeArgument)1