18
18
19
19
package com .graphhopper .gtfs .dropwizard ;
20
20
21
+ import com .graphhopper .reader .gtfs .GtfsStorage ;
21
22
import com .graphhopper .reader .gtfs .RealtimeFeed ;
22
23
import io .dropwizard .ConfiguredBundle ;
23
24
import io .dropwizard .client .HttpClientBuilder ;
24
25
import io .dropwizard .setup .Bootstrap ;
25
26
import io .dropwizard .setup .Environment ;
26
27
import org .apache .http .client .HttpClient ;
28
+ import org .glassfish .hk2 .api .Factory ;
27
29
import org .glassfish .hk2 .utilities .binding .AbstractBinder ;
28
30
31
+ import javax .inject .Inject ;
29
32
import javax .inject .Singleton ;
30
33
31
34
public class RealtimeBundle implements ConfiguredBundle <RealtimeBundleConfiguration > {
@@ -36,17 +39,45 @@ public void initialize(Bootstrap<?> bootstrap) {
36
39
37
40
@ Override
38
41
public void run (RealtimeBundleConfiguration configuration , Environment environment ) {
39
- final HttpClient httpClient = new HttpClientBuilder (environment )
40
- .using (configuration .gtfsrealtime ().getHttpClientConfiguration ())
41
- .build ("gtfs-realtime-feed-loader" );
42
- environment .jersey ().register (new AbstractBinder () {
43
- @ Override
44
- protected void configure () {
45
- bind (httpClient ).to (HttpClient .class );
46
- bind (configuration ).to (RealtimeBundleConfiguration .class );
47
- bindFactory (RealtimeFeedLoadingCache .class , Singleton .class ).to (RealtimeFeed .class );
48
- }
49
- });
42
+ if (configuration .gtfsrealtime ().getFeeds ().isEmpty ()) {
43
+ environment .jersey ().register (new AbstractBinder () {
44
+ @ Override
45
+ protected void configure () {
46
+ bindFactory (EmptyRealtimeFeedFactory .class ).to (RealtimeFeed .class ).in (Singleton .class );
47
+ }
48
+ });
49
+ } else {
50
+ final HttpClient httpClient = new HttpClientBuilder (environment )
51
+ .using (configuration .gtfsrealtime ().getHttpClientConfiguration ())
52
+ .build ("gtfs-realtime-feed-loader" );
53
+ environment .jersey ().register (new AbstractBinder () {
54
+ @ Override
55
+ protected void configure () {
56
+ bind (httpClient ).to (HttpClient .class );
57
+ bind (configuration ).to (RealtimeBundleConfiguration .class );
58
+ bindFactory (RealtimeFeedLoadingCache .class , Singleton .class ).to (RealtimeFeed .class );
59
+ }
60
+ });
61
+ }
50
62
}
51
63
64
+ private static class EmptyRealtimeFeedFactory implements Factory <RealtimeFeed > {
65
+
66
+ private final GtfsStorage staticGtfs ;
67
+
68
+ @ Inject
69
+ EmptyRealtimeFeedFactory (GtfsStorage staticGtfs ) {
70
+ this .staticGtfs = staticGtfs ;
71
+ }
72
+
73
+ @ Override
74
+ public RealtimeFeed provide () {
75
+ return RealtimeFeed .empty (staticGtfs );
76
+ }
77
+
78
+ @ Override
79
+ public void dispose (RealtimeFeed realtimeFeed ) {
80
+
81
+ }
82
+ }
52
83
}
0 commit comments