Package org.onebusaway.transit_data_federation.services.realtime

Examples of org.onebusaway.transit_data_federation.services.realtime.VehicleLocationCacheEntry


   ****/

  @Override
  public VehicleLocationCacheElements getRecordForVehicleId(
      AgencyAndId vehicleId) {
    VehicleLocationCacheEntry entry = _entriesByVehicleId.get(vehicleId);
    if (entry == null)
      return null;
    return entry.getElements();
  }
View Full Code Here


    Set<AgencyAndId> vehicleIds = _vehicleIdsByBlockInstance.get(blockInstance);

    List<VehicleLocationCacheElements> records = new ArrayList<VehicleLocationCacheElements>();
    if (vehicleIds != null) {
      for (AgencyAndId vehicleId : vehicleIds) {
        VehicleLocationCacheEntry record = _entriesByVehicleId.get(vehicleId);

        if (record != null && record.getBlockInstance().equals(blockInstance))
          records.add(record.getElements());
      }
    }

    return records;
  }
View Full Code Here

    AgencyAndId vehicleId = record.getVehicleId();

    while (true) {

      VehicleLocationCacheEntry newCacheEntry = new VehicleLocationCacheEntry(
          blockInstance);

      VehicleLocationCacheEntry cacheEntry = _entriesByVehicleId.putIfAbsent(
          vehicleId, newCacheEntry);

      if (cacheEntry == null) {

        cacheEntry = newCacheEntry;

        /**
         * Since we're adding a new entry, we indicate the connection between
         * this block instance and vehicleId
         */
        ConcurrentCollectionsLibrary.addToMapValueSet(
            _vehicleIdsByBlockInstance, blockInstance, vehicleId);
      }

      /**
       * If the block instance of a vehicle has changed mid-stream, we close off
       * the cache entry and remove the block=>vid mapping
       */
      if (cacheEntry.isClosedBecauseBlockInstanceChanged(blockInstance)) {

        _entriesByVehicleId.remove(vehicleId);

        ConcurrentCollectionsLibrary.removeFromMapValueSet(
            _vehicleIdsByBlockInstance, cacheEntry.getBlockInstance(),
            vehicleId);

        continue;
      }

      /**
       * If the element failed to add because the entry is closed, we loop.
       * Someone closed the entry while we were in the process of requesting it
       * from the map. On the next loop, it should no longer be in the map.
       */
      if (!cacheEntry.addElement(record, scheduledBlockLocation, samples))
        continue;

      BlockInstance existingBlockInstance = cacheEntry.getBlockInstance();
      if (!blockInstance.equals(existingBlockInstance))
        ConcurrentCollectionsLibrary.removeFromMapValueSet(
            _vehicleIdsByBlockInstance, existingBlockInstance, vehicleId);

      // Ensure the block => vehicle mapping is set

      return cacheEntry.getElements();

    }
  }
View Full Code Here

  }

  @Override
  public void clearRecordsForVehicleId(AgencyAndId vehicleId) {

    VehicleLocationCacheEntry record = _entriesByVehicleId.remove(vehicleId);

    if (record != null) {
      ConcurrentCollectionsLibrary.removeFromMapValueSet(
          _vehicleIdsByBlockInstance, record.getBlockInstance(), vehicleId);
    }
  }
View Full Code Here

    while (it.hasNext()) {

      Entry<AgencyAndId, VehicleLocationCacheEntry> entry = it.next();
      AgencyAndId vehicleId = entry.getKey();
      VehicleLocationCacheEntry cacheEntry = entry.getValue();

      if (cacheEntry.closeIfStale(time)) {

        if (_log.isDebugEnabled())
          _log.debug("pruning block location record cache for vehicle="
              + vehicleId + " block=" + cacheEntry.getBlockInstance());
        it.remove();
        ConcurrentCollectionsLibrary.removeFromMapValueSet(
            _vehicleIdsByBlockInstance, cacheEntry.getBlockInstance(),
            vehicleId);
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.onebusaway.transit_data_federation.services.realtime.VehicleLocationCacheEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.