Skip to content

Commit afcac8e

Browse files
committed
Nits
1 parent dff3b04 commit afcac8e

23 files changed

+171
-84
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
1. Use `google-java-format` for code formatting.
2+
2. Use wrapper classes instead of primitives. For example, use `Integer` in place of `int`. It helps us in distinguishing, when a value is not set.
3+
3. Use `@Builder` based object construction instead of `new`.
4+
4. Using `lombok` annotations for any new classes.
5+
5. All hardcoded constants appear as a `private static final` variables at the top of the class.

src/main/java/com/exceptionless/exceptionlessclient/configuration/Configuration.java

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,24 @@
77
import java.beans.PropertyChangeSupport;
88

99
public class Configuration {
10-
public static final String USER_AGENT = "exceptionless-java";
10+
private static final String DEFAULT_SERVER_URL = "https://collector.exceptionless.io";
11+
private static final String DEFAULT_HEARTBEAT_SERVER_URL = "https://heartbeat.exceptionless.io";
12+
private static final Long DEFAULT_UPDATE_SETTINGS_WHEN_IDLE_INTERVAL = 12000L;
13+
private static final Integer DEFAULT_SUBMISSION_BATCH_SIZE = 50;
14+
private static final Integer DEFAULT_SUBMISSION_CLIENT_TIMEOUT_IN_MILLIS = 500;
15+
private static final Integer DEFAULT_SETTINGS_CLIENT_TIMEOUT_IN_MILLIS = 500;
16+
17+
public static class Property {
18+
public static final String API_KEY = "apiKey";
19+
public static final String SERVER_URL = "serverUrl";
20+
public static final String HEART_BEAT_SERVER_URL = "heartbeatServerUrl";
21+
public static final String UPDATE_SETTINGS_WHEN_IDLE_INTERVAL =
22+
"updateSettingsWhenIdleInterval";
23+
public static final String SUBMISSION_BATCH_SIZE = "submissionBatchSize";
24+
public static final String SUBMISSION_CLIENT_TIMEOUT_IN_MILLIS =
25+
"submissionClientTimeoutInMillis";
26+
public static final String SETTINGS_CLIENT_TIMEOUT_IN_MILLIS = "settingsClientTimeoutInMillis";
27+
}
1128

1229
@Getter private String apiKey;
1330
@Getter private String serverUrl;
@@ -29,18 +46,25 @@ public Configuration(
2946
Integer submissionClientTimeoutInMillis,
3047
Integer settingsClientTimeoutInMillis) {
3148
this.apiKey = apiKey;
32-
this.serverUrl = serverUrl == null ? "https://collector.exceptionless.io" : serverUrl;
49+
this.serverUrl = serverUrl == null ? DEFAULT_SERVER_URL : serverUrl;
3350
this.heartbeatServerUrl =
3451
heartbeatServerUrl == null
35-
? (serverUrl == null ? "https://heartbeat.exceptionless.io" : serverUrl)
52+
? (serverUrl == null ? DEFAULT_HEARTBEAT_SERVER_URL : serverUrl)
3653
: heartbeatServerUrl;
3754
this.updateSettingsWhenIdleInterval =
38-
updateSettingsWhenIdleInterval == null ? 12000L : updateSettingsWhenIdleInterval;
39-
this.submissionBatchSize = submissionBatchSize == null ? 50 : submissionBatchSize;
55+
updateSettingsWhenIdleInterval == null
56+
? DEFAULT_UPDATE_SETTINGS_WHEN_IDLE_INTERVAL
57+
: updateSettingsWhenIdleInterval;
58+
this.submissionBatchSize =
59+
submissionBatchSize == null ? DEFAULT_SUBMISSION_BATCH_SIZE : submissionBatchSize;
4060
this.submissionClientTimeoutInMillis =
41-
submissionClientTimeoutInMillis == null ? 500 : submissionClientTimeoutInMillis;
61+
submissionClientTimeoutInMillis == null
62+
? DEFAULT_SUBMISSION_CLIENT_TIMEOUT_IN_MILLIS
63+
: submissionClientTimeoutInMillis;
4264
this.settingsClientTimeoutInMillis =
43-
settingsClientTimeoutInMillis == null ? 500 : settingsClientTimeoutInMillis;
65+
settingsClientTimeoutInMillis == null
66+
? DEFAULT_SETTINGS_CLIENT_TIMEOUT_IN_MILLIS
67+
: settingsClientTimeoutInMillis;
4468
this.propertyChangeSupport = new PropertyChangeSupport(this);
4569
}
4670

@@ -55,46 +79,47 @@ public static Configuration defaultConfiguration() {
5579
public void setApiKey(String apiKey) {
5680
String prevValue = this.apiKey;
5781
this.apiKey = apiKey;
58-
propertyChangeSupport.firePropertyChange("apiKey", prevValue, apiKey);
82+
propertyChangeSupport.firePropertyChange(Property.API_KEY, prevValue, apiKey);
5983
}
6084

6185
public void setServerUrl(String serverUrl) {
6286
String prevValue = this.serverUrl;
6387
this.serverUrl = serverUrl;
64-
propertyChangeSupport.firePropertyChange("serverUrl", prevValue, serverUrl);
88+
propertyChangeSupport.firePropertyChange(Property.SERVER_URL, prevValue, serverUrl);
6589
}
6690

67-
6891
public void setHeartbeatServerUrl(String heartbeatServerUrl) {
6992
String prevValue = this.heartbeatServerUrl;
7093
this.heartbeatServerUrl = heartbeatServerUrl;
71-
propertyChangeSupport.firePropertyChange("heartbeatServerUrl", prevValue, heartbeatServerUrl);
94+
propertyChangeSupport.firePropertyChange(
95+
Property.HEART_BEAT_SERVER_URL, prevValue, heartbeatServerUrl);
7296
}
7397

7498
public void setUpdateSettingsWhenIdleInterval(Long updateSettingsWhenIdleInterval) {
7599
Long prevValue = this.updateSettingsWhenIdleInterval;
76100
this.updateSettingsWhenIdleInterval = updateSettingsWhenIdleInterval;
77101
propertyChangeSupport.firePropertyChange(
78-
"updateSettingsWhenIdleInterval", prevValue, updateSettingsWhenIdleInterval);
102+
Property.UPDATE_SETTINGS_WHEN_IDLE_INTERVAL, prevValue, updateSettingsWhenIdleInterval);
79103
}
80104

81105
public void setSubmissionBatchSize(Integer submissionBatchSize) {
82106
Integer prevValue = this.submissionBatchSize;
83107
this.submissionBatchSize = submissionBatchSize;
84-
propertyChangeSupport.firePropertyChange("submissionBatchSize", prevValue, submissionBatchSize);
108+
propertyChangeSupport.firePropertyChange(
109+
Property.SUBMISSION_BATCH_SIZE, prevValue, submissionBatchSize);
85110
}
86111

87112
public void setSubmissionClientTimeoutInMillis(Integer submissionClientTimeoutInMillis) {
88113
Integer prevValue = this.submissionClientTimeoutInMillis;
89114
this.submissionClientTimeoutInMillis = submissionClientTimeoutInMillis;
90115
propertyChangeSupport.firePropertyChange(
91-
"submissionClientTimeoutInMillis", prevValue, submissionClientTimeoutInMillis);
116+
Property.SUBMISSION_CLIENT_TIMEOUT_IN_MILLIS, prevValue, submissionClientTimeoutInMillis);
92117
}
93118

94119
public void setSettingsClientTimeoutInMillis(Integer settingsClientTimeoutInMillis) {
95120
Integer prevValue = this.settingsClientTimeoutInMillis;
96121
this.settingsClientTimeoutInMillis = settingsClientTimeoutInMillis;
97122
propertyChangeSupport.firePropertyChange(
98-
"settingsClientTimeoutInMillis", prevValue, settingsClientTimeoutInMillis);
123+
Property.SETTINGS_CLIENT_TIMEOUT_IN_MILLIS, prevValue, settingsClientTimeoutInMillis);
99124
}
100125
}

src/main/java/com/exceptionless/exceptionlessclient/configuration/ConfigurationManager.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import ch.qos.logback.core.Context;
44
import com.exceptionless.exceptionlessclient.exceptions.InvalidApiKeyException;
5-
import com.exceptionless.exceptionlessclient.services.DefaultLastReferenceIdManager;
6-
import com.exceptionless.exceptionlessclient.services.LastReferenceIdManagerIF;
75
import com.exceptionless.exceptionlessclient.logging.LogCapturerAppender;
86
import com.exceptionless.exceptionlessclient.logging.LogCapturerIF;
97
import com.exceptionless.exceptionlessclient.logging.NullLogCapturer;
@@ -33,6 +31,8 @@
3331

3432
public class ConfigurationManager {
3533
private static final Logger LOG = LoggerFactory.getLogger(ConfigurationManager.class);
34+
private static final Integer API_KEY_MIN_LENGTH = 11;
35+
private static final Integer DEFAULT_HEART_BEAT_INTERVAL_IN_SECS = 30;
3636

3737
@Getter private final EnvironmentInfoCollectorIF environmentInfoCollector;
3838
@Getter private final ErrorParserIF errorParser;
@@ -131,7 +131,8 @@ private void addPropertyChangeListeners() {
131131
}
132132

133133
private void checkApiKeyIsValid() {
134-
if (configuration.getApiKey() != null && configuration.getApiKey().length() > 10) {
134+
if (configuration.getApiKey() != null
135+
&& configuration.getApiKey().length() >= API_KEY_MIN_LENGTH) {
135136
return;
136137
}
137138

@@ -185,31 +186,14 @@ public void addPlugin(EventPluginIF eventPlugin) {
185186
}
186187

187188
public void addPlugin(BiConsumer<EventPluginContext, ConfigurationManager> pluginAction) {
188-
addPlugin(UUID.randomUUID().toString(), 0, pluginAction);
189+
pluginManager.addPlugin(pluginAction);
189190
}
190191

191192
public void addPlugin(
192193
String name,
193194
int priority,
194195
BiConsumer<EventPluginContext, ConfigurationManager> pluginAction) {
195-
addPlugin(
196-
new EventPluginIF() {
197-
@Override
198-
public int getPriority() {
199-
return priority;
200-
}
201-
202-
@Override
203-
public String getName() {
204-
return name;
205-
}
206-
207-
@Override
208-
public void run(
209-
EventPluginContext eventPluginContext, ConfigurationManager configurationManager) {
210-
pluginAction.accept(eventPluginContext, configurationManager);
211-
}
212-
});
196+
pluginManager.addPlugin(name, priority, pluginAction);
213197
}
214198

215199
public void removePlugin(String name) {
@@ -237,7 +221,7 @@ public void setUserIdentity(UserInfo userInfo) {
237221
}
238222

239223
public void useSessions() {
240-
useSessions(30);
224+
useSessions(DEFAULT_HEART_BEAT_INTERVAL_IN_SECS);
241225
}
242226

243227
public void useSessions(int heartbeatIntervalInSecs) {

src/main/java/com/exceptionless/exceptionlessclient/configuration/PluginManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
public class PluginManager {
1818
private static final Logger LOG = LoggerFactory.getLogger(PluginManager.class);
19+
private static final Integer DEFAULT_PLUGIN_PRIORITY = 0;
1920

2021
@Getter private List<EventPluginIF> plugins;
2122

@@ -54,7 +55,7 @@ private void sortPlugins() {
5455
}
5556

5657
public void addPlugin(BiConsumer<EventPluginContext, ConfigurationManager> pluginAction) {
57-
addPlugin(UUID.randomUUID().toString(), 0, pluginAction);
58+
addPlugin(UUID.randomUUID().toString(), DEFAULT_PLUGIN_PRIORITY, pluginAction);
5859
}
5960

6061
public void addPlugin(

src/main/java/com/exceptionless/exceptionlessclient/configuration/PrivateInformationInclusions.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
import java.beans.PropertyChangeSupport;
88

99
public class PrivateInformationInclusions {
10+
public static class Property {
11+
public static final String ALL = "all";
12+
public static final String QUERY_STRING = "queryString";
13+
public static final String POST_DATA = "postData";
14+
public static final String COOKIES = "cookies";
15+
public static final String IP_ADDRESS = "ipAddress";
16+
public static final String MACHINE_NAME = "machineName";
17+
public static final String USER_NAME = "userName";
18+
}
19+
1020
@Getter private Boolean queryString;
1121
@Getter private Boolean postData;
1222
@Getter private Boolean cookies;
@@ -43,42 +53,42 @@ public Boolean isAllIncluded() {
4353
public void applyToAll(Boolean include) {
4454
Boolean prevValue = isAllIncluded();
4555
queryString = postData = cookies = ipAddress = machineName = userName = include;
46-
propertyChangeSupport.firePropertyChange("all", prevValue, include);
56+
propertyChangeSupport.firePropertyChange(Property.ALL, prevValue, include);
4757
}
4858

4959
public void setQueryString(Boolean queryString) {
5060
Boolean prevValue = this.queryString;
5161
this.queryString = queryString;
52-
propertyChangeSupport.firePropertyChange("queryString", prevValue, queryString);
62+
propertyChangeSupport.firePropertyChange(Property.QUERY_STRING, prevValue, queryString);
5363
}
5464

5565
public void setPostData(Boolean postData) {
5666
Boolean prevValue = this.postData;
5767
this.postData = postData;
58-
propertyChangeSupport.firePropertyChange("postData", prevValue, queryString);
68+
propertyChangeSupport.firePropertyChange(Property.POST_DATA, prevValue, queryString);
5969
}
6070

6171
public void setCookies(Boolean cookies) {
6272
Boolean prevValue = this.cookies;
6373
this.cookies = cookies;
64-
propertyChangeSupport.firePropertyChange("cookies", prevValue, queryString);
74+
propertyChangeSupport.firePropertyChange(Property.COOKIES, prevValue, queryString);
6575
}
6676

6777
public void setIpAddress(Boolean ipAddress) {
6878
Boolean prevValue = this.ipAddress;
6979
this.ipAddress = ipAddress;
70-
propertyChangeSupport.firePropertyChange("ipAddress", prevValue, queryString);
80+
propertyChangeSupport.firePropertyChange(Property.IP_ADDRESS, prevValue, queryString);
7181
}
7282

7383
public void setMachineName(Boolean machineName) {
7484
Boolean prevValue = this.machineName;
7585
this.machineName = machineName;
76-
propertyChangeSupport.firePropertyChange("machineName", prevValue, queryString);
86+
propertyChangeSupport.firePropertyChange(Property.MACHINE_NAME, prevValue, queryString);
7787
}
7888

7989
public void setUserName(Boolean userName) {
8090
Boolean prevValue = this.userName;
8191
this.userName = userName;
82-
propertyChangeSupport.firePropertyChange("userName", prevValue, queryString);
92+
propertyChangeSupport.firePropertyChange(Property.USER_NAME, prevValue, queryString);
8393
}
8494
}

src/main/java/com/exceptionless/exceptionlessclient/models/Event.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
import java.util.*;
1818
import java.util.stream.Collectors;
1919

20-
// Warning `SuperBuilder` will not work for any class extending this. This class breaks the chain
20+
// WARNING: `SuperBuilder` will not work for any class extending this. This class breaks the chain
2121
// for customization
2222
@Data
2323
@EqualsAndHashCode(callSuper = true)
2424
public class Event extends Model {
25+
private static final Integer DEFAULT_COUNT = 1;
26+
2527
private String type;
2628
private String source;
2729
private LocalDate date;
@@ -52,14 +54,15 @@ public Event(
5254
this.message = message;
5355
this.geo = geo;
5456
this.value = value;
55-
this.referenceId =
56-
referenceId == null
57-
? String.format("%s-%s", Thread.currentThread().getId(), UUID.randomUUID())
58-
: referenceId;
59-
this.count = count == null ? 1 : count;
57+
this.referenceId = referenceId == null ? getDefaultReferenceId() : referenceId;
58+
this.count = count == null ? DEFAULT_COUNT : count;
6059
initData(data == null ? new HashMap<>() : data, dataExclusions);
6160
}
6261

62+
private String getDefaultReferenceId() {
63+
return String.format("%s-%s", Thread.currentThread().getId(), UUID.randomUUID());
64+
}
65+
6366
private void initData(Map<String, Object> data, Set<String> dataExclusions) {
6467
EventDataFilter eventDataFilter = EventDataFilter.builder().exclusions(dataExclusions).build();
6568
this.data =

src/main/java/com/exceptionless/exceptionlessclient/models/PluginContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import java.net.http.HttpRequest;
99

10-
// Warning `SuperBuilder` will not work for any class extending this. This class breaks the chain
10+
// WARNING: `SuperBuilder` will not work for any class extending this. This class breaks the chain
1111
// for customization
1212
@Data
1313
@EqualsAndHashCode(callSuper = true)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.exceptionless.exceptionlessclient.models.enums;
2+
3+
public enum EnvironmentInfoPropertyKey {
4+
LOAD_AVG("loadavg"),
5+
TMP_DIR("tmpdir"),
6+
UP_TIME("uptime"),
7+
ENDIANESS("endianess");
8+
9+
private final String value;
10+
11+
EnvironmentInfoPropertyKey(String value) {
12+
this.value = value;
13+
}
14+
15+
public String value() {
16+
return value;
17+
}
18+
}

src/main/java/com/exceptionless/exceptionlessclient/plugins/preconfigured/ConfigurationDefaultsPlugin.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
import lombok.Builder;
88

99
public class ConfigurationDefaultsPlugin implements EventPluginIF {
10+
private static final Integer DEFAULT_PRIORITY = 10;
11+
1012
@Builder
1113
public ConfigurationDefaultsPlugin() {}
1214

1315
@Override
1416
public int getPriority() {
15-
return 10;
17+
return DEFAULT_PRIORITY;
1618
}
1719

1820
@Override
1921
public void run(
20-
EventPluginContext eventPluginContext, ConfigurationManager configurationManager) {
22+
EventPluginContext eventPluginContext, ConfigurationManager configurationManager) {
2123
Event event = eventPluginContext.getEvent();
2224
for (String tag : configurationManager.getDefaultTags()) {
2325
event.addTags(tag);

0 commit comments

Comments
 (0)