openplans/OpenTripPlanner — pull request #1082 by laurentg (2013-05-17 13:27:59+00:00)
Title: Add periodic refresh to multi-graph auto-discovery mode.

This allow for an easier to use configuration for multi-graph setups. Users just have to copy/update/move/delete graph in disk, and after a few seconds the new graphs are ready to serve or old ones evicted right away.

The auto-discover mode can be used by replacing the current graphService bean by:
-------------------%<-----------------------

-------------------%<-----------------------

Since we need Java7 to have file change notification, we scan every minute (configurable) the directory. Directory scan is rather fast so this should not impact performance too much.

Static spring configuration and auto-discover mode have been split in two classes, as adding periodic refresh leads to have 2 incompatible modes : the semantics of configuring a static list of graph, registering a graph through the web-service and auto-discovering become too complex for a user to understand and a developer to properly handle. And this has probably no proper use case anyway.

File-related common code have been factored out in a decorated class. The decorator pattern is probably not the best one here, but this allow the common class to implement GraphService interface, and lead to less disturbance to the widely used spring configurations in place.

Auto-discovery do not implement web-service interface (you cannot register new graphs). Some of them could be implemented if needed though: registerGraph(String routerId, Graph graph) which could create/replace the file on disk; and evictGraph(String routerId) which could remove the graph from disk.