Skip to content

Commit d0e88ca

Browse files
committed
Update examples to use Async
Update examples to use Async.
1 parent fbeac96 commit d0e88ca

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Add us as a dependancy to your project's maven pom:
1212
<dependency>
1313
<groupId>io.trakerr</groupId>
1414
<artifactId>trakerr-java-client</artifactId>
15-
<version>1.0.2</version>
15+
<version>1.1.0</version>
1616
<scope>compile</scope>
1717
</dependency>
1818
```
@@ -71,7 +71,7 @@ Then you can simply catch an exception like so:
7171
} catch (Exception e) {
7272
// First argument is the classification ("Error", "Warn" etc.), you can also pass a custom classification if required
7373
//client.sendException("Error", e); For a syncronous call
74-
client.sendExceptionAsync("Error", e)
74+
client.sendExceptionAsync(AppEvent.LogLevelEnum.WARNING, null, e, null);
7575
}
7676
```
7777

@@ -107,7 +107,11 @@ Afterwards, you can create your own app event:
107107
exceptionEvent.setCustomProperties(customProperties);
108108

109109
// send the event
110-
client.sendEventAsync(exceptionEvent);
110+
try {
111+
client.sendEventAsync(errevnt,null);
112+
} catch (ApiException senderr) {
113+
senderr.printStackTrace();
114+
}
111115
}
112116
```
113117

@@ -137,9 +141,7 @@ And then simply send the error. You may omit imports and the exception handling
137141

138142
AppEvent event = client.createAppEvent("debug", "foo", "bar");
139143
try {
140-
ApiResponse<Void> response = client.sendEvent(event);
141-
142-
System.out.println("Sent event: " + response.getStatusCode() + ", data: " + response.toString());
144+
client.sendEventAsync(event, null);
143145
} catch (ApiException e) {
144146
e.printStackTrace();
145147
}

src/main/java/io/trakerr/client/CpuUsageTracker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.lang.management.ManagementFactory;
44

55
class CpuUsageTracker {
6-
public static CpuUsageTracker CPU_USAGE_TRACKER = new CpuUsageTracker(5000);
6+
public static CpuUsageTracker CPU_USAGE_TRACKER = new CpuUsageTracker(1000);
77

88
private CpuUsageTrackerThread cpuTracker;
99

src/main/java/io/trakerr/client/TrakerrClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ public class TrakerrClient {
2222
private static final ApiCallback<Void> NULL_CALLBACK = new ApiCallback<Void>() {
2323
@Override
2424
public void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
25+
System.out.println(statusCode);
2526

2627
}
2728

2829
@Override
2930
public void onSuccess(Void result, int statusCode, Map<String, List<String>> responseHeaders) {
30-
31+
System.out.println(statusCode);
3132
}
3233

3334
@Override

test/main/java/testapp/SampleTrakerrApp.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
import io.trakerr.client.*;
44
import io.trakerr.ApiException;
5-
import io.trakerr.ApiResponse;
5+
//import io.trakerr.ApiResponse; For synchronized calls.
66
import io.trakerr.model.AppEvent;
77

88
import io.trakerr.model.CustomData;
99
import io.trakerr.model.CustomStringData;
1010
import org.apache.log4j.Logger;
1111

12+
import java.io.BufferedReader;
13+
import java.io.IOException;
14+
import java.io.InputStreamReader;
15+
1216
import java.util.concurrent.*;
1317

1418
public class SampleTrakerrApp {
@@ -32,7 +36,7 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
3236
try {
3337
throw new Exception("This is a test exception.");
3438
} catch(Exception e) {
35-
client.sendExceptionAsync(AppEvent.LogLevelEnum.WARNING, null, e, TrakerrClient.NULL_CALLBACK);
39+
client.sendExceptionAsync(AppEvent.LogLevelEnum.WARNING, null, e, null);
3640
System.out.println("Test exception sent.");
3741
}
3842

@@ -46,9 +50,7 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
4650
errevnt.eventSession("20");
4751

4852
try {
49-
ApiResponse<Void> response = client.sendEvent(errevnt);
50-
51-
System.out.println("Sent event: " + response.getStatusCode() + ", data: " + response.toString());
53+
client.sendEventAsync(errevnt,null);
5254
} catch (ApiException senderr) {
5355
senderr.printStackTrace();
5456
}
@@ -66,13 +68,17 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
6668

6769
event.customProperties(new CustomData().stringData(msg));
6870
try {
69-
ApiResponse<Void> response = client.sendEvent(event);
70-
71-
System.out.println("Sent event: " + response.getStatusCode() + ", data: " + response.toString());
71+
client.sendEventAsync(event, null);
7272
} catch (ApiException e) {
7373
e.printStackTrace();
7474
}
7575

76+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
77+
try {
78+
br.readLine();
79+
} catch (IOException e){
80+
//user input wait gone wrong.
81+
}
7682
System.exit(0);
7783
}
7884
}

0 commit comments

Comments
 (0)