Skip to content

Commit f3e2a2c

Browse files
feat/async http transporter, internal logger, withDebig flag to enable internal logs
1 parent 120af4c commit f3e2a2c

17 files changed

Lines changed: 429 additions & 52 deletions

File tree

.idea/workspace.xml

Lines changed: 69 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
<maven.compiler.target>8</maven.compiler.target>
2020
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2121
<apache.httpclient.version>4.5.13</apache.httpclient.version>
22+
<apache.httpcore.version>4.4.14</apache.httpcore.version>
23+
<apache.httpasync.version>4.1.4</apache.httpasync.version>
2224
<jackson.databind.version>2.13.0</jackson.databind.version>
25+
<mockito.core.version>3.11.2</mockito.core.version>
26+
<slf4j.api.version>1.7.36</slf4j.api.version>
2327
</properties>
2428

2529
</project>

traceo-sdk-core/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
<artifactId>httpclient</artifactId>
2424
<version>${apache.httpclient.version}</version>
2525
</dependency>
26+
<dependency>
27+
<groupId>org.apache.httpcomponents</groupId>
28+
<artifactId>httpcore</artifactId>
29+
<version>${apache.httpcore.version}</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.apache.httpcomponents</groupId>
33+
<artifactId>httpasyncclient</artifactId>
34+
<version>${apache.httpasync.version}</version>
35+
</dependency>
2636
<dependency>
2737
<groupId>com.fasterxml.jackson.core</groupId>
2838
<artifactId>jackson-databind</artifactId>
@@ -34,6 +44,22 @@
3444
<version>4.13.1</version>
3545
<scope>test</scope>
3646
</dependency>
47+
<dependency>
48+
<groupId>org.mockito</groupId>
49+
<artifactId>mockito-core</artifactId>
50+
<version>${mockito.core.version}</version>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.slf4j</groupId>
55+
<artifactId>slf4j-simple</artifactId>
56+
<version>1.7.21</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.slf4j</groupId>
60+
<artifactId>slf4j-api</artifactId>
61+
<version>${slf4j.api.version}</version> <!-- {x-version-update;org.slf4j:slf4j-api;external_dependency} -->
62+
</dependency>
3763
</dependencies>
3864
<build>
3965
<plugins>

traceo-sdk-core/src/main/java/com/traceo/sdk/builder/ClientCoreConfiguration.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ public class ClientCoreConfiguration {
66

77
private String host = null;
88

9+
private boolean isEnabled = true;
10+
11+
private boolean isDebug = false;
12+
913
public ClientCoreConfiguration() {}
1014

1115
public ClientCoreConfiguration(ClientCoreConfiguration configuration) {
1216
this.apiKey = configuration.getApiKey();
1317
this.host = configuration.getHost();
18+
this.isEnabled = configuration.isEnabled();
19+
this.isDebug = configuration.isDebug();
1420
}
1521

1622
public String getApiKey() {
@@ -28,4 +34,20 @@ public void setApiKey(String apiKey) {
2834
public void setHost(String host) {
2935
this.host = host;
3036
}
37+
38+
public boolean isEnabled() {
39+
return isEnabled;
40+
}
41+
42+
public void setEnabled(boolean enabled) {
43+
isEnabled = enabled;
44+
}
45+
46+
public boolean isDebug() {
47+
return isDebug;
48+
}
49+
50+
public void setDebug(boolean debug) {
51+
isDebug = debug;
52+
}
3153
}

traceo-sdk-core/src/main/java/com/traceo/sdk/builder/CoreBuilder.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,14 @@ public final Subclass withHost(String host) {
2525
configuration.setHost(host);
2626
return getSubclass();
2727
}
28+
29+
public final Subclass withEnabled(boolean enabled) {
30+
configuration.setEnabled(enabled);
31+
return getSubclass();
32+
}
33+
34+
public final Subclass withDebug(boolean enabled) {
35+
configuration.setDebug(enabled);
36+
return getSubclass();
37+
}
2838
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
11
package com.traceo.sdk.client;
22

33
import com.traceo.sdk.builder.ClientCoreConfiguration;
4+
import com.traceo.sdk.http.HttpAsyncClient;
5+
import com.traceo.sdk.logging.ClientLogger;
6+
import org.apache.commons.logging.Log;
7+
8+
import java.io.IOException;
49

510
public class CoreClient<T extends ClientCoreConfiguration> {
11+
private final static ClientLogger LOGGER = new ClientLogger(CoreClient.class);
612
private static volatile ClientCoreConfiguration configuration;
13+
private static HttpAsyncClient asyncTransport;
714

815
protected CoreClient() {}
916

1017
public static <T extends ClientCoreConfiguration> void init(T clientConfiguration) {
1118
configuration = clientConfiguration;
19+
20+
if (clientConfiguration.isEnabled()) {
21+
asyncTransport = new HttpAsyncClient();
22+
shutdownHook();
23+
} else {
24+
LOGGER.log("Traceo client is not enabled.");
25+
}
1226
}
1327

1428
public static <T extends ClientCoreConfiguration> T getConfigs() {
1529
return (T) configuration;
1630
}
31+
32+
private static void shutdownHook() {
33+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
34+
try {
35+
asyncTransport.closeHttpClient();
36+
} catch (IOException e) {
37+
LOGGER.logThrowableWithMessage("Exception while closing http client.", e);
38+
throw new RuntimeException(e);
39+
}
40+
}));
41+
}
1742
}
1843

traceo-sdk-core/src/main/java/com/traceo/sdk/converters/StringConverter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ public class StringConverter {
44
/**
55
* Method to convert string to header-string:
66
* eq. Some header Key -> some-header-key
7-
* @param key
8-
* @return
97
*/
108
public static String convertToHeaderKey(String key) {
119
if (key == null) {

0 commit comments

Comments
 (0)