Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions enos-http-sdk/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ desired version by inserting the following code snippet:
<dependency>
<groupId>com.envisioniot</groupId>
<artifactId>enos-http</artifactId>
<version>0.1.1</version>
<version>0.1.8</version>
<!--This is latest current version number when this document is being written. Yours may vary.-->
</dependency>
----
Expand Down Expand Up @@ -155,5 +155,6 @@ Under development
* 2020/01/15 (Initial Release): Reporting measurement points (including file-type points)
* 2020/05/07 (0.1.4): Support deleting and downloading files
* 2020/05/14 (0.1.5): Fix NPE while uploading measurepoints
* 2020/07/22 (0.1.6): Fix security vulnerabilities.
* 2020/08/17 (0.1.7): Support file upload/download via EnOS LARK.
* 2020/07/22 (0.1.6): Fix security vulnerabilities
* 2020/08/17 (0.1.7): Support file upload/download via EnOS LARK and support OTA
* 2020/12/09 (0.1.8): Add some log information
3 changes: 2 additions & 1 deletion enos-http-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>enos-http</artifactId>
<version>0.1.7</version>
<version>0.1.8</version>

<packaging>jar</packaging>

Expand All @@ -25,6 +25,7 @@
0.1.3 Refactored to share common codes with HTTP integration
0.1.4 support to download or delete file
0.1.7 support OTA, support file upload/download via EnOS LARK
0.1.8 2.2 GA fix some log and sample
-->

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public class HttpConnection
public static final String MEDIA_TYPE_JSON_UTF_8 = JSON_UTF_8.toString();
public static final String MEDIA_TYPE_OCTET_STREAM = OCTET_STREAM.toString();

private static final String CMD_PAYLOAD = "command-payload";

/**
* Builder for http connection. A customized OkHttpClient can be provided, to
* define specific connection pool, proxy etc. Find more at
Expand Down Expand Up @@ -205,13 +207,14 @@ public void removeArrivedMsgHandler(Class<? extends IMqttArrivedMessage> arrived

@SuppressWarnings("unchecked")
public void handleAdditionalMsg(Headers headers){
final String CMD_PAYLOAD = "command-payload";

if(headers == null){
return;
}

BaseMqttCommand<?> command = MethodClassMap.convertFromJson(headers.get(CMD_PAYLOAD));
String msg = headers.get(CMD_PAYLOAD);
if(msg == null){
return;
}
BaseMqttCommand<?> command = MethodClassMap.convertFromJson(msg);
if(command == null){
return;
}
Expand Down Expand Up @@ -426,13 +429,17 @@ private <T extends BaseMqttResponse> T publishCall(Call call, BaseMqttRequest<T>
String filename = uriInfo.getFilename();
uriInfoMap.put("filename", featureIdAndFileMap.get(filename).getName());
if (this.isAutoUpload()) {
Response uploadFileRsp = FileUtil.uploadFile(uriInfo.getUploadUrl(), featureIdAndFileMap.get(filename), uriInfo.getHeaders());
Response uploadFileRsp = FileUtil.uploadFile(uriInfo.getUploadUrl(),
featureIdAndFileMap.get(filename), uriInfo.getHeaders());
if (!uploadFileRsp.isSuccessful()) {
log.warn("Fail to autoUpload file, filename: {}, uploadUrl: {}", featureIdAndFileMap.get(filename).getName(), uriInfo.getUploadUrl());
log.error("Fail to upload file automatically, filename: {}, uploadUrl: {}, msg: {}",
featureIdAndFileMap.get(filename).getName(),
uriInfo.getUploadUrl(),
uploadFileRsp.message());
}
}
} catch (Exception e) {
log.error("Fail to upload file, uri info: {}", uriInfoMap);
log.error("Fail to upload file, uri info: {}, exception: {}", uriInfoMap, e);
}
});
rsp.setData(uriInfos);
Expand Down Expand Up @@ -607,11 +614,12 @@ public InputStream downloadFile(String fileUri, FileCategory category) throws En
if (fileUri.startsWith(FileScheme.ENOS_LARK_URI_SCHEME)) {
String downloadUrl = getDownloadUrl(fileUri, category);
Response response = FileUtil.downloadFile(downloadUrl);
if (response.isSuccessful() && response.body() != null) {
return response.body().byteStream();
} else {
throw new EnvisionException("file not exist");
}
Preconditions.checkArgument(response.isSuccessful(),
"fail to download file, downloadUrl: %s, msg: %s",
downloadUrl, response.message());
Preconditions.checkNotNull(response.body(),
"response body is null, downloadUrl: %s", downloadUrl);
return response.body().byteStream();
}

Call call = generateDownloadCall(fileUri, category);
Expand Down
3 changes: 2 additions & 1 deletion enos-mqtt-sdk/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ desired version by inserting the following code snippet:
<dependency>
<groupId>com.envisioniot</groupId>
<artifactId>enos-mqtt</artifactId>
<version>2.2.1</version>
<version>2.2.13</version>
<!--This is latest current version number when this document is being written. Yours may vary.-->
</dependency>
----
Expand Down Expand Up @@ -196,3 +196,4 @@ Under development
* 2020/05/14 (2.2.7): Fix NPE while uploading measurepoints.
* 2020/07/22 (2.2.9): Fix security vulnerabilities.
* 2020/10/05 (2.2.10): Support message compression.
* 2020/12/09 (2.2.13): Support NetworkStatusReportRequest and upgrade paho mqtt.
14 changes: 6 additions & 8 deletions enos-mqtt-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>enos-mqtt</artifactId>
<version>2.2.10</version>
<version>2.2.13</version>

<packaging>jar</packaging>

Expand All @@ -22,14 +22,9 @@

<!-- Version History -->
<!--
0.0.3 remove command DeleteDeviceCommand DisableDeviceCommand
use these command instead: SubDeviceDelete, SubDeviceDisable SubDeviceEnable commands
remove RrpcCommand, the ServiceInvocationCommand handle the sync service as well
add requests including : QueryDeviceTag,AttributeQuery,AttributeUpdate
0.0.4 rename some requests
2.1.0 release
2.1.1 support dynamic activate(login by productSecret)
support init by config file
2.1.2 support ota feature
2.1.3 message integration
2.1.4 internal logic refactor, fix thread pool resource leak
Expand All @@ -44,6 +39,9 @@
2.2.5 add ecc support to connect mqtt-broker
2.2.6 refine connection state management and avoid duplicate re-connections in extreme case
2.2.10 support message compression
2.2.11 upgrade to paho mqtt 1.2.2 and remove synchronize lock for qos 0
2.2.12 improve reconnect timer
2.2.13 upgrade enos-core
-->

<properties>
Expand All @@ -65,13 +63,13 @@
<dependency>
<groupId>com.envisioniot</groupId>
<artifactId>enos-core</artifactId>
<version>0.1.7</version>
<version>0.1.8</version>
</dependency>

<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
package com.envisioniot.enos.iot_mqtt_sdk.core;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.concurrent.*;
/**
* Factory that provides thread pools for handling connect, publish, time-out scheduler,
* async callback. Note that this factory is per MqttClient. <br/>
* <br/>
* User can customize the relevant thread pool through the provided <b>set</b> method.
*
* @author zhensheng.cai
* @author jian.zhang4
*/
public class ExecutorFactory implements IExecutorFactory {
/**
* Thread pools that handles mqtt publish action in async way.
*/
private ExecutorService publishExecutor = new ThreadPoolExecutor(3, 5, 3, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(1000), new ThreadFactoryBuilder().setNameFormat("publish-executor-%d").build());
/**
* We should only have one connect action per MqttClient at the same time. So one
* thread should be good enough to handle async connection.
*/
private ExecutorService connectExecutor = Executors.newSingleThreadExecutor(
new ThreadFactoryBuilder().setNameFormat("connect-executor-%d").build());
/**
* callback timeout pool
*/
private ScheduledExecutorService timeoutScheduler = new ScheduledThreadPoolExecutor(3,
new ThreadFactoryBuilder().setNameFormat("timeout-pool-%d").build());
/**
* Thread pools that execute async callback provided by user
*/
private ExecutorService callbackExecutor = new ThreadPoolExecutor(3, 5, 3, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("callback-executor-%d").build());
/**
* shutdown all thread pools managed by this factory
*/
public void shutdownExecutorServices() {
publishExecutor.shutdownNow();
connectExecutor.shutdownNow();
timeoutScheduler.shutdownNow();
callbackExecutor.shutdownNow();
}
public ExecutorService getPublishExecutor() {
return publishExecutor;
}
public void setPublishExecutor(ExecutorService publishExecutor) {
this.publishExecutor = publishExecutor;
}
public ExecutorService getConnectExecutor() {
return connectExecutor;
}
public void setConnectExecutor(ExecutorService connectExecutor) {
this.connectExecutor = connectExecutor;
}
public ScheduledExecutorService getTimeoutScheduler() {
return timeoutScheduler;
}
public void setTimeoutScheduler(ScheduledExecutorService timeoutScheduler) {
this.timeoutScheduler = timeoutScheduler;
}
public ExecutorService getCallbackExecutor() {
return callbackExecutor;
}
public void setCallbackExecutor(ExecutorService callbackExecutor) {
this.callbackExecutor = callbackExecutor;
}
}
package com.envisioniot.enos.iot_mqtt_sdk.core;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

/**
* Factory that provides thread pools for handling connect, publish, time-out scheduler,
* async callback. Note that this factory is per MqttClient. <br/>
* <br/>
* User can customize the relevant thread pool through the provided <b>set</b> method.
*
* @author zhensheng.cai
* @author jian.zhang4
*/
public class ExecutorFactory implements IExecutorFactory {

/**
* Thread pools that handles mqtt publish action in async way.
*/
private ExecutorService publishExecutor = new ThreadPoolExecutor(3, 5, 3, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(1000), new ThreadFactoryBuilder().setNameFormat("publish-executor-%d").build());

/**
* We should only have one connect action per MqttClient at the same time. So one
* thread should be good enough to handle async connection.
*/
private ExecutorService connectExecutor = Executors.newSingleThreadExecutor(
new ThreadFactoryBuilder().setNameFormat("connect-executor-%d").build());

/**
* callback timeout pool
*/
private ScheduledExecutorService timeoutScheduler = new ScheduledThreadPoolExecutor(3,
new ThreadFactoryBuilder().setNameFormat("timeout-pool-%d").build());

/**
* Thread pools that execute async callback provided by user
*/
private ExecutorService callbackExecutor = new ThreadPoolExecutor(3, 5, 3, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("callback-executor-%d").build());


/**
* shutdown all thread pools managed by this factory
*/
public void shutdownExecutorServices() {
publishExecutor.shutdownNow();
connectExecutor.shutdownNow();
timeoutScheduler.shutdownNow();
callbackExecutor.shutdownNow();
}

public ExecutorService getPublishExecutor() {
return publishExecutor;
}

public void setPublishExecutor(ExecutorService publishExecutor) {
this.publishExecutor = publishExecutor;
}

public ExecutorService getConnectExecutor() {
return connectExecutor;
}

public void setConnectExecutor(ExecutorService connectExecutor) {
this.connectExecutor = connectExecutor;
}

public ScheduledExecutorService getTimeoutScheduler() {
return timeoutScheduler;
}

public void setTimeoutScheduler(ScheduledExecutorService timeoutScheduler) {
this.timeoutScheduler = timeoutScheduler;
}

public ExecutorService getCallbackExecutor() {
return callbackExecutor;
}

public void setCallbackExecutor(ExecutorService callbackExecutor) {
this.callbackExecutor = callbackExecutor;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.envisioniot.enos.iot_mqtt_sdk.core;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
public interface IExecutorFactory {
void shutdownExecutorServices();
ExecutorService getPublishExecutor();
ExecutorService getConnectExecutor();
ScheduledExecutorService getTimeoutScheduler();
ExecutorService getCallbackExecutor();
}
package com.envisioniot.enos.iot_mqtt_sdk.core;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;

public interface IExecutorFactory {

void shutdownExecutorServices();

ExecutorService getPublishExecutor();

ExecutorService getConnectExecutor();

ScheduledExecutorService getTimeoutScheduler();

ExecutorService getCallbackExecutor();
}
Loading