Example usage for com.google.gwt.user.client Timer scheduleRepeating

List of usage examples for com.google.gwt.user.client Timer scheduleRepeating

Introduction

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

Prototype

public synchronized void scheduleRepeating(final int periodMs) 

Source Link

Document

Schedules a timer that elapses repeatedly.

Usage

From source file:org.sonar.api.web.gwt.client.webservices.SequentialQueries.java

License:Open Source License

@Override
public void execute(final QueryCallBack<VoidResponse> callback) {
    for (AjaxQuery<?> query : queries) {
        query.execute();/* w  w w  . j  a  v  a2 s . co m*/
    }
    Timer queriesMonitor = new Timer() {
        @Override
        public void run() {
            boolean queriesExecuted = true;
            for (AjaxQuery<?> query : queries) {
                if (!query.isCompleted()) {
                    queriesExecuted = false;
                    break;
                }
            }
            if (queriesExecuted) {
                callback.onResponse(new VoidResponse(), null);
                cancel();
            }
        }
    };
    queriesMonitor.scheduleRepeating(sleepTimeBetweenCbChecks);
}

From source file:stroom.dispatch.client.ClientDispatchAsyncImpl.java

License:Apache License

@Inject
public ClientDispatchAsyncImpl(final EventBus eventBus,
        final Provider<ClientSecurityContext> securityContextProvider,
        final DispatchServiceAsync dispatchService) {
    this.eventBus = eventBus;
    this.dispatchService = dispatchService;
    this.applicationInstanceId = RandomId.createDiscrimiator();

    final Timer refreshTimer = new Timer() {
        @Override/*from  w w  w.  j  a  v a 2 s .com*/
        public void run() {
            if (!refreshing) {
                final ClientSecurityContext securityContext = securityContextProvider.get();
                if (securityContext != null && securityContext.isLoggedIn()) {
                    refreshing = true;
                    final RefreshAction action = new RefreshAction();
                    action.setApplicationInstanceId(applicationInstanceId);
                    execute(action, new AsyncCallbackAdaptor<SharedString>() {
                        @Override
                        public void onSuccess(final SharedString result) {
                            if (result != null) {
                                AlertEvent.fireWarn(ClientDispatchAsyncImpl.this, result.toString(),
                                        () -> refreshing = false);
                            } else {
                                refreshing = false;
                            }
                        }

                        @Override
                        public void onFailure(final Throwable caught) {
                            refreshing = false;
                        }
                    });
                }
            }
        }
    };
    // Refresh all actions on the server every minute so that they
    // don't die.
    refreshTimer.scheduleRepeating(ONE_MINUTE);

    // realService = GWT.create(DispatchService.class);
    final String endPointName = GWT.getHostPageBaseURL() + "dispatch.rpc";
    final ServiceDefTarget target = (ServiceDefTarget) dispatchService;
    target.setServiceEntryPoint(endPointName);
}

From source file:stroom.node.client.ClientPropertyCache.java

License:Apache License

@Inject
public ClientPropertyCache(final ClientDispatchAsync dispatcher, final ClientSecurityContext securityContext) {
    this.dispatcher = dispatcher;

    final Timer refreshTimer = new Timer() {
        @Override/*from   w  w w  .  j a  va2 s.c om*/
        public void run() {
            // Don't auto refresh if we are already refreshing.
            if (!refreshing) {
                // Don't auto refresh if we are not logged in as this will keep the user session alive unnecessarily.
                if (securityContext.isLoggedIn()) {
                    refreshing = true;
                    refresh().onSuccess(result -> refreshing = false)
                            .onFailure(throwable -> refreshing = false);
                }
            }
        }
    };

    // Refreshing the client properties keeps them current and also ensures that all actions on the server belonging
    // to the logged in user are refreshed every minute so that the server doesn't try and terminate them.
    refreshTimer.scheduleRepeating(ONE_MINUTE);
}

From source file:us.asciiroth.client.core.Game.java

License:Apache License

public void gameOver(final String url, final boolean hasWon) {
    gameInProgress = false;/*w ww.  j a va2  s  .c  o m*/
    Timer timer = new Timer() {
        private Style style = RootPanel.getBodyElement().getStyle();
        private int i = 0;

        @Override
        public void run() {
            style.setProperty("backgroundColor", Color.random().toString());
            if (!hasWon || i++ >= 20) {
                cancel();
                style.setProperty("backgroundColor", Color.BLACK.toString());
                GameOverDialog dialog = new GameOverDialog();
                dialog.setHTML(player.getScenarioURL() + url);
                DialogManager.get().push(dialog);
            }
        }
    };
    timer.scheduleRepeating(100);
}

From source file:us.softoption.proofs.TGWTRewriteRules.java

License:Open Source License

private void initialize() {
    initializeRulesList();/*from ww  w .  j ava  2 s .c o  m*/
    initializeRulesBox();

    /*to do       fBeforeText.addCaretListener(new CaretListener(){
         public void caretUpdate(CaretEvent e){
           int dot = e.getDot();
           int mark = e.getMark();
           if (dot!=mark)
    doChoice();
           ;}});
    */

    /*we need to act on selection change but don't have any
     * handy listener         
     */

    // Create a new timer
    Timer pollTimer = new Timer() {
        public void run() {
            if (!fBeforeText.getText().equals(fBeforeTextReference.getText())) {
                fBeforeText.setText(fBeforeTextReference.getText());
                //has to be set editable but we don't want eidting
            }

            fSelection = fBeforeText.getSelectedText();
            if (!fSelection.equals(fOldSelection)) { //a change
                if (fSelection.equals(""))
                    fAfterText.setText(fBeforeTextReference.getText());
                //nothing selected set new to old
                else
                    doChoice(); //a selection that may rewrite
                fOldSelection = fSelection.substring(0); //need copy
            }
        }
    };

    pollTimer.scheduleRepeating(1000); // every second

}