Skip to content

Commit 39127e0

Browse files
author
xuchang
committed
Release 3.4.0
1 parent aa43a8c commit 39127e0

File tree

14 files changed

+1178
-43
lines changed

14 files changed

+1178
-43
lines changed

SensorsAnalyticsSDK/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<groupId>com.sensorsdata.analytics.javasdk</groupId>
1616
<name>SensorsAnalyticsSDK</name>
1717
<artifactId>SensorsAnalyticsSDK</artifactId>
18-
<version>3.3.1</version>
18+
<version>3.4.0</version>
1919
<description>The official Java SDK of Sensors Analytics</description>
2020
<url>http://sensorsdata.cn</url>
2121

@@ -149,11 +149,11 @@
149149
<distributionManagement>
150150
<snapshotRepository>
151151
<id>ossrh</id>
152-
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
152+
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
153153
</snapshotRepository>
154154
<repository>
155155
<id>ossrh</id>
156-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
156+
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
157157
</repository>
158158
</distributionManagement>
159159
<build>

SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/javasdk/SensorsConst.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private SensorsConst() {
1515
/**
1616
* 当前JDK版本号,注意要和pom文件里面的version保持一致
1717
*/
18-
public static final String SDK_VERSION = "3.3.1";
18+
public static final String SDK_VERSION = "3.4.0";
1919
/**
2020
* 当前语言类型
2121
*/

SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/javasdk/consumer/BatchConsumer.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,33 @@ public BatchConsumer(final String serverUrl) {
2828
}
2929

3030
public BatchConsumer(final String serverUrl, final int bulkSize) {
31-
this(serverUrl, 3, bulkSize);
31+
this(serverUrl, bulkSize, 3);
3232
}
3333

34-
public BatchConsumer(final String serverUrl, final int timeoutSec, final int bulkSize) {
35-
this(serverUrl, bulkSize, timeoutSec, false);
34+
public BatchConsumer(final String serverUrl, final int bulkSize, final int timeoutSec) {
35+
this(serverUrl, bulkSize, false, timeoutSec);
3636
}
3737

38-
public BatchConsumer(final String serverUrl, final int bulkSize, final int timeoutSec,
39-
final boolean throwException) {
40-
this(serverUrl, bulkSize, timeoutSec, 0, throwException);
38+
public BatchConsumer(final String serverUrl, final int bulkSize, final boolean throwException) {
39+
this(serverUrl, bulkSize, throwException, 3);
40+
}
41+
42+
public BatchConsumer(final String serverUrl, final int bulkSize, final boolean throwException,
43+
final int timeoutSec) {
44+
this(serverUrl, bulkSize, 0, throwException, timeoutSec);
4145
}
4246

43-
public BatchConsumer(final String serverUrl, final int bulkSize, final int timeoutSec, final int maxCacheSize,
47+
public BatchConsumer(final String serverUrl, final int bulkSize, final int maxCacheSize,
4448
final boolean throwException) {
49+
this(serverUrl, bulkSize, maxCacheSize, throwException, 3);
50+
}
51+
52+
public BatchConsumer(final String serverUrl, final int bulkSize, final int maxCacheSize,
53+
final boolean throwException, final int timeoutSec) {
4554
this.messageList = new LinkedList<>();
4655
this.httpConsumer = new HttpConsumer(serverUrl, Math.max(timeoutSec, 1));
4756
this.jsonMapper = SensorsAnalyticsUtil.getJsonObjectMapper();
48-
this.bulkSize = Math.min(MAX_FLUSH_BULK_SIZE, bulkSize);
57+
this.bulkSize = Math.min(MAX_FLUSH_BULK_SIZE, Math.max(1, bulkSize));
4958
if (maxCacheSize > MAX_CACHE_SIZE) {
5059
this.maxCacheSize = MAX_CACHE_SIZE;
5160
} else if (maxCacheSize > 0 && maxCacheSize < MIN_CACHE_SIZE) {

SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/javasdk/util/SensorsAnalyticsUtil.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,34 +160,34 @@ public static void assertFailedData(FailedData failedData) throws InvalidArgumen
160160
}
161161
for (int i = 0; i < failedData.getFailedData().size(); i++) {
162162
final Map<String, Object> dataMap = failedData.getFailedData().get(i);
163-
if (!dataMap.containsKey("type") || dataMap.get("type") == null) {
163+
if (verifyMapValueIsBlank(dataMap, "type")) {
164164
throw new InvalidArgumentException(
165165
String.format("The index [%d] of failed data list have not [type].", i));
166166
}
167167
final String type = String.valueOf(dataMap.get("type"));
168168
switch (type) {
169169
case ITEM_SET_ACTION_TYPE:
170170
case ITEM_DELETE_ACTION_TYPE:
171-
if (!dataMap.containsKey("item_id") || dataMap.get("item_id") == null) {
171+
if (verifyMapValueIsBlank(dataMap, "item_id")) {
172172
throw new InvalidArgumentException(
173173
String.format("The index [%d] of failed data list have not [item_id].", i));
174174
}
175175
assertValue("item id", dataMap.get("item_id").toString());
176-
if (!dataMap.containsKey("item_type") || dataMap.get("item_type") == null) {
176+
if (verifyMapValueIsBlank(dataMap, "item_type")) {
177177
throw new InvalidArgumentException(
178178
String.format("The index [%d] of failed data list have not [item_type].", i));
179179
}
180180
assertValue("item type", dataMap.get("item_type").toString());
181181
break;
182182
case TRACK_SIGN_UP_ACTION_TYPE:
183-
if (!dataMap.containsKey("original_id") || dataMap.get("original_id") == null) {
183+
if (verifyMapValueIsBlank(dataMap, "original_id")) {
184184
throw new InvalidArgumentException(
185185
String.format("The index [%d] of failed data list have not [original_id].", i));
186186
}
187187
assertValue("Original Distinct Id", dataMap.get("original_id").toString());
188188
case BIND_ID_ACTION_TYPE:
189189
case UNBIND_ID_ACTION_TYPE:
190-
if (!dataMap.containsKey("identities") || dataMap.get("identities") == null) {
190+
if (!TRACK_SIGN_UP_ACTION_TYPE.equals(type) && verifyMapValueIsBlank(dataMap, "identities")) {
191191
throw new InvalidArgumentException(
192192
String.format("The index [%d] of failed data list have not [identities].", i));
193193
}
@@ -198,12 +198,11 @@ public static void assertFailedData(FailedData failedData) throws InvalidArgumen
198198
case PROFILE_INCREMENT_ACTION_TYPE:
199199
case PROFILE_UNSET_ACTION_TYPE:
200200
case PROFILE_DELETE_ACTION_TYPE:
201-
if (!dataMap.containsKey("distinct_id") || dataMap.get("distinct_id") == null) {
201+
if (verifyMapValueIsBlank(dataMap, "distinct_id")) {
202202
throw new InvalidArgumentException(
203203
String.format("The index [%d] of failed data list have not [distinct_id].", i));
204204
}
205-
if (!dataMap.containsKey("_track_id") || dataMap.get("_track_id") == null ||
206-
!(dataMap.get("_track_id") instanceof Integer)) {
205+
if (verifyMapValueIsBlank(dataMap, "_track_id") || !(dataMap.get("_track_id") instanceof Integer)) {
207206
throw new InvalidArgumentException(String.format("The index [%d] of of failed data list is invalid.", i));
208207
}
209208
assertValue("Distinct Id", dataMap.get("distinct_id").toString());
@@ -254,4 +253,8 @@ public static List<Map<String, Object>> deepCopy(List<Map<String, Object>> sourc
254253
}
255254
return newList;
256255
}
256+
257+
private static boolean verifyMapValueIsBlank(Map<String, Object> map, String key) {
258+
return map == null || !map.containsKey(key) || map.get(key) == null;
259+
}
257260
}

SensorsAnalyticsSDK/src/main/test/java/com.sensorsdata.analytics.javasdk/BatchConsumerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class BatchConsumerTest {
2929

3030
@Before
3131
public void init() throws NoSuchFieldException, IllegalAccessException {
32-
batchConsumer = new BatchConsumer("http://localhost:8016/sa", 1, 3, true);
32+
batchConsumer = new BatchConsumer("http://localhost:8016/sa", 1, true, 3);
3333
Field field = batchConsumer.getClass().getDeclaredField("messageList");
3434
field.setAccessible(true);
3535
messageList = (List<Map<String, Object>>) field.get(batchConsumer);

0 commit comments

Comments
 (0)