Example usage for com.google.gwt.user.client IncrementalCommand execute

List of usage examples for com.google.gwt.user.client IncrementalCommand execute

Introduction

In this page you can find the example usage for com.google.gwt.user.client IncrementalCommand execute.

Prototype

boolean execute();

Source Link

Document

Causes the IncrementalCommand to execute its encapsulated behavior.

Usage

From source file:gov.lbl.glamm.client.experiment.util.DelayConfigCommandExecutor.java

License:Apache License

/**
 * This method will dispatch commands from the command queue. It will dispatch
 * commands until one of the following conditions is <code>true</code>:
 * <ul>//from ww w. j  a v  a  2  s  . c  om
 * <li>It consumed its dispatching time slice
 * {@value #DEFAULT_TIME_SLICE_MILLIS}</li>
 * <li>It encounters a <code>null</code> in the command queue</li>
 * <li>All commands which were present at the start of the dispatching have
 * been removed from the command queue</li>
 * <li>The command that it was processing was canceled due to a false
 * cancellation -- in this case we exit without updating any state</li>
 * </ul>
 * 
 * @param startTimeMillis the time when this method started
 */
protected void doExecuteCommands(double startTimeMillis) {
    assert (!isExecutionTimerPending());

    boolean wasCanceled = false;
    try {
        setExecuting(true);

        iterator.setEnd(commands.size());

        cancellationTimer.schedule(DEFAULT_CANCELLATION_TIMEOUT_MILLIS);

        while (iterator.hasNext()) {
            Object element = iterator.next();

            boolean removeCommand = true;
            try {
                if (element == null) {
                    // null forces a yield or pause in execution
                    return;
                }

                if (element instanceof Command) {
                    Command command = (Command) element;
                    command.execute();
                } else if (element instanceof IncrementalCommand) {
                    IncrementalCommand incrementalCommand = (IncrementalCommand) element;
                    removeCommand = !incrementalCommand.execute();
                }

            } finally {
                wasCanceled = iterator.wasRemoved();
                if (wasCanceled) {
                    /*
                     * The iterator may have already had its remove method called, if it
                     * has, then we need to exit without updating any state
                     */
                    return;
                }

                if (removeCommand) {
                    iterator.remove();
                }
            }

            if (hasTimeSliceExpired(Duration.currentTimeMillis(), startTimeMillis)) {
                // the time slice has expired
                return;
            }
        }
    } finally {
        if (!wasCanceled) {
            cancellationTimer.cancel();

            setExecuting(false);

            maybeStartExecutionTimer();
        }
    }
}