Search in sources :

Example 1 with Refreshable

use of org.onebusaway.container.refresh.Refreshable in project onebusaway-application-modules by camsys.

the class BundleSearchServiceImpl method init.

@PostConstruct
@Refreshable(dependsOn = { RefreshableResources.ROUTE_COLLECTIONS_DATA, RefreshableResources.TRANSIT_GRAPH })
public void init() {
    Runnable initThread = new Runnable() {

        @Override
        public void run() {
            while (!_initialized) {
                try {
                    Thread.sleep(1 * 1000);
                } catch (InterruptedException e) {
                    return;
                }
            }
            _log.info("building cache");
            Map<String, List<String>> tmpSuggestions = Collections.synchronizedMap(new HashMap<String, List<String>>());
            Map<String, List<CoordinateBounds>> agencies = _transitDataService.getAgencyIdsWithCoverageArea();
            for (String agency : agencies.keySet()) {
                ListBean<RouteBean> routes = _transitDataService.getRoutesForAgencyId(agency);
                for (RouteBean route : routes.getList()) {
                    String shortName = route.getShortName();
                    generateInputsForString(tmpSuggestions, shortName, "\\s+");
                }
                ListBean<String> stopIds = _transitDataService.getStopIdsForAgencyId(agency);
                for (String stopId : stopIds.getList()) {
                    if (_transitDataService.stopHasRevenueService(agency, stopId)) {
                        AgencyAndId agencyAndId = AgencyAndIdLibrary.convertFromString(stopId);
                        generateInputsForString(tmpSuggestions, agencyAndId.getId(), null);
                    }
                }
            }
            suggestions = tmpSuggestions;
            _log.info("complete");
        }
    };
    new Thread(initThread).start();
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) List(java.util.List) Refreshable(org.onebusaway.container.refresh.Refreshable) PostConstruct(javax.annotation.PostConstruct)

Example 2 with Refreshable

use of org.onebusaway.container.refresh.Refreshable in project onebusaway-application-modules by camsys.

the class BundleConfigDao method setup.

@PostConstruct
@Refreshable(dependsOn = RefreshableResources.TRANSIT_GRAPH)
public void setup() throws IOException, ClassNotFoundException {
    _meta = null;
    File path = _bundle.getBundleMetadataPath();
    _log.info("looking for metadata file " + path);
    if (path.exists()) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        BundleMetadata meta = null;
        try {
            meta = mapper.readValue(path, BundleMetadata.class);
        } catch (Exception any) {
            _log.error("reading metadata failed:", any);
        }
        if (meta != null) {
            _meta = meta;
        }
    } else {
        _log.error(" did not find metadata file " + path);
    }
}
Also used : File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) IOException(java.io.IOException) BundleMetadata(org.onebusaway.transit_data.model.config.BundleMetadata) Refreshable(org.onebusaway.container.refresh.Refreshable) PostConstruct(javax.annotation.PostConstruct)

Example 3 with Refreshable

use of org.onebusaway.container.refresh.Refreshable in project onebusaway-application-modules by camsys.

the class TransitGraphDaoImpl method setup.

@PostConstruct
@Refreshable(dependsOn = RefreshableResources.TRANSIT_GRAPH)
public void setup() throws IOException, ClassNotFoundException {
    File path = _bundle.getTransitGraphPath();
    if (_graph != null) {
        TransitGraphImpl graph = (TransitGraphImpl) _graph;
        graph.empty();
        _graph = null;
    }
    if (path.exists()) {
        TransitGraphImpl graph = ObjectSerializationLibrary.readObject(path);
        graph.initialize();
        _graph = graph;
    } else {
        _graph = new TransitGraphImpl();
    }
}
Also used : File(java.io.File) Refreshable(org.onebusaway.container.refresh.Refreshable) PostConstruct(javax.annotation.PostConstruct)

Example 4 with Refreshable

use of org.onebusaway.container.refresh.Refreshable in project onebusaway-application-modules by camsys.

the class RefreshableCalendarServiceImpl method setup.

@PostConstruct
@Refreshable(dependsOn = RefreshableResources.CALENDAR_DATA)
public void setup() throws IOException, ClassNotFoundException {
    File path = _bundle.getCalendarServiceDataPath();
    if (path.exists()) {
        CalendarServiceData data = ObjectSerializationLibrary.readObject(path);
        setData(data);
    } else {
        setData(new CalendarServiceData());
    }
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) File(java.io.File) Refreshable(org.onebusaway.container.refresh.Refreshable) PostConstruct(javax.annotation.PostConstruct)

Example 5 with Refreshable

use of org.onebusaway.container.refresh.Refreshable in project onebusaway-application-modules by camsys.

the class RouteCollectionSearchServiceImpl method initialize.

@PostConstruct
@Refreshable(dependsOn = RefreshableResources.ROUTE_COLLECTION_SEARCH_DATA)
public void initialize() throws IOException {
    File path = _bundle.getRouteSearchIndexPath();
    if (path.exists()) {
        IndexReader reader = IndexReader.open(path);
        _searcher = new IndexSearcher(reader);
    } else {
        _searcher = null;
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) IndexReader(org.apache.lucene.index.IndexReader) File(java.io.File) Refreshable(org.onebusaway.container.refresh.Refreshable) PostConstruct(javax.annotation.PostConstruct)

Aggregations

PostConstruct (javax.annotation.PostConstruct)9 Refreshable (org.onebusaway.container.refresh.Refreshable)9 File (java.io.File)6 Envelope (com.vividsolutions.jts.geom.Envelope)2 STRtree (com.vividsolutions.jts.index.strtree.STRtree)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 IndexReader (org.apache.lucene.index.IndexReader)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)2 IOException (java.io.IOException)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 CalendarServiceData (org.onebusaway.gtfs.model.calendar.CalendarServiceData)1 RouteBean (org.onebusaway.transit_data.model.RouteBean)1 BundleMetadata (org.onebusaway.transit_data.model.config.BundleMetadata)1