List of usage examples for com.google.gwt.user.client Timer Timer
Timer
From source file:com.calclab.emite.core.client.services.gwt.GWTScheduler.java
License:Open Source License
public static void schedule(final int msecs, final ScheduledAction action) { new Timer() { @Override// ww w .j a v a 2 s . c o m public void run() { action.run(); } }.schedule(msecs); }
From source file:com.calclab.emite.core.session.SessionReconnect.java
License:Open Source License
@Override public void onSessionStatusChanged(final SessionStatusChangedEvent event) { if (SessionStatus.connecting.equals(event.getStatus())) { shouldReconnect = false;//from w w w .ja v a 2 s . c o m } else if (SessionStatus.isDisconnected(event.getStatus()) && shouldReconnect) { if (lastSuccessfulCredentials != null) { final double seconds = Math.pow(2, reconnectionAttempts - 1); new Timer() { @Override public void run() { logger.info("Reconnecting..."); if (shouldReconnect) { shouldReconnect = false; session.login(lastSuccessfulCredentials); } } }.schedule((int) (1000 * seconds)); logger.info("Reconnecting in " + seconds + " seconds."); } } else if (SessionStatus.isReady(event.getStatus())) { logger.finer("CLEAR RECONNECTION ATTEMPS"); reconnectionAttempts = 0; } }
From source file:com.calclab.emite.example.pingpong.client.events.SessionEventsSupervisor.java
License:Open Source License
protected void trackSessionLength(final XmppSession session, final PingPongDisplay display) { if (session.isReady()) { final long currentTime = System.currentTimeMillis(); final int totalSeconds = (int) ((currentTime - currentSessionLogin) / 1000); final int minutes = totalSeconds / 60; final int seconds = totalSeconds % 60; display.getSessionStatus()// ww w . j av a 2s .c o m .setText(" Session activity for " + minutes + " minutes and " + seconds + " seconds."); if (refreshTime < 10000) { refreshTime += 500; } new Timer() { @Override public void run() { trackSessionLength(session, display); } }.schedule(refreshTime); } else { display.getSessionStatus().setText(" Session is not ready."); } }
From source file:com.calclab.emite.example.pingpong.client.logic.PingChatPresenter.java
License:Open Source License
protected void sendPing(final Chat chat) { if (chat.isReady()) { pings++;/*from w w w .j a v a 2 s . c o m*/ waitTime += 500; final String body = "Ping " + pings + " [" + System.currentTimeMillis() + "]"; chat.send(new Message(body)); display.print("SENT: " + body, Style.sent); new Timer() { @Override public void run() { sendPing(chat); } }.schedule(waitTime); } }
From source file:com.calclab.emite.example.pingpong.client.logic.PingInviteRoomPresenter.java
License:Open Source License
@Override public void start() { display.printHeader("This is ping invite room example", Style.title); display.printHeader("You need to open the pong invite room example page in order to run the example", Style.important);/*w w w . ja v a2s. c o m*/ display.printHeader("Room: " + roomUri, Style.info); display.printHeader("Ping to: " + otherUri, Style.info); new ChatManagerEventsSupervisor(roomManager, display); new RoomManagerEventsSupervisor(roomManager, display); final Room room = (Room) roomManager.open(roomUri); // When the room is ready, we invite other room.addChatStateChangedHandler(true, new StateChangedHandler() { @Override public void onStateChanged(final StateChangedEvent event) { if (event.is(ChatStates.ready)) { display.print("Room ready. Sending invitation to " + otherUri, Style.important); pings++; room.sendInvitationTo(otherUri, "ping invite " + pings); } } }); room.addOccupantChangedHandler(new OccupantChangedHandler() { @Override public void onOccupantChanged(final OccupantChangedEvent event) { final boolean isOtherOccupant = event.getOccupant().getUserUri().equalsNoResource(otherUri); if (isOtherOccupant) { if (event.isRemoved()) { display.print("Invited removed... waiting to send invitation", Style.important); new Timer() { @Override public void run() { display.print("Sending invitation", Style.important); pings++; time += 1000; room.sendInvitationTo(otherUri, "ping invite " + pings); } }.schedule(time); } else if (event.isAdded()) { display.print("Change subject", Style.important); RoomSubject.requestSubjectChange(room, "Subject ping" + pings); } } } }); }
From source file:com.calclab.emite.example.pingpong.client.logic.PingSessionPresenter.java
License:Open Source License
private void sendPing() { if (session.isReady()) { pings++;//from w w w . jav a 2 s. c om waitTime += 500; final String body = "Ping " + pings + " [" + System.currentTimeMillis() + "]"; session.send(new Message(body, other)); output.print("SENT: " + body, Style.sent); new Timer() { @Override public void run() { sendPing(); } }.schedule(waitTime); } }
From source file:com.calclab.emite.example.pingpong.client.logic.PongInviteRoomPresenter.java
License:Open Source License
private void closeRoom(final RoomManager manager, final Chat room) { new Timer() { @Override//from www .j a v a 2 s . c o m public void run() { display.print("We close the room: " + room.getURI(), Style.important); time += 2000; manager.close(room); } }.schedule(time); }
From source file:com.calclab.emite.reconnect.client.SessionReconnect.java
License:Open Source License
@Inject public SessionReconnect(final XmppConnection connection, final XmppSession session, final SASLManager saslManager) { shouldReconnect = false;/*from w w w. ja va2 s . c om*/ reconnectionAttempts = 0; logger.info("RECONNECT BEHAVIOUR"); saslManager.addAuthorizationResultHandler(new AuthorizationResultHandler() { @Override public void onAuthorization(final AuthorizationResultEvent event) { lastSuccessfulCredentials = event.getCredentials(); } }); session.addSessionStateChangedHandler(true, new StateChangedHandler() { @Override public void onStateChanged(final StateChangedEvent event) { if (event.is(SessionStates.connecting)) { shouldReconnect = false; } else if (event.is(SessionStates.disconnected) && shouldReconnect) { if (lastSuccessfulCredentials != null) { final double seconds = Math.pow(2, reconnectionAttempts - 1); new Timer() { @Override public void run() { logger.info("Reconnecting..."); if (shouldReconnect) { shouldReconnect = false; session.login(lastSuccessfulCredentials); } } }.schedule((int) (1000 * seconds)); logger.info("Reconnecting in " + seconds + " seconds."); } } else if (event.is(SessionStates.ready)) { logger.finer("CLEAR RECONNECTION ATTEMPS"); reconnectionAttempts = 0; } } }); connection.addConnectionStateChangedHandler(new ConnectionStateChangedHandler() { @Override public void onStateChanged(final ConnectionStateChangedEvent event) { if (event.is(ConnectionState.error) || event.is(ConnectionState.waitingForRetry)) { shouldReconnect(); } } }); }
From source file:com.calclab.emiteuimodule.client.chat.ChatStateTimer.java
License:Open Source License
public ChatStateTimer(final ChatStatePresenter presenter) { timer = new Timer() { @Override//from w w w . j av a 2s . com public void run() { presenter.onTime(); } }; }
From source file:com.calclab.emiteuimodule.client.dialog.MultiChatPanel.java
License:Open Source License
public void focusInput() { new Timer() { @Override// w w w . jav a 2 s. c o m public void run() { input.focus(); } }.schedule(50); }