diff --git a/README.md b/README.md
index fe47114d..db941103 100644
--- a/README.md
+++ b/README.md
@@ -69,13 +69,22 @@ Projects that use Matomo Java Tracker:
## What Is New?
+### Version 3.4.x
+
+We fixed a synchronization issue in the Java 8 sender (https://github.com/matomo-org/matomo-java-tracker/issues/168).
+To consume the exact amount of space needed for the queries to send to Matomo, we need the collection size of the incoming
+requests. So we changed `Iterable` to `Collection` in some `MatomoTracker`. This could affect users, that use parameters
+of type `Iterable` in the tracker. Please use `Collection` instead.
+
+### Version 3.3.x
+
Do you still use Matomo Java Tracker 2.x? We created version 3, that is compatible with Matomo 4 and 5 and contains
fewer
dependencies. Release notes can be found here: https://github.com/matomo-org/matomo-java-tracker/releases
Here are the most important changes:
-* Matomo Java Tracker 3.3.0 is compatible with Matomo 4 and 5
+* Matomo Java Tracker 3.4.0 is compatible with Matomo 4 and 5
* less dependencies
* new dimension parameter
* special types allow to provide valid parameters now
@@ -140,7 +149,7 @@ Add a dependency on Matomo Java Tracker using Maven. For Java 8:
org.piwik.java.tracking
matomo-java-tracker
- 3.3.0
+ 3.4.0
```
@@ -151,7 +160,7 @@ For Java 11:
org.piwik.java.tracking
matomo-java-tracker-java11
- 3.3.0
+ 3.4.0
```
@@ -159,7 +168,7 @@ or Gradle (Java 8):
```groovy
dependencies {
- implementation("org.piwik.java.tracking:matomo-java-tracker:3.3.0")
+ implementation("org.piwik.java.tracking:matomo-java-tracker:3.4.0")
}
```
@@ -167,20 +176,20 @@ or Gradle (Java 11):
```groovy
dependencies {
- implementation("org.piwik.java.tracking:matomo-java-tracker-java11:3.3.0")
+ implementation("org.piwik.java.tracking:matomo-java-tracker-java11:3.4.0")
}
```
or Gradle with Kotlin DSL (Java 8)
```kotlin
-implementation("org.piwik.java.tracking:matomo-java-tracker:3.3.0")
+implementation("org.piwik.java.tracking:matomo-java-tracker:3.4.0")
```
or Gradle with Kotlin DSL (Java 11)
```kotlin
-implementation("org.piwik.java.tracking:matomo-java-tracker-java11:3.3.0")
+implementation("org.piwik.java.tracking:matomo-java-tracker-java11:3.4.0")
```
### Spring Boot Module
@@ -193,7 +202,7 @@ and allows you to configure the tracker via application properties. Add the foll
org.piwik.java.tracking
matomo-java-tracker-spring-boot-starter
- 3.3.0
+ 3.4.0
```
@@ -201,14 +210,14 @@ or Gradle:
```groovy
dependencies {
- implementation("org.piwik.java.tracking:matomo-java-tracker-spring-boot-starter:3.3.0")
+ implementation("org.piwik.java.tracking:matomo-java-tracker-spring-boot-starter:3.4.0")
}
```
or Gradle with Kotlin DSL
```kotlin
-implementation("org.piwik.java.tracking:matomo-java-tracker-spring-boot-starter:3.3.0")
+implementation("org.piwik.java.tracking:matomo-java-tracker-spring-boot-starter:3.4.0")
```
The following properties are supported:
@@ -678,7 +687,7 @@ version can be used in your local Maven repository for testing purposes, e.g.
org.piwik.java.tracking
matomo-java-tracker
- 3.3.1-SNAPSHOT
+ 3.4.1-SNAPSHOT
```
diff --git a/core/pom.xml b/core/pom.xml
index 07d3c099..9455a6c0 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -4,7 +4,7 @@
org.piwik.java.tracking
matomo-java-tracker-parent
- 3.3.2-SNAPSHOT
+ 3.4.0-SNAPSHOT
../pom.xml
diff --git a/core/src/main/java/org/matomo/java/tracking/MatomoTracker.java b/core/src/main/java/org/matomo/java/tracking/MatomoTracker.java
index 84c48271..3c38d017 100644
--- a/core/src/main/java/org/matomo/java/tracking/MatomoTracker.java
+++ b/core/src/main/java/org/matomo/java/tracking/MatomoTracker.java
@@ -11,6 +11,7 @@
import java.net.URI;
import java.time.Duration;
import java.util.Arrays;
+import java.util.Collection;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -135,7 +136,7 @@ public MatomoTracker(
*
*
Use this method if you want to send a single request. If you want to send multiple requests at once, use
* {@link #sendBulkRequest(Iterable)} instead. If you want to send multiple requests asynchronously, use
- * {@link #sendRequestAsync(MatomoRequest)} or {@link #sendBulkRequestAsync(Iterable)} instead.
+ * {@link #sendRequestAsync(MatomoRequest)} or {@link #sendBulkRequestAsync(Collection)} instead.
*
* @param request request to send. must not be null
*/
@@ -160,7 +161,7 @@ private void initializeSender() {
* Send a request asynchronously via HTTP GET.
*
*
Use this method if you want to send a single request. If you want to send multiple requests at once, use
- * {@link #sendBulkRequestAsync(Iterable)} instead. If you want to send multiple requests synchronously, use
+ * {@link #sendBulkRequestAsync(Collection)} instead. If you want to send multiple requests synchronously, use
* {@link #sendRequest(MatomoRequest)} or {@link #sendBulkRequest(Iterable)} instead.
*
* @param request request to send
@@ -176,8 +177,8 @@ public CompletableFuture sendRequestAsync(
* Send a request asynchronously via HTTP GET and specify a callback that gets executed when the response arrives.
*
* Use this method if you want to send a single request. If you want to send multiple requests at once, use
- * {@link #sendBulkRequestAsync(Iterable, Consumer)} instead. If you want to send multiple requests synchronously, use
- * {@link #sendRequest(MatomoRequest)} or {@link #sendBulkRequest(Iterable)} instead.
+ * {@link #sendBulkRequestAsync(Collection, Consumer)} instead. If you want to send multiple requests synchronously,
+ * use {@link #sendRequest(MatomoRequest)} or {@link #sendBulkRequest(Iterable)} instead.
*
* @param request request to send
* @param callback callback that gets executed when response arrives, must not be null
@@ -223,7 +224,7 @@ private void applyGoalIdAndCheckSiteId(
*
*
More efficient than sending several individual requests. If you want to send a single request, use
* {@link #sendRequest(MatomoRequest)} instead. If you want to send multiple requests asynchronously, use
- * {@link #sendBulkRequestAsync(Iterable)} instead.
+ * {@link #sendBulkRequestAsync(Collection)} instead.
*
* @param requests the requests to send
*/
@@ -236,7 +237,7 @@ public void sendBulkRequest(MatomoRequest... requests) {
*
*
More efficient than sending several individual requests. If you want to send a single request, use
* {@link #sendRequest(MatomoRequest)} instead. If you want to send multiple requests asynchronously, use
- * {@link #sendBulkRequestAsync(Iterable)} instead.
+ * {@link #sendBulkRequestAsync(Collection)} instead.
*
* @param requests the requests to send
*/
@@ -250,7 +251,7 @@ public void sendBulkRequest(@NonNull Iterable extends MatomoRequest> requests)
*
*
Specify the AuthToken if parameters that require an auth token is used. If you want to send a single request,
* use {@link #sendRequest(MatomoRequest)} instead. If you want to send multiple requests asynchronously, use
- * {@link #sendBulkRequestAsync(Iterable)} instead.
+ * {@link #sendBulkRequestAsync(Collection)} instead.
*
* @param requests the requests to send
* @param authToken specify if any of the parameters use require AuthToken, if null the default auth token from the
@@ -293,7 +294,7 @@ public CompletableFuture sendBulkRequestAsync(MatomoRequest... requests) {
* @return completable future to let you know when the request is done
*/
public CompletableFuture sendBulkRequestAsync(
- @NonNull Iterable extends MatomoRequest> requests
+ @NonNull Collection extends MatomoRequest> requests
) {
return sendBulkRequestAsync(requests, null, null);
}
@@ -313,7 +314,7 @@ public CompletableFuture sendBulkRequestAsync(
*/
@Deprecated
public CompletableFuture sendBulkRequestAsync(
- @NonNull Iterable extends MatomoRequest> requests,
+ @NonNull Collection extends MatomoRequest> requests,
@Nullable String authToken,
@Nullable Consumer callback
) {
@@ -342,7 +343,7 @@ public CompletableFuture sendBulkRequestAsync(
* @return completable future to let you know when the request is done
*/
public CompletableFuture sendBulkRequestAsync(
- @NonNull Iterable extends MatomoRequest> requests,
+ @NonNull Collection extends MatomoRequest> requests,
@Nullable Consumer callback
) {
return sendBulkRequestAsync(requests, null, callback);
@@ -357,10 +358,10 @@ public CompletableFuture sendBulkRequestAsync(
* @param authToken specify if any of the parameters use require AuthToken, null allowed
* @return completable future to let you know when the request is done
* @deprecated Please set the auth token in the tracker configuration or the requests directly and use
- * {@link #sendBulkRequestAsync(Iterable)} instead.
+ * {@link #sendBulkRequestAsync(Collection)} instead.
*/
public CompletableFuture sendBulkRequestAsync(
- @NonNull Iterable extends MatomoRequest> requests, @Nullable String authToken
+ @NonNull Collection extends MatomoRequest> requests, @Nullable String authToken
) {
return sendBulkRequestAsync(requests, authToken, null);
}
diff --git a/core/src/main/java/org/matomo/java/tracking/Sender.java b/core/src/main/java/org/matomo/java/tracking/Sender.java
index a256335e..7b1df985 100644
--- a/core/src/main/java/org/matomo/java/tracking/Sender.java
+++ b/core/src/main/java/org/matomo/java/tracking/Sender.java
@@ -2,6 +2,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
+import java.util.Collection;
import java.util.concurrent.CompletableFuture;
interface Sender extends AutoCloseable {
@@ -20,6 +21,6 @@ void sendBulk(
@NonNull
CompletableFuture sendBulkAsync(
- @NonNull Iterable extends MatomoRequest> requests, @Nullable String overrideAuthToken
+ @NonNull Collection extends MatomoRequest> requests, @Nullable String overrideAuthToken
);
}
diff --git a/core/src/test/java/org/matomo/java/tracking/TestSender.java b/core/src/test/java/org/matomo/java/tracking/TestSender.java
index 0342cf98..f000bc8d 100644
--- a/core/src/test/java/org/matomo/java/tracking/TestSender.java
+++ b/core/src/test/java/org/matomo/java/tracking/TestSender.java
@@ -53,7 +53,7 @@ public void sendBulk(
@NonNull
@Override
public CompletableFuture sendBulkAsync(
- @NonNull Iterable extends MatomoRequest> requests, @Nullable String overrideAuthToken
+ @NonNull Collection extends MatomoRequest> requests, @Nullable String overrideAuthToken
) {
for (MatomoRequest request : requests) {
createQueryAndAddRequest(request, overrideAuthToken);
diff --git a/java11/pom.xml b/java11/pom.xml
index de8a04fb..def72bd4 100644
--- a/java11/pom.xml
+++ b/java11/pom.xml
@@ -4,12 +4,12 @@
org.piwik.java.tracking
matomo-java-tracker-parent
- 3.3.2-SNAPSHOT
+ 3.4.0-SNAPSHOT
../pom.xml
matomo-java-tracker-java11
- 3.3.2-SNAPSHOT
+ 3.4.0-SNAPSHOT
jar
Matomo Java Tracker Java 11
diff --git a/java11/src/main/java/org/matomo/java/tracking/Java11Sender.java b/java11/src/main/java/org/matomo/java/tracking/Java11Sender.java
index 2cff400d..abb6181f 100644
--- a/java11/src/main/java/org/matomo/java/tracking/Java11Sender.java
+++ b/java11/src/main/java/org/matomo/java/tracking/Java11Sender.java
@@ -115,7 +115,7 @@ private HttpRequest buildHttpPostRequest(
@NonNull
@Override
public CompletableFuture sendBulkAsync(
- @NonNull @lombok.NonNull Iterable extends MatomoRequest> requests,
+ @NonNull @lombok.NonNull Collection extends MatomoRequest> requests,
@Nullable String overrideAuthToken
) {
return sendAsyncAndCheckResponse(buildHttpPostRequest(requests, overrideAuthToken), null);
diff --git a/java8/pom.xml b/java8/pom.xml
index 96c05b2b..5c61634c 100644
--- a/java8/pom.xml
+++ b/java8/pom.xml
@@ -4,12 +4,12 @@
org.piwik.java.tracking
matomo-java-tracker-parent
- 3.3.2-SNAPSHOT
+ 3.4.0-SNAPSHOT
../pom.xml
matomo-java-tracker
- 3.3.2-SNAPSHOT
+ 3.4.0-SNAPSHOT
jar
Matomo Java Tracker Java 8
diff --git a/java8/src/main/java/org/matomo/java/tracking/Java8Sender.java b/java8/src/main/java/org/matomo/java/tracking/Java8Sender.java
index 849ccda1..9aca209c 100644
--- a/java8/src/main/java/org/matomo/java/tracking/Java8Sender.java
+++ b/java8/src/main/java/org/matomo/java/tracking/Java8Sender.java
@@ -27,6 +27,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.CompletableFuture;
@@ -60,7 +61,6 @@ class Java8Sender implements Sender {
private final QueryCreator queryCreator;
private final ExecutorService executorService;
- private final Collection queries = new ArrayList<>(16);
@Override
@NonNull
@@ -322,39 +322,37 @@ private static void preparePostConnection(HttpURLConnection connection) {
@Override
@NonNull
public CompletableFuture sendBulkAsync(
- @NonNull Iterable extends MatomoRequest> requests, @Nullable String overrideAuthToken
+ @NonNull Collection extends MatomoRequest> requests, @Nullable String overrideAuthToken
) {
String authToken = AuthToken.determineAuthToken(overrideAuthToken, requests, trackerConfiguration);
Map headers = new LinkedHashMap<>();
String headerUserAgent = findHeaderUserAgent(requests);
String sessionId = findSessionId(requests);
Map cookies = findCookies(requests);
- synchronized (queries) {
- for (MatomoRequest request : requests) {
- RequestValidator.validate(request, authToken);
- if (request.getHeaders() != null && !request.getHeaders().isEmpty()) {
- headers.putAll(request.getHeaders());
- }
- String query = queryCreator.createQuery(request, null);
- queries.add(query);
+ List queries = new ArrayList<>(requests.size());
+ for (MatomoRequest request : requests) {
+ RequestValidator.validate(request, authToken);
+ if (request.getHeaders() != null && !request.getHeaders().isEmpty()) {
+ headers.putAll(request.getHeaders());
}
+ queries.add(queryCreator.createQuery(request, null));
}
return CompletableFuture.supplyAsync(() ->
- sendBulkAsync(authToken, headers, headerUserAgent, sessionId, cookies), executorService);
+ sendBulkAsync(queries, authToken, headers, headerUserAgent, sessionId, cookies),
+ executorService);
}
@Nullable
private Void sendBulkAsync(
- @Nullable String authToken, Map headers, String headerUserAgent, String sessionId,
+ List queries,
+ @Nullable String authToken,
+ Map headers,
+ String headerUserAgent,
+ String sessionId,
Map cookies
) {
- synchronized (queries) {
- if (!queries.isEmpty()) {
- sendBulk(queries, authToken, headers, headerUserAgent, sessionId, cookies);
- queries.clear();
- }
- return null;
- }
+ sendBulk(queries, authToken, headers, headerUserAgent, sessionId, cookies);
+ return null;
}
@Nullable
diff --git a/pom.xml b/pom.xml
index 8a5b0cf6..f868b1b8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
org.piwik.java.tracking
matomo-java-tracker-parent
- 3.3.2-SNAPSHOT
+ 3.4.0-SNAPSHOT
pom
Matomo Java Tracker Parent
diff --git a/servlet-jakarta/pom.xml b/servlet-jakarta/pom.xml
index 0679c2e9..0964d5a4 100644
--- a/servlet-jakarta/pom.xml
+++ b/servlet-jakarta/pom.xml
@@ -4,12 +4,12 @@
org.piwik.java.tracking
matomo-java-tracker-parent
- 3.3.2-SNAPSHOT
+ 3.4.0-SNAPSHOT
../pom.xml
matomo-java-tracker-servlet-jakarta
- 3.3.2-SNAPSHOT
+ 3.4.0-SNAPSHOT
jar
Matomo Java Tracker Servlet Jakarta
diff --git a/servlet-jakarta/src/test/java/org/matomo/java/tracking/TestSender.java b/servlet-jakarta/src/test/java/org/matomo/java/tracking/TestSender.java
index d610ff08..14f8cde6 100644
--- a/servlet-jakarta/src/test/java/org/matomo/java/tracking/TestSender.java
+++ b/servlet-jakarta/src/test/java/org/matomo/java/tracking/TestSender.java
@@ -46,7 +46,7 @@ public void sendBulk(
@NonNull
@Override
public CompletableFuture sendBulkAsync(
- @NonNull Iterable extends MatomoRequest> requests, @Nullable String overrideAuthToken
+ @NonNull Collection extends MatomoRequest> requests, @Nullable String overrideAuthToken
) {
throw new UnsupportedOperationException();
}
diff --git a/servlet-javax/pom.xml b/servlet-javax/pom.xml
index 65511295..0152f0d6 100644
--- a/servlet-javax/pom.xml
+++ b/servlet-javax/pom.xml
@@ -4,12 +4,12 @@
org.piwik.java.tracking
matomo-java-tracker-parent
- 3.3.2-SNAPSHOT
+ 3.4.0-SNAPSHOT
../pom.xml
matomo-java-tracker-servlet-javax
- 3.3.2-SNAPSHOT
+ 3.4.0-SNAPSHOT
jar
Matomo Java Tracker Servlet Javax
diff --git a/servlet-javax/src/test/java/org/matomo/java/tracking/TestSender.java b/servlet-javax/src/test/java/org/matomo/java/tracking/TestSender.java
index 4d155494..0e1704f1 100644
--- a/servlet-javax/src/test/java/org/matomo/java/tracking/TestSender.java
+++ b/servlet-javax/src/test/java/org/matomo/java/tracking/TestSender.java
@@ -46,7 +46,7 @@ public void sendBulk(
@NonNull
@Override
public CompletableFuture sendBulkAsync(
- @NonNull Iterable extends MatomoRequest> requests, @Nullable String overrideAuthToken
+ @NonNull Collection extends MatomoRequest> requests, @Nullable String overrideAuthToken
) {
throw new UnsupportedOperationException();
}
diff --git a/spring/pom.xml b/spring/pom.xml
index 89325afb..9df6330a 100644
--- a/spring/pom.xml
+++ b/spring/pom.xml
@@ -4,7 +4,7 @@
org.piwik.java.tracking
matomo-java-tracker-parent
- 3.3.2-SNAPSHOT
+ 3.4.0-SNAPSHOT
../pom.xml
diff --git a/test/pom.xml b/test/pom.xml
index 72e713aa..a95ba3d8 100644
--- a/test/pom.xml
+++ b/test/pom.xml
@@ -4,7 +4,7 @@
org.piwik.java.tracking
matomo-java-tracker-parent
- 3.3.2-SNAPSHOT
+ 3.4.0-SNAPSHOT
../pom.xml