All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.as.console.client.shared.schedule.LongRunningTask Maven / Gradle / Ivy

Go to download

Bundles the core AS7 console as a GWT module. Includes minor customizations to support extensions.

There is a newer version: 0.7.0.Final
Show newest version
package org.jboss.as.console.client.shared.schedule;

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.user.client.ui.PopupPanel;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.domain.model.SimpleCallback;
import org.jboss.as.console.client.shared.dispatch.AsyncCommand;
import org.jboss.ballroom.client.widgets.window.Feedback;

/**
 * @author Heiko Braun
 * @date 12/19/11
 */
public class LongRunningTask {

    private AsyncCommand command;
    private int numAttempts = 0;
    private int limit;
    private boolean keepRunning = true;
    private String message = null;

    public LongRunningTask(AsyncCommand command, int limit) {
        this.command = command;
        this.limit = limit;

    }

    public void schedule(int millis) {

        final PopupPanel window = Feedback.loading(
                Console.CONSTANTS.common_label_plaseWait(),
                Console.CONSTANTS.common_label_requestProcessed(),
                new Feedback.LoadingCallback() {
                    @Override
                    public void onCancel() {
                        keepRunning = false;
                    }
                });

        Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {
            @Override
            public boolean execute() {

                numAttempts++;

                if(numAttempts>limit)
                {
                    Console.warning("Your request timed out.");
                    keepRunning=false;
                }
                else
                {

                    command.execute(new SimpleCallback() {
                        @Override
                        public void onSuccess(Boolean result) {
                            keepRunning = result;
                        }
                    });
                }

                if(!keepRunning && window!=null)
                    window.hide();

                return keepRunning;
            }
        }, millis);

    }

    public void setMessage(String message) {
        this.message = message;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy