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

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

Introduction

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

Prototype

public synchronized void schedule(int delayMs) 

Source Link

Document

Schedules a timer to elapse in the future.

Usage

From source file:hu.akarnokd.reactive4java.util.DefaultGwtScheduler.java

License:Apache License

@Override
public Closeable schedule(final Runnable run, long initialDelay, final long betweenDelay) {
    final Timer outerTimer = new Timer() {
        /** The inner timer. */
        final Timer timer = new Timer() {
            @Override//from   w w  w.  j  a va  2  s.  c o m
            public void run() {
                try {
                    run.run();
                } catch (Throwable ex) {
                    timer.cancel();
                }
            }
        };

        @Override
        public void run() {
            timer.run();
            timer.scheduleRepeating((int) (betweenDelay / 1000000L));
        }

        @Override
        public void cancel() {
            timer.cancel();
            super.cancel();
        }
    };
    outerTimer.schedule((int) (initialDelay / 1000000L));
    return new Closeable() {
        @Override
        public void close() throws IOException {
            outerTimer.cancel();
        }
    };
}

From source file:hu.akarnokd.reactive4java.util.DefaultScheduler.java

License:Apache License

@Override
public Closeable schedule(final Runnable run) {
    final Timer timer = new Timer() {
        @Override/*ww  w .  ja va2  s  . co  m*/
        public void run() {
            try {
                run.run();
            } finally {
                Thread.interrupted(); // clear interrupt flag
            }
        }
    };
    timer.schedule(1);
    return new Closeable() {
        @Override
        public void close() throws IOException {
            Thread.currentThread().interrupt();
            timer.cancel();
        }
    };
}

From source file:hu.akarnokd.reactive4java.util.DefaultScheduler.java

License:Apache License

@Override
public Closeable schedule(final Runnable run, long delay) {
    final Timer timer = new Timer() {
        @Override//from w w w. ja  va2s .  co m
        public void run() {
            try {
                run.run();
            } finally {
                Thread.interrupted(); // clear interrupt flag
            }
        }
    };
    timer.schedule((int) (delay / 1000000L));
    return new Closeable() {
        @Override
        public void close() throws IOException {
            Thread.currentThread().interrupt();
            timer.cancel();
        }
    };
}

From source file:hu.akarnokd.reactive4java.util.DefaultScheduler.java

License:Apache License

@Override
public Closeable schedule(final Runnable run, long initialDelay, final long betweenDelay) {
    final Timer outerTimer = new Timer() {
        /** The inner timer. */
        final Timer timer = new Timer() {
            @Override/*from ww w.  j av  a2  s  .com*/
            public void run() {
                try {
                    run.run();
                } catch (Throwable ex) {
                    Thread.currentThread().interrupt();
                }
                if (Thread.interrupted()) {
                    timer.cancel();
                }
            }
        };

        @Override
        public void run() {
            try {
                run.run();
                if (!Thread.interrupted()) {
                    timer.scheduleRepeating((int) (betweenDelay / 1000000L));
                }
            } catch (Throwable ex) {

            }
        }

        @Override
        public void cancel() {
            Thread.currentThread().interrupt();
            timer.cancel();
            super.cancel();
        }
    };
    outerTimer.schedule((int) (initialDelay / 1000000L));
    return new Closeable() {
        @Override
        public void close() throws IOException {
            outerTimer.cancel();
        }
    };
}

From source file:io.apiman.manager.ui.client.local.pages.admin.GatewayTestResultDialog.java

License:Apache License

/**
 * Shut down the dialog.  Do this in a timer to give the animation a chance to work.
 *///from w  w  w. j a v a  2  s  .c  o m
protected void shutdown() {
    this.getElement().removeAttribute("id"); //$NON-NLS-1$
    Timer timer = new Timer() {
        @Override
        public void run() {
            rootPanel.remove(GatewayTestResultDialog.this);
        }
    };
    timer.schedule(2000);
}

From source file:io.apiman.manager.ui.client.local.pages.app.CopyApiEndpointDialog.java

License:Apache License

/**
 * Shut down the dialog.  Do this in a timer to give the animation a chance to work.
 *///from  w  w w.j a v  a2  s . c  o m
protected void shutdown() {
    this.getElement().removeAttribute("id"); //$NON-NLS-1$
    Timer timer = new Timer() {
        @Override
        public void run() {
            rootPanel.remove(CopyApiEndpointDialog.this);
        }
    };
    timer.schedule(2000);
}

From source file:io.apiman.manager.ui.client.local.services.ConfigurationService.java

License:Apache License

/**
 * Starts a timer that will refresh the configuration's bearer token
 * periodically./*from  ww w. j  a va 2s .  c  o  m*/
 */
private void startTokenRefreshTimer() {
    Timer timer = new Timer() {
        @Override
        public void run() {
            GWT.log("Refreshing auth token."); //$NON-NLS-1$

            final String url = GWT.getHostPageBaseURL() + "rest/tokenRefresh"; //$NON-NLS-1$
            RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    @Override
                    public void onResponseReceived(Request request, Response response) {
                        if (response.getStatusCode() != 200) {
                            GWT.log("[001] Authentication token refresh failure: " + url); //$NON-NLS-1$
                        } else {
                            BearerTokenCredentialsBean bean = new BearerTokenCredentialsBean();
                            JSONObject root = JSONParser.parseStrict(response.getText()).isObject();
                            bean.setToken(root.get("token").isString().stringValue()); //$NON-NLS-1$
                            bean.setRefreshPeriod((int) root.get("refreshPeriod").isNumber().doubleValue()); //$NON-NLS-1$
                            configuration.getApi().getAuth().setBearerToken(bean);
                        }
                        startTokenRefreshTimer();
                    }

                    @Override
                    public void onError(Request request, Throwable exception) {
                        GWT.log("[002] Authentication token refresh failure: " + url); //$NON-NLS-1$
                    }
                });
            } catch (RequestException e) {
                GWT.log("Authentication token refresh failed!"); //$NON-NLS-1$
            }
        }
    };
    timer.schedule(configuration.getApi().getAuth().getBearerToken().getRefreshPeriod() * 1000);
}

From source file:io.apiman.manager.ui.client.local.widgets.ConfirmationDialog.java

License:Apache License

/**
 * Shut down the dialog.  Do this in a timer to give the animation a chance to work.
 */// ww  w  .j av  a 2 s.  co m
protected void shutdown() {
    this.getElement().removeAttribute("id"); //$NON-NLS-1$
    Timer timer = new Timer() {
        @Override
        public void run() {
            rootPanel.remove(ConfirmationDialog.this);
        }
    };
    timer.schedule(2000);
}

From source file:it.bz.tis.sasabus.html5.shared.ui.map.SASAbusMap.java

License:Open Source License

public void toggle() {
    this.addStyleName("anim-left");
    if (this.mapOpen) {
        this.removeStyleName("show");
    } else {/*from w  w  w . ja va 2s .co m*/
        this.addStyleName("show");
    }
    this.mapOpen = !this.mapOpen;
    Timer removeAnim = new Timer() {
        @Override
        public void run() {
            SASAbusMap.this.removeStyleName("anim-left");
        }
    };
    removeAnim.schedule(1000);
}

From source file:it.bz.tis.sasabus.html5.shared.ui.menu.Menu.java

License:Open Source License

public void show() {
    if (!this.menuOpen) {
        this.addStyleName("anim-left");
        this.addStyleName("show");
        this.menuOpen = !this.menuOpen;
        Timer removeAnim = new Timer() {
            @Override/*from ww w .  j  a  v a2s . co  m*/
            public void run() {
                Menu.this.removeStyleName("anim-left");
            }
        };
        removeAnim.schedule(1000);
    }
}