11package com .exceptionless .exceptionlessclient .configuration ;
22
33import ch .qos .logback .core .Context ;
4+ import com .exceptionless .exceptionlessclient .enums .EventPropertyKey ;
45import com .exceptionless .exceptionlessclient .exceptions .InvalidApiKeyException ;
56import com .exceptionless .exceptionlessclient .logging .LogCapturerAppender ;
67import com .exceptionless .exceptionlessclient .logging .LogCapturerIF ;
78import com .exceptionless .exceptionlessclient .logging .NullLogCapturer ;
89import com .exceptionless .exceptionlessclient .models .EventPluginContext ;
910import com .exceptionless .exceptionlessclient .models .UserInfo ;
10- import com .exceptionless .exceptionlessclient .enums .EventPropertyKey ;
1111import com .exceptionless .exceptionlessclient .plugins .EventPluginIF ;
1212import com .exceptionless .exceptionlessclient .plugins .preconfigured .HeartbeatPlugin ;
1313import com .exceptionless .exceptionlessclient .queue .DefaultEventQueue ;
1414import com .exceptionless .exceptionlessclient .queue .EventQueueIF ;
15- import com .exceptionless .exceptionlessclient .services .*;
15+ import com .exceptionless .exceptionlessclient .services .DefaultLastReferenceIdManager ;
16+ import com .exceptionless .exceptionlessclient .services .LastReferenceIdManagerIF ;
1617import com .exceptionless .exceptionlessclient .settings .DefaultSettingsClient ;
1718import com .exceptionless .exceptionlessclient .settings .SettingsClientIF ;
1819import com .exceptionless .exceptionlessclient .settings .SettingsManager ;
2627import org .slf4j .Logger ;
2728import org .slf4j .LoggerFactory ;
2829
30+ import java .beans .PropertyChangeSupport ;
2931import java .util .*;
3032import java .util .function .BiConsumer ;
3133import java .util .function .Consumer ;
3436public class ConfigurationManager {
3537 private static final Integer API_KEY_MIN_LENGTH = 11 ;
3638 private static final Integer DEFAULT_HEART_BEAT_INTERVAL_IN_SECS = 30 ;
39+ private static final String DEFAULT_SERVER_URL = "https://collector.exceptionless.io" ;
40+ private static final String DEFAULT_HEARTBEAT_SERVER_URL = "https://heartbeat.exceptionless.io" ;
41+ private static final String DEFAULT_CONFIG_SERVER_URL = "https://config.exceptionless.io" ;
42+ private static final Long DEFAULT_UPDATE_SETTINGS_WHEN_IDLE_INTERVAL = 12000L ;
43+ private static final Integer DEFAULT_SUBMISSION_BATCH_SIZE = 50 ;
44+ private static final Integer DEFAULT_SUBMISSION_CLIENT_TIMEOUT_IN_MILLIS = 500 ;
45+ private static final Integer DEFAULT_SETTINGS_CLIENT_TIMEOUT_IN_MILLIS = 500 ;
46+
47+ public static class Property {
48+ public static final String API_KEY = "apiKey" ;
49+ public static final String SERVER_URL = "serverUrl" ;
50+ public static final String CONFIG_SERVER_URL = "configServerUrl" ;
51+ public static final String HEART_BEAT_SERVER_URL = "heartbeatServerUrl" ;
52+ public static final String UPDATE_SETTINGS_WHEN_IDLE_INTERVAL =
53+ "updateSettingsWhenIdleInterval" ;
54+ public static final String SUBMISSION_BATCH_SIZE = "submissionBatchSize" ;
55+ public static final String SUBMISSION_CLIENT_TIMEOUT_IN_MILLIS =
56+ "submissionClientTimeoutInMillis" ;
57+ public static final String SETTINGS_CLIENT_TIMEOUT_IN_MILLIS = "settingsClientTimeoutInMillis" ;
58+ }
3759
3860 @ Getter private final LastReferenceIdManagerIF lastReferenceIdManager ;
3961 @ Getter private final SubmissionClientIF submissionClient ;
@@ -48,6 +70,15 @@ public class ConfigurationManager {
4870 private final Set <String > dataExclusions ;
4971 private final PluginManager pluginManager ;
5072 @ Getter private final StorageProviderIF storageProvider ;
73+ @ Getter private ValueProvider <String > apiKey ;
74+ @ Getter private ValueProvider <String > serverUrl ;
75+ @ Getter private ValueProvider <String > heartbeatServerUrl ;
76+ @ Getter private ValueProvider <String > configServerUrl ;
77+ @ Getter private ValueProvider <Long > updateSettingsWhenIdleInterval ;
78+ @ Getter private ValueProvider <Integer > submissionBatchSize ;
79+ @ Getter private ValueProvider <Integer > submissionClientTimeoutInMillis ;
80+ @ Getter private ValueProvider <Integer > settingsClientTimeoutInMillis ;
81+ private final PropertyChangeSupport propertyChangeSupport ;
5182
5283 @ Builder
5384 public ConfigurationManager (
@@ -59,7 +90,15 @@ public ConfigurationManager(
5990 EventQueueIF queue ,
6091 Configuration configuration ,
6192 Integer maxQueueItems ,
62- Integer processingIntervalInSecs ) {
93+ Integer processingIntervalInSecs ,
94+ String apiKey ,
95+ String serverUrl ,
96+ String configServerUrl ,
97+ String heartbeatServerUrl ,
98+ Long updateSettingsWhenIdleInterval ,
99+ Integer submissionBatchSize ,
100+ Integer submissionClientTimeoutInMillis ,
101+ Integer settingsClientTimeoutInMillis ) {
63102 this .lastReferenceIdManager =
64103 lastReferenceIdManager == null
65104 ? DefaultLastReferenceIdManager .builder ().build ()
@@ -101,14 +140,46 @@ public ConfigurationManager(
101140 this .onChangedHandlers = new ArrayList <>();
102141 this .dataExclusions = new HashSet <>();
103142 this .privateInformationInclusions = PrivateInformationInclusions .builder ().build ();
143+ this .apiKey = ValueProvider .of (apiKey );
144+ this .serverUrl =
145+ serverUrl == null ? ValueProvider .of (DEFAULT_SERVER_URL ) : ValueProvider .of (serverUrl );
146+ this .heartbeatServerUrl =
147+ heartbeatServerUrl == null
148+ ? (serverUrl == null
149+ ? ValueProvider .of (DEFAULT_HEARTBEAT_SERVER_URL )
150+ : ValueProvider .of (serverUrl ))
151+ : ValueProvider .of (heartbeatServerUrl );
152+ this .configServerUrl =
153+ configServerUrl == null
154+ ? (serverUrl == null
155+ ? ValueProvider .of (DEFAULT_CONFIG_SERVER_URL )
156+ : ValueProvider .of (serverUrl ))
157+ : ValueProvider .of (configServerUrl );
158+ this .updateSettingsWhenIdleInterval =
159+ updateSettingsWhenIdleInterval == null
160+ ? ValueProvider .of (DEFAULT_UPDATE_SETTINGS_WHEN_IDLE_INTERVAL )
161+ : ValueProvider .of (updateSettingsWhenIdleInterval );
162+ this .submissionBatchSize =
163+ submissionBatchSize == null
164+ ? ValueProvider .of (DEFAULT_SUBMISSION_BATCH_SIZE )
165+ : ValueProvider .of (submissionBatchSize );
166+ this .submissionClientTimeoutInMillis =
167+ submissionClientTimeoutInMillis == null
168+ ? ValueProvider .of (DEFAULT_SUBMISSION_CLIENT_TIMEOUT_IN_MILLIS )
169+ : ValueProvider .of (submissionClientTimeoutInMillis );
170+ this .settingsClientTimeoutInMillis =
171+ settingsClientTimeoutInMillis == null
172+ ? ValueProvider .of (DEFAULT_SETTINGS_CLIENT_TIMEOUT_IN_MILLIS )
173+ : ValueProvider .of (settingsClientTimeoutInMillis );
174+ this .propertyChangeSupport = new PropertyChangeSupport (this );
104175 checkApiKeyIsValid ();
105176 addPropertyChangeListeners ();
106177 addLogCapturer (logCatpurer );
107178 }
108179
109180 private void addPropertyChangeListeners () {
110181 this .privateInformationInclusions .addPropertyChangeListener (ignored -> changed ());
111- this .configuration .addPropertyChangeListener (ignored -> changed ());
182+ this .propertyChangeSupport .addPropertyChangeListener (ignored -> changed ());
112183 this .settingsManager .addPropertyChangeListener (ignored -> changed ());
113184 }
114185
@@ -133,6 +204,67 @@ private void addLogCapturer(LogCapturerIF logCatpurer) {
133204 logBackRootLogger .addAppender (appender );
134205 }
135206
207+ public void setApiKey (String apiKey ) {
208+ String prevValue = this .apiKey .get ();
209+ this .apiKey .update (apiKey );
210+ propertyChangeSupport .firePropertyChange (Configuration .Property .API_KEY , prevValue , apiKey );
211+ }
212+
213+ public void setServerUrl (String serverUrl ) {
214+ String prevValue = this .serverUrl .get ();
215+ this .serverUrl .update (serverUrl );
216+ propertyChangeSupport .firePropertyChange (
217+ Configuration .Property .SERVER_URL , prevValue , serverUrl );
218+ }
219+
220+ public void setConfigServerUrl (String configServerUrl ) {
221+ String prevValue = this .configServerUrl .get ();
222+ this .configServerUrl .update (configServerUrl );
223+ propertyChangeSupport .firePropertyChange (
224+ Configuration .Property .CONFIG_SERVER_URL , prevValue , configServerUrl );
225+ }
226+
227+ public void setHeartbeatServerUrl (String heartbeatServerUrl ) {
228+ String prevValue = this .heartbeatServerUrl .get ();
229+ this .heartbeatServerUrl .update (heartbeatServerUrl );
230+ propertyChangeSupport .firePropertyChange (
231+ Configuration .Property .HEART_BEAT_SERVER_URL , prevValue , heartbeatServerUrl );
232+ }
233+
234+ public void setUpdateSettingsWhenIdleInterval (Long updateSettingsWhenIdleInterval ) {
235+ Long prevValue = this .updateSettingsWhenIdleInterval .get ();
236+ this .updateSettingsWhenIdleInterval .update (updateSettingsWhenIdleInterval );
237+ propertyChangeSupport .firePropertyChange (
238+ Configuration .Property .UPDATE_SETTINGS_WHEN_IDLE_INTERVAL ,
239+ prevValue ,
240+ updateSettingsWhenIdleInterval );
241+ }
242+
243+ public void setSubmissionBatchSize (Integer submissionBatchSize ) {
244+ Integer prevValue = this .submissionBatchSize .get ();
245+ this .submissionBatchSize .update (submissionBatchSize );
246+ propertyChangeSupport .firePropertyChange (
247+ Configuration .Property .SUBMISSION_BATCH_SIZE , prevValue , submissionBatchSize );
248+ }
249+
250+ public void setSubmissionClientTimeoutInMillis (Integer submissionClientTimeoutInMillis ) {
251+ Integer prevValue = this .submissionClientTimeoutInMillis .get ();
252+ this .submissionClientTimeoutInMillis .update (submissionClientTimeoutInMillis );
253+ propertyChangeSupport .firePropertyChange (
254+ Configuration .Property .SUBMISSION_CLIENT_TIMEOUT_IN_MILLIS ,
255+ prevValue ,
256+ submissionClientTimeoutInMillis );
257+ }
258+
259+ public void setSettingsClientTimeoutInMillis (Integer settingsClientTimeoutInMillis ) {
260+ Integer prevValue = this .settingsClientTimeoutInMillis .get ();
261+ this .settingsClientTimeoutInMillis .update (settingsClientTimeoutInMillis );
262+ propertyChangeSupport .firePropertyChange (
263+ Configuration .Property .SETTINGS_CLIENT_TIMEOUT_IN_MILLIS ,
264+ prevValue ,
265+ settingsClientTimeoutInMillis );
266+ }
267+
136268 public void addDefaultTags (String ... tags ) {
137269 defaultTags .addAll (Arrays .asList (tags ));
138270 }
0 commit comments