Exemplo n.º 1
0
  /**
   * Initiates a real-time amigocloud feed. If there is a JSONException while starting connection
   * then will try again every 10 seconds until successful.
   */
  public void startRealtimeWebsockets() {
    logger.info("Starting amigocloud AVL feed");

    int numberOfExceptions = 0;
    boolean exceptionOccurred = false;
    do {
      try {
        // Actually make the connection
        AmigoWebsockets socket =
            new AmigoWebsockets(
                userId.getValue(),
                projectId.getValue(),
                datasetId.getValue(),
                feedUrl.toString(),
                new MyAmigoWebsocketListener(this));
        socket.connect();
        exceptionOccurred = false;
      } catch (JSONException e) {
        ++numberOfExceptions;
        exceptionOccurred = true;

        // If exception has occurred several times then send e-mail to
        // indicate there is an ongoing problem
        if (numberOfExceptions == 3) {
          logger.error(
              Markers.email(),
              "For agencyId={} exception when starting up "
                  + "AmigoCloudAvlModule. {}. numberOfExceptions={}",
              AgencyConfig.getAgencyId(),
              e.getMessage(),
              numberOfExceptions,
              e);
        }

        // Sleep 10 seconds before trying again
        Time.sleep(10 * Time.MS_PER_SEC);
      }
    } while (exceptionOccurred);
  }
Exemplo n.º 2
0
 /** For in case want to test a non-realtime amigocloud feed */
 public void startNonRealtimeWebsockets() {
   AmigoWebsockets socket =
       new AmigoWebsockets(
           userId.getValue(), feedUrl.toString(), new MyAmigoWebsocketListener(this));
   socket.connect();
 }