Skip to content

Commit cbcdd39

Browse files
authored
Merge pull request #17 from stefaneberl/feature/OpenKitMemoryLeak
Feature/open kit memory leak
2 parents 4879028 + 8649d06 commit cbcdd39

18 files changed

+92
-89
lines changed

docs/internals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#OpenKit - Internals
22

3-
## Data Sending (Beacon sending)
3+
## Data Sending (Beacon Sending)
44

55
All data sending, including synchronization with the backend (Dynatrace SaaS/Dynatrace Managed/AppMon)
66
happens asynchronously by starting an own thread when OpenKit is initialized.

src/main/java/com/dynatrace/openkit/OpenKitFactory.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ public static OpenKit createDynatraceInstance(String applicationName, String app
4747
* @return Dynatrace SaaS instance of the OpenKit
4848
*/
4949
public static OpenKit createDynatraceInstance(String applicationName, String applicationID, long visitorID, String endpointURL, boolean verbose) {
50-
return new OpenKitImpl(
50+
OpenKitImpl openKit = new OpenKitImpl(
5151
new DynatraceConfiguration(applicationName, applicationID, visitorID, endpointURL, verbose));
52+
openKit.initialize();
53+
54+
return openKit;
5255
}
5356

5457
/**
@@ -77,8 +80,11 @@ public static OpenKit createDynatraceManagedInstance(String applicationName, Str
7780
* @return Dynatrace Managed instance of the OpenKit
7881
*/
7982
public static OpenKit createDynatraceManagedInstance(String applicationName, String applicationID, long visitorID, String endpointURL, String tenantID, boolean verbose) {
80-
return new OpenKitImpl(
83+
OpenKitImpl openKit = new OpenKitImpl(
8184
new DynatraceManagedConfiguration(tenantID, applicationName, applicationID, visitorID, endpointURL, verbose));
85+
openKit.initialize();
86+
87+
return openKit;
8288
}
8389

8490
/**
@@ -103,8 +109,11 @@ public static OpenKit createAppMonInstance(String applicationName, long visitorI
103109
* @return Dynatrace AppMon instance of the OpenKit
104110
*/
105111
public static OpenKit createAppMonInstance(String applicationName, long visitorID, String endpointURL, boolean verbose) {
106-
return new OpenKitImpl(
112+
OpenKitImpl openKit = new OpenKitImpl(
107113
new AppMonConfiguration(applicationName, visitorID, endpointURL, verbose));
114+
openKit.initialize();
115+
116+
return openKit;
108117
}
109118

110119
}

src/main/java/com/dynatrace/openkit/api/Action.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface Action {
1818
* @param eventName name of the event
1919
* @return this Action (for usage as fluent API)
2020
*/
21-
public Action reportEvent(String eventName);
21+
Action reportEvent(String eventName);
2222

2323
/**
2424
* Reports an int value with a specified name.
@@ -27,7 +27,7 @@ public interface Action {
2727
* @param value value itself
2828
* @return this Action (for usage as fluent API)
2929
*/
30-
public Action reportValue(String valueName, int value);
30+
Action reportValue(String valueName, int value);
3131

3232
/**
3333
* Reports a double value with a specified name.
@@ -36,7 +36,7 @@ public interface Action {
3636
* @param value value itself
3737
* @return this Action (for usage as fluent API)
3838
*/
39-
public Action reportValue(String valueName, double value);
39+
Action reportValue(String valueName, double value);
4040

4141
/**
4242
* Reports a String value with a specified name.
@@ -45,7 +45,7 @@ public interface Action {
4545
* @param value value itself
4646
* @return this Action (for usage as fluent API)
4747
*/
48-
public Action reportValue(String valueName, String value);
48+
Action reportValue(String valueName, String value);
4949

5050
/**
5151
* Reports an error with a specified name, error code and a reason.
@@ -55,7 +55,7 @@ public interface Action {
5555
* @param reason reason for this error
5656
* @return this Action (for usage as fluent API)
5757
*/
58-
public Action reportError(String errorName, int errorCode, String reason);
58+
Action reportError(String errorName, int errorCode, String reason);
5959

6060
/**
6161
* Traces a web request - which is provided as a URLConnection - and allows adding timing information to this request.
@@ -65,7 +65,7 @@ public interface Action {
6565
* @param connection the URLConnection of the HTTP request to be tagged and timed
6666
* @return a WebRequestTracer which allows adding timing information
6767
*/
68-
public WebRequestTracer traceWebRequest(URLConnection connection);
68+
WebRequestTracer traceWebRequest(URLConnection connection);
6969

7070
/**
7171
* Allows tracing and timing of a web request handled by any 3rd party HTTP Client (e.g. Apache, Google, Jetty, ...).
@@ -77,13 +77,13 @@ public interface Action {
7777
* @param url the URL of the web request to be tagged and timed
7878
* @return a WebRequestTracer which allows getting the tag value and adding timing information
7979
*/
80-
public WebRequestTracer traceWebRequest(String url);
80+
WebRequestTracer traceWebRequest(String url);
8181

8282
/**
8383
* Leaves this Action.
8484
*
8585
* @return this Action (for usage as fluent API)
8686
*/
87-
public Action leaveAction();
87+
Action leaveAction();
8888

8989
}

src/main/java/com/dynatrace/openkit/api/Device.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ public interface Device {
1515
*
1616
* @param operatingSystem name of operating system
1717
*/
18-
public void setOperatingSystem(String operatingSystem);
18+
void setOperatingSystem(String operatingSystem);
1919

2020
/**
2121
* Sets manufacturer name.
2222
*
2323
* @param manufacturer name of manufacturer
2424
*/
25-
public void setManufacturer(String manufacturer);
25+
void setManufacturer(String manufacturer);
2626

2727
/**
2828
* Sets a model identifier.
2929
*
3030
* @param modelID model identifier
3131
*/
32-
public void setModelID(String modelID);
32+
void setModelID(String modelID);
3333

3434
}

src/main/java/com/dynatrace/openkit/api/OpenKit.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@ public interface OpenKit {
1515
*/
1616
String WEBREQUEST_TAG_HEADER = "X-dynaTrace";
1717

18-
/**
19-
* Initializes the OpenKit.
20-
* <p>
21-
* The initial settings are received in a background thread, allowing the OpenKit user to continue
22-
* without waiting for OpenKit to be initialized.
23-
*
24-
* After calling this method {@link #waitForInitCompletion()} can be used to wait until OpenKit is
25-
* fully initialized.
26-
* </p>
27-
*
28-
* Must be done before any other calls to the OpenKit, otherwise those calls to the OpenKit will do nothing.
29-
*/
30-
void initialize();
3118
/**
3219
* Waits until OpenKit is fully initialized.
3320
*

src/main/java/com/dynatrace/openkit/api/RootAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ public interface RootAction extends Action {
1010
* @param actionName name of the Action
1111
* @return Action instance to work with
1212
*/
13-
public Action enterAction(String actionName);
13+
Action enterAction(String actionName);
1414
}

src/main/java/com/dynatrace/openkit/api/Session.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface Session {
1616
* @param actionName name of the Action
1717
* @return Action instance to work with
1818
*/
19-
public RootAction enterAction(String actionName);
19+
RootAction enterAction(String actionName);
2020

2121
/**
2222
* Reports a crash with a specified error name, crash reason and a stacktrace.
@@ -25,11 +25,11 @@ public interface Session {
2525
* @param reason reason or description of that error
2626
* @param stacktrace stacktrace leading to that crash
2727
*/
28-
public void reportCrash(String errorName, String reason, String stacktrace);
28+
void reportCrash(String errorName, String reason, String stacktrace);
2929

3030
/**
3131
* Ends this Session and marks it as finished for sending.
3232
*/
33-
public void end();
33+
void end();
3434

3535
}

src/main/java/com/dynatrace/openkit/api/WebRequestTracer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,22 @@ public interface WebRequestTracer {
1717
*
1818
* @return the Dynatrace tag to be set as HTTP header value or an empty String if capture is off
1919
*/
20-
public String getTag();
20+
String getTag();
2121

2222
/**
23-
* Sets the response code of this web request. Has to be called before {@link WebRequestTracer#stopTiming()}.
23+
* Sets the response code of this web request. Has to be called before {@link WebRequestTracer#stop()}.
2424
*
2525
* @param responseCode response code of this web request
2626
*/
27-
public void setResponseCode(int responseCode);
27+
void setResponseCode(int responseCode);
2828

2929
/**
3030
* Starts the web request timing. Should be called when the web request is initiated.
3131
*/
32-
public void startTiming();
32+
void start();
3333

3434
/**
3535
* Stops the web request timing. Should be called when the web request is finished.
3636
*/
37-
public void stopTiming();
38-
37+
void stop();
3938
}

src/main/java/com/dynatrace/openkit/core/DummyWebRequestTracer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public void setResponseCode(int responseCode) {
2424
}
2525

2626
@Override
27-
public void startTiming() {
27+
public void start() {
2828
// do nothing
2929
}
3030

3131
@Override
32-
public void stopTiming() {
32+
public void stop() {
3333
// do nothing
3434
}
3535

src/main/java/com/dynatrace/openkit/core/OpenKitImpl.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,20 @@ protected OpenKitImpl(AbstractConfiguration config, HTTPClientProvider httpClien
3939
beaconSender = new BeaconSender(configuration, httpClientProvider, timingProvider);
4040
}
4141

42-
// *** OpenKit interface methods ***
43-
44-
@Override
42+
/**
43+
* Initialize this OpenKit instance.
44+
*
45+
* <p>
46+
* This method starts the {@link BeaconSender} and is called directly after
47+
* the instance has been created in {@link com.dynatrace.openkit.OpenKitFactory}.
48+
* </p>
49+
*/
4550
public void initialize() {
4651
beaconSender.initialize();
4752
}
4853

54+
// *** OpenKit interface methods ***
55+
4956
@Override
5057
public boolean waitForInitCompletion() {
5158
return beaconSender.waitForInit();

0 commit comments

Comments
 (0)