Skip to content

Commit

Permalink
Release 1.3.7
Browse files Browse the repository at this point in the history
1. 优化 Flush 的实现过程
  • Loading branch information
Yuhan ZOU committed Apr 27, 2016
1 parent 3c95897 commit a19c48d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Add the following lines to your project's pom.xml:
<dependency>
<groupId>com.sensorsdata.analytics.javasdk</groupId>
<artifactId>SensorsAnalyticsSDK</artifactId>
<version>1.3.6</version>
<version>1.3.7</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion SensorsAnalyticsSDK/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<groupId>com.sensorsdata.analytics.javasdk</groupId>
<name>SensorsAnalyticsSDK</name>
<artifactId>SensorsAnalyticsSDK</artifactId>
<version>1.3.6</version>
<version>1.3.7</version>
<description>The official Java SDK of Sensors Analytics</description>
<url>http://sensorsdata.cn</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class SensorsDataAPI {
private final static Logger log = LoggerFactory.getLogger(SensorsDataAPI.class);

private final static int EXECUTE_THREAD_NUMBER = 10;
private final static String SDK_VERSION = "1.3.6";
private final static String SDK_VERSION = "1.3.7";

private final static Pattern KEY_PATTERN = Pattern.compile(
"^((?!^distinct_id$|^original_id$|^time$|^properties$|^id$|^first_id$|^second_id$|^users$|^events$|^event$|^user_id$|^date$|^datetime$)[a-zA-Z_$][a-zA-Z\\d_$]{0,99})$",
Expand Down Expand Up @@ -134,7 +134,7 @@ public static SensorsDataAPI sharedInstance() {
/**
* 初始化 Sensors Analytics SDK,并返回 SensorsDataAPI 的单例
*
* 默认刷新周期为1秒或缓存1000条数据。更多说明请参考
* 默认刷新周期为1秒或缓存100条数据。更多说明请参考
* {@link #sharedInstanceWithConfigure(String, int, int,
* com.sensorsdata.analytics.javasdk.SensorsDataAPI.DebugMode)}
*
Expand All @@ -146,7 +146,7 @@ public static SensorsDataAPI sharedInstance() {
*/
public static SensorsDataAPI sharedInstanceWithServerURL(final String serverUrl, final
DebugMode debugMode) {
return sharedInstanceWithConfigure(serverUrl, 1000, 1000, debugMode);
return sharedInstanceWithConfigure(serverUrl, 1000, 100, debugMode);
}

/**
Expand Down Expand Up @@ -704,7 +704,17 @@ public SubmitTask(final List<Map<String, Object>> data) {

@Override public Boolean call() throws FlushErrorException, ConnectErrorException {
try {
return sendData(this.data);
// 每次发送不超过 100 条数据到 Sensors Analytics
int sendingPos = 0;
while (sendingPos < this.data.size()) {
int sendingSize = Math.min(this.data.size(), 100);

if (!sendData(this.data.subList(sendingPos, sendingPos + sendingSize))) {
return false;
}

sendingPos += sendingSize;
}
} catch (FlushErrorException e) {
log.error(e.getMessage(), e);
System.out.println("Sensors Analytics SDK ERROR: " + e.getMessage());
Expand All @@ -714,6 +724,7 @@ public SubmitTask(final List<Map<String, Object>> data) {
System.out.println("Sensors Analytics SDK ERROR: " + e.getMessage());
throw e;
}
return true;
}

private Boolean sendData(final List<Map<String, Object>> data)
Expand Down Expand Up @@ -786,7 +797,7 @@ private char[] encodeTasks(String data) throws IOException {
}
}

private final List<Map<String, Object>> data;
private List<Map<String, Object>> data;
}


Expand Down

0 comments on commit a19c48d

Please sign in to comment.