optimized remoteIndex validation process
This commit is contained in:
@@ -201,5 +201,93 @@
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.11.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-jul:2.11.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.1.1.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.1.1.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.11.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.3.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.23" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.1.1.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:1.3.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis:3.4.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:1.3.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.1.1.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.1.1.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.1.1.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:9.0.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:9.0.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.0.13.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.validation:validation-api:2.0.1.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.2.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.4.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-redis:2.1.1.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-redis:2.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-keyvalue:2.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:2.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-tx:5.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-oxm:5.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context-support:5.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.lettuce:lettuce-core:5.1.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.projectreactor:reactor-core:3.2.3.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.31.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.31.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.31.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.31.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.1.31.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.31.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-io:commons-io:2.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.aliyun.oss:aliyun-sdk-oss:3.4.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.11" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jdom:jdom:1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sun.jersey:jersey-json:1.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.codehaus.jettison:jettison:1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: stax:stax-api:1.0.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-impl:2.2.3-1" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-core-asl:1.8.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-mapper-asl:1.8.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-jaxrs:1.8.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-xc:1.8.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sun.jersey:jersey-core:1.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.aliyun:aliyun-java-sdk-core:3.4.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.json:json:20170516" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.aliyun:aliyun-java-sdk-ram:3.0.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.aliyun:aliyun-java-sdk-sts:3.0.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.aliyun:aliyun-java-sdk-ecs:4.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.1.1.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.1.1.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: redis.clients:jedis:2.9.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.6.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-log4j2:2.1.1.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-slf4j-impl:2.11.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.11.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.11.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-jul:2.11.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -93,27 +93,19 @@ public class DecodeLogic {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int[] decode(IIRBinaryRepository irBinaryRepository, IDecodeSessionRepository decodeSessionRepository,
|
||||
String sessionId, int remoteIndexId, ACStatus acStatus, int keyCode, int changeWindDirection) {
|
||||
// since the binary is already opened and probably cached to redis, we just need to load it
|
||||
Integer cachedRemoteIndexId = decodeSessionRepository.find(sessionId);
|
||||
public int[] decode(RemoteIndex remoteIndex, ACStatus acStatus, int keyCode, int changeWindDirection) {
|
||||
int[] decoded = null;
|
||||
if (null != cachedRemoteIndexId) {
|
||||
RemoteIndex cachedRemoteIndex = irBinaryRepository.find(cachedRemoteIndexId);
|
||||
if (null != cachedRemoteIndex) {
|
||||
int categoryId = cachedRemoteIndex.getCategoryId();
|
||||
int subCate = cachedRemoteIndex.getSubCate();
|
||||
byte[] binaryContent = cachedRemoteIndex.getBinaries();
|
||||
IRDecode irDecode = IRDecode.getInstance();
|
||||
int ret = irDecode.openBinary(categoryId, subCate, binaryContent, binaryContent.length);
|
||||
if (0 == ret) {
|
||||
decoded = irDecode.decodeBinary(keyCode, acStatus, changeWindDirection);
|
||||
}
|
||||
irDecode.closeBinary();
|
||||
return decoded;
|
||||
if (null != remoteIndex) {
|
||||
int categoryId = remoteIndex.getCategoryId();
|
||||
int subCate = remoteIndex.getSubCate();
|
||||
byte[] binaryContent = remoteIndex.getBinaries();
|
||||
IRDecode irDecode = IRDecode.getInstance();
|
||||
int ret = irDecode.openBinary(categoryId, subCate, binaryContent, binaryContent.length);
|
||||
if (0 == ret) {
|
||||
decoded = irDecode.decodeBinary(keyCode, acStatus, changeWindDirection);
|
||||
}
|
||||
} else {
|
||||
LoggerUtil.getInstance().trace(TAG, "session cache missed, need to re-open binary");
|
||||
irDecode.closeBinary();
|
||||
return decoded;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,8 @@ public class IRDecodeService extends AbstractBaseService {
|
||||
StringResponse response = new StringResponse();
|
||||
RemoteIndex remoteIndex = IndexLogic.getInstance(remoteIndexMapper).getRemoteIndex(remoteIndexId);
|
||||
if (null == remoteIndex) {
|
||||
response.setStatus(new Status(Constants.ERROR_CODE_NETWORK_ERROR, ""));
|
||||
response.setStatus(new Status(Constants.ERROR_CODE_NETWORK_ERROR,
|
||||
Constants.ERROR_CODE_NETWORK_ERROR_TEXT));
|
||||
response.setEntity(null);
|
||||
return response;
|
||||
} else {
|
||||
@@ -96,7 +97,7 @@ public class IRDecodeService extends AbstractBaseService {
|
||||
decodeSessionRepository.add(decodeSession.getSessionId(), decodeSession.getBinaryId());
|
||||
response.setEntity(decodeSession.getSessionId());
|
||||
}
|
||||
response.setStatus(new Status(Constants.ERROR_CODE_SUCCESS, ""));
|
||||
response.setStatus(new Status(Constants.ERROR_CODE_SUCCESS, Constants.ERROR_CODE_SUCESS_TEXT));
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -113,16 +114,48 @@ public class IRDecodeService extends AbstractBaseService {
|
||||
int changeWindDir = decodeRequest.getChangeWindDir();
|
||||
String sessionId = decodeRequest.getSessionId();
|
||||
|
||||
RemoteIndex cachedRemoteIndex = null;
|
||||
DecodeResponse response = new DecodeResponse();
|
||||
|
||||
if (null == sessionId) {
|
||||
LoggerUtil.getInstance().trace(TAG, "sessionId is not given, abort");
|
||||
response.setEntity(null);
|
||||
response.setStatus(new Status(Constants.ERROR_CODE_INVALID_SESSION,
|
||||
Constants.ERROR_CODE_INVALID_SESSION_TEXT));
|
||||
} else {
|
||||
Integer cachedRemoteIndexId = decodeSessionRepository.find(sessionId);
|
||||
if (null == cachedRemoteIndexId) {
|
||||
response.setEntity(null);
|
||||
response.setStatus(new Status(Constants.ERROR_CODE_INVALID_SESSION,
|
||||
Constants.ERROR_CODE_INVALID_SESSION_TEXT));
|
||||
} else {
|
||||
cachedRemoteIndex = irBinaryRepository.find(cachedRemoteIndexId);
|
||||
if (null == cachedRemoteIndex) {
|
||||
response.setEntity(null);
|
||||
response.setStatus(new Status(Constants.ERROR_CODE_INVALID_SESSION,
|
||||
Constants.ERROR_CODE_INVALID_SESSION_TEXT));
|
||||
} else {
|
||||
if (indexId != cachedRemoteIndex.getId()) {
|
||||
response.setEntity(null);
|
||||
response.setStatus(new Status(Constants.ERROR_CODE_INVALID_SESSION,
|
||||
Constants.ERROR_CODE_INVALID_SESSION_TEXT));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (response.getStatus().getCode() != Constants.ERROR_CODE_SUCCESS) {
|
||||
return response;
|
||||
}
|
||||
|
||||
int[] irArray = DecodeLogic.getInstance().decode(
|
||||
irBinaryRepository,
|
||||
decodeSessionRepository,
|
||||
sessionId,
|
||||
indexId,
|
||||
cachedRemoteIndex,
|
||||
acStatus,
|
||||
keyCode,
|
||||
changeWindDir);
|
||||
|
||||
response.setStatus(new Status(Constants.ERROR_CODE_SUCCESS, Constants.ERROR_CODE_SUCESS_TEXT));
|
||||
response.setEntity(irArray);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -14,11 +14,23 @@ public class Constants {
|
||||
|
||||
public static final int ERROR_CODE_SUCCESS = 0;
|
||||
public static final int ERROR_CODE_NETWORK_ERROR = -1;
|
||||
|
||||
public static final int ERROR_CODE_AUTH_FAILURE = 1;
|
||||
public static final int ERROR_CODE_INVALID_CATEGORY = 2;
|
||||
public static final int ERROR_CODE_INVALID_BRAND = 3;
|
||||
public static final int ERROR_CODE_INVALID_PARAMETER = 4;
|
||||
|
||||
public static final int ERROR_CODE_INVALID_SESSION = 20;
|
||||
|
||||
public static final String ERROR_CODE_SUCESS_TEXT = "success";
|
||||
public static final String ERROR_CODE_NETWORK_ERROR_TEXT = "network error";
|
||||
public static final String ERROR_CODE_AUTH_FAILUTRE_TEXT = "auth failure";
|
||||
public static final String ERROR_CODE_INVALID_CATEGORY_TEXT = "invalid category";
|
||||
public static final String ERROR_CODE_INVALID_BRAND_TEXT = "invalid brand";
|
||||
public static final String ERROR_CODE_INVALID_PARAMETER_TEXT = "invalid parameter";
|
||||
|
||||
public static final String ERROR_CODE_INVALID_SESSION_TEXT = "invalid decode session";
|
||||
|
||||
public enum CategoryID {
|
||||
AIR_CONDITIONER(1),
|
||||
TV(2),
|
||||
|
||||
Reference in New Issue
Block a user