View Javadoc

1   package com.atlassian.johnson.config;
2   
3   import com.atlassian.johnson.event.ApplicationEventCheck;
4   import com.atlassian.johnson.event.EventCheck;
5   import com.atlassian.johnson.event.EventLevel;
6   import com.atlassian.johnson.event.EventType;
7   import com.atlassian.johnson.event.RequestEventCheck;
8   import com.atlassian.johnson.setup.ContainerFactory;
9   import com.atlassian.johnson.setup.DefaultContainerFactory;
10  import com.atlassian.johnson.setup.DefaultSetupConfig;
11  import com.atlassian.johnson.setup.SetupConfig;
12  
13  import javax.annotation.Nonnull;
14  import java.util.Collections;
15  import java.util.List;
16  import java.util.Map;
17  
18  import static com.google.common.base.Preconditions.checkNotNull;
19  
20  /**
21   * A default implementation of {@link JohnsonConfig} which may be used as a failsafe when no other configuration is
22   * available.
23   * <p>
24   * All URIs are {@link #isIgnoredPath(String) ignored} by this implementation. All collection-returning properties are
25   * implemented to return empty, immutable collections. All other methods generally return {@code null}, except for:
26   * <ul>
27   * <li>{@link SetupConfig} is provided by {@link DefaultSetupConfig}</li>
28   * <li>{@link ContainerFactory} is provided by {@link DefaultContainerFactory}</li>
29   * </ul>
30   * This class cannot be instantiated. A single, immutable instance is available via {@link #getInstance()}.
31   *
32   * @since 2.0
33   */
34  public final class DefaultJohnsonConfig implements JohnsonConfig {
35  
36      private static final DefaultJohnsonConfig instance = new DefaultJohnsonConfig();
37  
38      private final ContainerFactory containerFactory;
39      private final SetupConfig setupConfig;
40  
41      private DefaultJohnsonConfig() {
42          containerFactory = new DefaultContainerFactory();
43          setupConfig = new DefaultSetupConfig();
44      }
45  
46      /**
47       * Retrieves the immutable singleton instance of the default configuration.
48       *
49       * @return the default configuration singleton
50       */
51      @Nonnull
52      public static JohnsonConfig getInstance() {
53          return instance;
54      }
55  
56      /**
57       * Always empty but non-{@code null}.
58       *
59       * @return an empty list
60       */
61      @Nonnull
62      @Override
63      public List<ApplicationEventCheck> getApplicationEventChecks() {
64          return Collections.emptyList();
65      }
66  
67      /**
68       * Always an instance of {@link DefaultContainerFactory}.
69       *
70       * @return a default container factory
71       */
72      @Nonnull
73      @Override
74      public ContainerFactory getContainerFactory() {
75          return containerFactory;
76      }
77  
78      /**
79       * Always {@code "/unavailable"}. {@link #isIgnoredPath(String)} always returns {@code true}, so this path
80       * should never be accessed; Johnson processing is bypassed for all paths.
81       *
82       * @return {@code "/unavailable"}
83       */
84      @Nonnull
85      @Override
86      public String getErrorPath() {
87          return "/unavailable";
88      }
89  
90      /**
91       * Always {@code null}.
92       *
93       * @param id ignored
94       * @return {@code null}
95       */
96      @Override
97      public EventCheck getEventCheck(int id) {
98          return null;
99      }
100 
101     /**
102      * Always empty but non-{@code null}.
103      *
104      * @return an empty list
105      */
106     @Nonnull
107     @Override
108     public List<EventCheck> getEventChecks() {
109         return Collections.emptyList();
110     }
111 
112     /**
113      * Always {@code null}.
114      *
115      * @param level ignored
116      * @return {@code null}
117      */
118     @Override
119     public EventLevel getEventLevel(@Nonnull String level) {
120         checkNotNull(level, "level");
121 
122         return null;
123     }
124 
125     /**
126      * Always {@code null}.
127      *
128      * @param type ignored
129      * @return {@code null}
130      */
131     @Override
132     public EventType getEventType(@Nonnull String type) {
133         checkNotNull(type, "type");
134 
135         return null;
136     }
137 
138     /**
139      * Always empty but non-{@code null}.
140      *
141      * @return an empty list
142      */
143     @Nonnull
144     @Override
145     public List<String> getIgnorePaths() {
146         return Collections.emptyList();
147     }
148 
149     /**
150      * Always empty but non-{@code null}.
151      *
152      * @return an empty map
153      */
154     @Nonnull
155     @Override
156     public Map<String, String> getParams() {
157         return Collections.emptyMap();
158     }
159 
160     /**
161      * Always empty but non-{@code null}.
162      *
163      * @return an empty list
164      */
165     @Nonnull
166     @Override
167     public List<RequestEventCheck> getRequestEventChecks() {
168         return Collections.emptyList();
169     }
170 
171     /**
172      * Always an instance of {@link DefaultSetupConfig}.
173      */
174     @Nonnull
175     @Override
176     public SetupConfig getSetupConfig() {
177         return setupConfig;
178     }
179 
180     /**
181      * Always {@code "/setup"}. The default configuration is always setup, so this path should never be accessed.
182      *
183      * @return {@code "/setup"}
184      */
185     @Nonnull
186     @Override
187     public String getSetupPath() {
188         return "/setup";
189     }
190 
191     /**
192      * Always {@code true}. This has the net effect of disabling Johnson, because all URIs included for filtering will
193      * be ignored and events will not be processed for them.
194      *
195      * @param uri ignored
196      * @return {@code true}
197      */
198     @Override
199     public boolean isIgnoredPath(@Nonnull String uri) {
200         checkNotNull(uri, "uri");
201 
202         return true;
203     }
204 }