private void addToMessagesCheckQueue(final MessageWrapper message) {
   if (User.get().getUserId().equals(message.getUserId())) {
     logger.info("Adding message to waiting queue: " + message.getText());
     waitingMessages.put(Duration.currentTimeMillis(), message);
     fireEvent(new MessageInLimboEvent(message));
   }
 }
Пример #2
0
 public String getUrl(int connectionCount) {
   String url = client.getUrl();
   if (client.getSerializer() != null && client.getSerializer().getMode() == SerialMode.DE_RPC) {
     url +=
         (url.contains("?") ? "&" : "?")
             + Constants.MODULE_BASE_PARAMETER
             + '='
             + GWT.getModuleBaseURL()
             + '&'
             + Constants.STRONG_NAME_PARAMETER
             + '='
             + GWT.getPermutationStrongName();
   }
   String className = getClass().getName();
   className = className.substring(className.lastIndexOf('.') + 1);
   String transport = className.substring(0, className.indexOf("CometTransport"));
   return url
       + (url.contains("?") ? "&" : "?")
       + "t="
       + Integer.toString(
               (int) (Duration.currentTimeMillis() % Integer.MAX_VALUE), Character.MAX_RADIX)
           .toUpperCase()
       + "&c="
       + connectionCount
       + "&tr="
       + transport;
 }
 private void resendOldMessages() {
   final Iterator<Entry<Double, Message>> it = waitingMessages.entrySet().iterator();
   while (it.hasNext()) {
     final Entry<Double, Message> next = it.next();
     if (Duration.currentTimeMillis() - next.getKey() > 5000) {
       fireEvent(new RemoveMessageEvent(next.getValue().getId()));
       sendMessage(next.getValue().getText(), false);
       logger.info("Resending message: " + next.getValue().getText());
       it.remove();
     }
   }
 }
Пример #4
0
  /**
   * Outputs the time passed since various events recored in performance.timing if supported by the
   * browser.
   */
  public static void logBootstrapTimings() {
    if (isEnabled()) {
      double now = Duration.currentTimeMillis();

      String[] keys =
          new String[] {
            "navigationStart",
            "unloadEventStart",
            "unloadEventEnd",
            "redirectStart",
            "redirectEnd",
            "fetchStart",
            "domainLookupStart",
            "domainLookupEnd",
            "connectStart",
            "connectEnd",
            "requestStart",
            "responseStart",
            "responseEnd",
            "domLoading",
            "domInteractive",
            "domContentLoadedEventStart",
            "domContentLoadedEventEnd",
            "domComplete",
            "loadEventStart",
            "loadEventEnd"
          };

      LinkedHashMap<String, Double> timings = new LinkedHashMap<>();

      for (String key : keys) {
        double value = getPerformanceTiming(key);
        if (value == 0) {
          // Ignore missing value
          continue;
        }
        timings.put(key, Double.valueOf(now - value));
      }

      if (timings.isEmpty()) {
        getLogger()
            .info(
                "Bootstrap timings not supported, please ensure your browser supports performance.timing");
        return;
      }

      if (getConsumer() != null) {
        getConsumer().addBootstrapData(timings);
      }
    }
  }
Пример #5
0
    @Override
    public void onConnected(int heartbeat, int connectionID) {
      heartbeatTimeout = heartbeat + connectionTimeout;
      lastReceivedTime = Duration.currentTimeMillis();
      this.connectionID = connectionID;
      if (transport instanceof WebSocketCometTransport) {
        webSocketSuccessful = true;
      }

      cancelTimers();
      heartbeatTimer.schedule(heartbeatTimeout);

      doOnConnected(heartbeat, connectionID, this);
    }
Пример #6
0
  public void onBrowserEvent(Event event) {
    double now = Duration.currentTimeMillis();
    // Workaround for Issue_20
    if (lastType.equals(event.getType())
        && now - lastEvnt < 10
        && "body".equalsIgnoreCase(element.getTagName())) {
      return;
    }
    lastEvnt = now;
    lastType = event.getType();

    // Execute the original Gwt listener
    if (getOriginalEventListener() != null && getOriginalEventListener() != this) {
      getOriginalEventListener().onBrowserEvent(event);
    }

    dispatchEvent(event);
  }
  @Override
  public TimingOptions endTimingEvent(
      final String trackerName, final String timingCategory, final String timingVariableName) {
    final String key = getTimingKey(timingCategory, timingVariableName);
    if (timingEvents.containsKey(key)) {
      return sendTiming(
          trackerName,
          timingCategory,
          timingVariableName,
          (int) (Duration.currentTimeMillis() - timingEvents.remove(key)));
    }
    return new AnalyticsOptions(
            new JSONOptionsCallback() {

              @Override
              public void onCallback(final JSONObject options) {
                // Do nothing a timing event was ended before it was started.  This is here just to
                // stop a crash.
              }
            })
        .timingOptions(timingCategory, timingVariableName, 0);
  }
Пример #8
0
 @Override
 public void onMessage(List<?> messages) {
   lastReceivedTime = Duration.currentTimeMillis();
   doOnMessage(messages, this);
 }
Пример #9
0
 @Override
 public void onAfterRefresh() {
   lastReceivedTime = Duration.currentTimeMillis();
 }
Пример #10
0
 @Override
 public void onRefresh() {
   lastReceivedTime = Duration.currentTimeMillis();
   doOnRefresh(this);
 }
Пример #11
0
 @Override
 public void onHeartbeat() {
   lastReceivedTime = Duration.currentTimeMillis();
   doOnHeartbeat(this);
 }
Пример #12
0
 public long nanoTime() {
   return (long) Duration.currentTimeMillis();
 }
Пример #13
0
  /** To animate a seed from one pit to another */
  @Override
  public void animateFromPitToPit(
      PlayerColor startSide,
      int startCol,
      PlayerColor endSide,
      int endCol,
      double delay,
      boolean finalAnimation) {
    int startRow = startSide.isNorth() ? 0 : 1;
    int actualStartCol = (startRow == 0) ? 5 - startCol : startCol;
    int endRow = endSide.isNorth() ? 0 : 1;
    int actualEndCol = (endRow == 0) ? 5 - endCol : endCol;

    AbsolutePanel startPanel = (AbsolutePanel) gameGrid.getWidget(startRow, actualStartCol);
    final Image seed;
    seed = (Image) startPanel.getWidget(startPanel.getWidgetCount() - 2);
    int startXStartPanel = startPanel.getWidgetLeft(seed);
    int startYStartPanel = startPanel.getWidgetTop(seed);
    int startX =
        2
            + actualStartCol * 2
            + TREASURE_CHEST_WIDTH
            + PIT_WIDTH * actualStartCol
            + PADDING * (actualStartCol * 2 + 3)
            + startXStartPanel;
    int startY = 2 + PADDING + startRow * (PIT_HEIGHT + 2 * PADDING + 2) + startYStartPanel;

    AbsolutePanel endPanel;
    int[] endPointEndPanel;
    int endXEndPanel;
    int endYEndPanel;
    int endX;
    int endY;
    if (endCol < 6) {
      endPanel = (AbsolutePanel) gameGrid.getWidget(endRow, actualEndCol);
      endPointEndPanel = getTargetPoint(endPanel.getWidgetCount() - 1);
      endXEndPanel = endPointEndPanel[0];
      endYEndPanel = endPointEndPanel[1];
      endX =
          2
              + actualEndCol * 2
              + TREASURE_CHEST_WIDTH
              + PIT_WIDTH * actualEndCol
              + PADDING * (actualEndCol * 2 + 3)
              + endXEndPanel;
      endY = 2 + PADDING + endRow * (PIT_HEIGHT + 2 * PADDING + 2) + endYEndPanel;
    } else {
      Grid hGrid = endRow == 0 ? treasureGridN : treasureGridS;
      endPanel = (AbsolutePanel) hGrid.getWidget(0, 0);
      endPointEndPanel = getTargetPointTreasureChest(endPanel.getWidgetCount() - 1);
      endXEndPanel = endPointEndPanel[0];
      endYEndPanel = endPointEndPanel[1];
      endX =
          2
              + PADDING
              + (TREASURE_CHEST_WIDTH + PIT_WIDTH * 6 + PADDING * 14 + 6 * 2) * endRow
              + endXEndPanel;
      endY = 2 + PADDING + endYEndPanel;
    }

    animation =
        new SeedMovingAnimation(
            seed,
            gameImages.redSeed(),
            startPanel,
            endPanel,
            startXStartPanel,
            startYStartPanel,
            endXEndPanel,
            endYEndPanel,
            startX,
            startY,
            endX,
            endY,
            finalAnimation,
            this,
            dotSound);
    animation.run(1000, Duration.currentTimeMillis() + delay);
  }
Пример #14
0
    @Override
    public void onBrowserEvent(Event event) {
      switch (event.getTypeInt()) {
        case Event.ONMOUSEDOWN:
          mouseDown = true;

          /*
           * Resize glassElem to take up the entire scrollable window area,
           * which is the greater of the scroll size and the client size.
           */
          int width = Math.max(Window.getClientWidth(), Document.get().getScrollWidth());
          int height = Math.max(Window.getClientHeight(), Document.get().getScrollHeight());
          glassElem.getStyle().setHeight(height, Unit.PX);
          glassElem.getStyle().setWidth(width, Unit.PX);
          Document.get().getBody().appendChild(glassElem);

          offset = getEventPosition(event) - getAbsolutePosition();
          Event.setCapture(getElement());
          event.preventDefault();
          break;

        case Event.ONMOUSEUP:
          mouseDown = false;

          glassElem.removeFromParent();

          // Handle double-clicks.
          // Fake them since the double-click event aren't fired.
          if (this.toggleDisplayAllowed) {
            double now = Duration.currentTimeMillis();
            // if (now - this.lastClick < DOUBLE_CLICK_TIMEOUT) {
            now = 0;
            LayoutData layout = (LayoutData) target.getLayoutData();
            if (layout.size == 0) {
              // Restore the old size.
              // setAssociatedWidgetSize(layout.oldSize);
              setAssociatedWidgetSize(200);

              setStyleName("gwt-SplitLayoutPanel-myHDragger_right");
            } else {
              /*
               * Collapse to size 0. We change the size instead of hiding the
               * widget because hiding the widget can cause issues if the
               * widget contains a flash component.
               */
              layout.oldSize = layout.size;
              setAssociatedWidgetSize(0);
              setStyleName("gwt-SplitLayoutPanel-myHDragger_left");
            }
            // }
            this.lastClick = now;
          }

          Event.releaseCapture(getElement());
          event.preventDefault();
          break;

        case Event.ONMOUSEMOVE:
          if (mouseDown) {
            //            int size;
            //            if (reverse) {
            //              size = getTargetPosition() + getTargetSize() - getSplitterSize()
            //                  - getEventPosition(event) + offset;
            //            } else {
            //              size = getEventPosition(event) - getTargetPosition() - offset;
            //            }
            //            ((LayoutData) target.getLayoutData()).hidden = false;
            //            setAssociatedWidgetSize(size);
            event.preventDefault();
          }
          break;
      }
    }
 @Override
 public void startTimingEvent(final String timingCategory, final String timingVariableName) {
   timingEvents.put(timingCategory + ":" + timingVariableName, Duration.currentTimeMillis());
 }