/** ******************** Member Functions ************************* */ public static ArrivalDepartureGenerator getInstance() { // If the PredictionGenerator hasn't been created yet then do so now if (singleton == null) { singleton = ClassInstantiator.instantiate(className.getValue(), ArrivalDepartureGenerator.class); } return singleton; }
/** * 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); }
/** 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(); }
/** Returns URL to use */ @Override protected String getUrl() { return mbtaCommuterRailFeedUrl.getValue(); }