Skip to content

Commit

Permalink
fix: checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbuon committed Aug 16, 2024
1 parent 757f065 commit d21e120
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 24 deletions.
13 changes: 9 additions & 4 deletions rollbar-java/src/main/java/com/rollbar/notifier/RollbarBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import com.rollbar.notifier.wrapper.RollbarThrowableWrapper;
import com.rollbar.notifier.wrapper.ThrowableWrapper;

import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
Expand Down Expand Up @@ -76,7 +78,8 @@ public void recordManualEventFor(Level level, String message) {
}

/**
* Record navigation telemetry event with from (origin) and to (destination).({@link TelemetryType#NAVIGATION})
* Record navigation telemetry event with from (origin) and to (destination).
* ({@link TelemetryType#NAVIGATION}).
*
* @param level the TelemetryEvent severity (e.g. {@link Level#DEBUG}).
* @param from the starting point (e.g. "SettingView").
Expand All @@ -87,11 +90,13 @@ public void recordNavigationEventFor(Level level, String from, String to) {
}

/**
* Record network telemetry event with method, url, and status code.({@link TelemetryType#NETWORK})
* Record network telemetry event with method, url, and status code.
* ({@link TelemetryType#NETWORK}).
*
* @param level the TelemetryEvent severity (e.g. {@link Level#DEBUG}).
* @param method the verb used (e.g. "POST").
* @param url the api url (e.g. "<a href="http://rollbar.com/test/api">http://rollbar.com/test/api</a>").
* @param url the api url (e.g. "<a href="http://rollbar.com/test/api">
* http://rollbar.com/test/api</a>").
* @param statusCode the response status code (e.g. "404").
*/
public void recordNetworkEventFor(Level level, String method, String url, String statusCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public class ConfigBuilder {

private TelemetryEventTracker telemetryEventTracker;

private final static int MINIMUM_CAPACITY_FOR_TELEMETRY_EVENTS = 1;
private static final int MINIMUM_CAPACITY_FOR_TELEMETRY_EVENTS = 1;

private final static int DEFAULT_CAPACITY_FOR_TELEMETRY_EVENTS = 10;
private static final int DEFAULT_CAPACITY_FOR_TELEMETRY_EVENTS = 10;

private final static int MAXIMUM_CAPACITY_FOR_TELEMETRY_EVENTS = 50;
private static final int MAXIMUM_CAPACITY_FOR_TELEMETRY_EVENTS = 50;

/**
* Constructor with an access token.
Expand Down Expand Up @@ -552,7 +552,8 @@ public Config build() {
}

if (telemetryEventTracker == null) {
telemetryEventTracker = new RollbarTelemetryEventTracker(new TimestampProvider(), maximumTelemetryData);
telemetryEventTracker =
new RollbarTelemetryEventTracker(new TimestampProvider(), maximumTelemetryData);
}

return new ConfigImpl(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
* Default {@link TelemetryEventTracker}.
*/
public class RollbarTelemetryEventTracker implements TelemetryEventTracker {
private final int maximumTelemetryData;
private final Queue<TelemetryEvent> telemetryEvents = new ConcurrentLinkedQueue<>();
Expand All @@ -24,6 +27,12 @@ public class RollbarTelemetryEventTracker implements TelemetryEventTracker {
private static final String NETWORK_KEY_URL = "url";
private static final String NETWORK_KEY_STATUS_CODE = "status_code";

/**
* Construct a {@link RollbarTelemetryEventTracker}.
*
* @param timestampProvider A Provider of timestamps for the events
* @param maximumTelemetryData Maximum number of accumulated events
*/
public RollbarTelemetryEventTracker(
Provider<Long> timestampProvider,
int maximumTelemetryData
Expand All @@ -32,37 +41,48 @@ public RollbarTelemetryEventTracker(
this.maximumTelemetryData = maximumTelemetryData;
}

@Override
public List<TelemetryEvent> dump() {
List<TelemetryEvent> events = new ArrayList<>(telemetryEvents);
telemetryEvents.clear();
return events;
}

@Override
public void recordLogEventFor(Level level, Source source, String message) {
Map<String, String> body = new HashMap<>();
body.put(LOG_KEY_MESSAGE, message);
addEvent(new TelemetryEvent(TelemetryType.LOG, level, timestampProvider.provide(), source, body));
addEvent(new TelemetryEvent(TelemetryType.LOG, level, getTimestamp(), source, body));
}

@Override
public void recordManualEventFor(Level level, Source source, String message) {
Map<String, String> body = new HashMap<>();
body.put(LOG_KEY_MESSAGE, message);
addEvent(new TelemetryEvent(TelemetryType.MANUAL, level, timestampProvider.provide(), source, body));
addEvent(new TelemetryEvent(TelemetryType.MANUAL, level, getTimestamp(), source, body));
}

@Override
public void recordNavigationEventFor(Level level, Source source, String from, String to) {
Map<String, String> body = new HashMap<>();
body.put(NAVIGATION_KEY_FROM, from);
body.put(NAVIGATION_KEY_TO, to);
addEvent(new TelemetryEvent(TelemetryType.NAVIGATION, level, timestampProvider.provide(), source, body));
addEvent(new TelemetryEvent(TelemetryType.NAVIGATION, level, getTimestamp(), source, body));
}

public void recordNetworkEventFor(Level level, Source source, String method, String url, String statusCode) {
@Override
public void recordNetworkEventFor(
Level level,
Source source,
String method,
String url,
String statusCode
) {
Map<String, String> body = new HashMap<>();
body.put(NETWORK_KEY_METHOD, method);
body.put(NETWORK_KEY_URL, url);
body.put(NETWORK_KEY_STATUS_CODE, statusCode);
addEvent(new TelemetryEvent(TelemetryType.NETWORK, level, timestampProvider.provide(), source, body));
addEvent(new TelemetryEvent(TelemetryType.NETWORK, level, getTimestamp(), source, body));
}

private void addEvent(TelemetryEvent telemetryEvent) {
Expand All @@ -71,4 +91,8 @@ private void addEvent(TelemetryEvent telemetryEvent) {
}
telemetryEvents.add(telemetryEvent);
}

private long getTimestamp() {
return timestampProvider.provide();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public interface TelemetryEventTracker {

/**
* Dump all the events recorded
* Dump all the events recorded.
*/
List<TelemetryEvent> dump();

Expand All @@ -33,7 +33,8 @@ public interface TelemetryEventTracker {
void recordManualEventFor(Level level, Source source, String message);

/**
* Record navigation telemetry event with from (origin) and to (destination).({@link TelemetryType#NAVIGATION}) .
* Record navigation telemetry event with from (origin) and to (destination).
* ({@link TelemetryType#NAVIGATION}).
*
* @param level the TelemetryEvent severity (e.g. {@link Level#DEBUG}).
* @param source the {@link Source} this event is recorded from (e.g. {@link Source#CLIENT}).
Expand All @@ -43,12 +44,14 @@ public interface TelemetryEventTracker {
void recordNavigationEventFor(Level level, Source source, String from, String to);

/**
* Record network telemetry event with method, url, and status code.({@link TelemetryType#NETWORK}).
* Record network telemetry event with method, url, and status code.
* ({@link TelemetryType#NETWORK}).
*
* @param level the TelemetryEvent severity (e.g. {@link Level#DEBUG}).
* @param source the {@link Source} this event is recorded from (e.g. {@link Source#CLIENT}).
* @param method the verb used (e.g. "POST").
* @param url the api url (e.g. "<a href="http://rollbar.com/test/api">http://rollbar.com/test/api</a>").
* @param url the api url (e.g. "<a href="http://rollbar.com/test/api">
* http://rollbar.com/test/api</a>").
* @param statusCode the response status code (e.g. "404").
*/
void recordNetworkEventFor(Level level, Source source, String method, String url, String statusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.rollbar.jvmti.ThrowableCache;
import com.rollbar.notifier.wrapper.RollbarThrowableWrapper;
import com.rollbar.notifier.wrapper.ThrowableWrapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -23,11 +24,10 @@ public class BodyFactory {
/**
* Builds the body for the throwable and description supplied.
*
* @param throwable the throwable.
* @param throwable the throwable.
* @param description the description.
* @return the body.
*
* @deprecated Replaced by {@link #from(ThrowableWrapper, String)}.
* @deprecated Replaced by {@link #from(ThrowableWrapper, String)}.
*/
@Deprecated
public Body from(Throwable throwable, String description) {
Expand All @@ -42,7 +42,7 @@ public Body from(Throwable throwable, String description) {
* supplied.
*
* @param throwableWrapper the throwable proxy.
* @param description the description.
* @param description the description.
* @return the body.
*/
public Body from(ThrowableWrapper throwableWrapper, String description) {
Expand All @@ -55,11 +55,15 @@ public Body from(ThrowableWrapper throwableWrapper, String description) {
* supplied and telemetry events.
*
* @param throwableWrapper the throwable proxy.
* @param description the description.
* @param telemetryEvents the telemetry events.
* @param description the description.
* @param telemetryEvents the telemetry events.
* @return the body.
*/
public Body from(ThrowableWrapper throwableWrapper, String description, List<TelemetryEvent> telemetryEvents) {
public Body from(
ThrowableWrapper throwableWrapper,
String description,
List<TelemetryEvent> telemetryEvents
) {
Body.Builder builder = new Body.Builder().telemetryEvents(telemetryEvents);
return from(throwableWrapper, description, builder);
}
Expand Down

0 comments on commit d21e120

Please sign in to comment.