Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Commit

Permalink
调整服务http请求未异步请求,提高登录速度
Browse files Browse the repository at this point in the history
  • Loading branch information
Acexy committed Oct 9, 2018
1 parent a0ba42a commit 64247ba
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 42 deletions.
59 changes: 30 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,36 @@
---
> ### Bug fixes & 升级备注
```
1.0.1
修复腾讯修改二维码校验流程带来的影响
1.0.2
调整代码易读性,增加稳定性等
代码结构调整
增加异常重试机制,增强稳定性
初始化SmartQQ的实现新增两个可选的构造参数
1.0.3
配合java-toolkit升级,修复async.http模块稳定性
配合async.http参数变更结构调整等
解决由于腾讯协议bug导致的自己发送的群消息识别为别人的信息
1.0.4
升级java-toolkit依赖的模块
1.0.5
升级依赖组件
调整代码结构
1.1.0
标注废除历史版本登录和应用初始化相关代码预计1.1.1将彻底移除)
新增提供基于Fluent Interface风格代码的初始化,并提供测试案例代码
调整部分代码注释,调整可配参数代码
废弃主动登录接口,合并到初始化自动完成
闭环登录环节的相关异常,各个需要业务控制的回调均提供反馈调用
增加稳定性,新增应用健康状态监控,提供优化掉线自动重连机制
1.1.1
移除了历史版本登录测试方法和历史登录的相关支持代码
调整了测试代码优化了大量代码注释
1.1.2
升级部分依赖组件版本
关闭httpclient cookie检查的警告日志
1.0.1
修复腾讯修改二维码校验流程带来的影响
1.0.2
调整代码易读性,增加稳定性等
代码结构调整
增加异常重试机制,增强稳定性
初始化SmartQQ的实现新增两个可选的构造参数
1.0.3
配合java-toolkit升级,修复async.http模块稳定性
配合async.http参数变更结构调整等
解决由于腾讯协议bug导致的自己发送的群消息识别为别人的信息
1.0.4
升级java-toolkit依赖的模块
1.0.5
升级依赖组件
调整代码结构
1.1.0
标注废除历史版本登录和应用初始化相关代码预计1.1.1将彻底移除)
新增提供基于Fluent Interface风格代码的初始化,并提供测试案例代码
调整部分代码注释,调整可配参数代码
废弃主动登录接口,合并到初始化自动完成
闭环登录环节的相关异常,各个需要业务控制的回调均提供反馈调用
增加稳定性,新增应用健康状态监控,提供优化掉线自动重连机制
1.1.1
移除了历史版本登录测试方法和历史登录的相关支持代码
调整了测试代码优化了大量代码注释
1.1.2
升级部分依赖组件版本
关闭httpclient cookie检查的警告日志
登录相关信息查询使用async.http的异步请求方式,提高登录速度
```
---
Expand Down
109 changes: 109 additions & 0 deletions src/main/java/com/thankjava/wqq/core/action/GetInfoAction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.thankjava.wqq.core.action;

import com.thankjava.wqq.extend.ActionListener;
import com.thankjava.wqq.extend.CallBackListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -43,6 +45,7 @@ public class GetInfoAction {
* @date 2016年12月22日 下午1:34:35
* @version 1.0
*/
@Deprecated
public FriendsList getFriendsList() {

AsyncResponse response = null;
Expand All @@ -62,6 +65,42 @@ public FriendsList getFriendsList() {
return null;
}

/**
* 异步获取好友列表
*
* @param callBackListener
* @param tryTimes
*/
public void getFriendsList(final CallBackListener callBackListener, final Integer... tryTimes) {

final int tryTime = tryTimes == null || tryTimes.length == 0 ? 1 : tryTimes[0] + 1;
if (tryTime >= ConfigParams.EXCEPTION_RETRY_MAX_TIME) {
logger.error("getUserFriends2 失败 (已尝试重试)");
callBackListener.onListener(new ActionListener(null));
return;
}

getUserFriends2.doRequest(new CallBackListener() {

@Override
public void onListener(ActionListener actionListener) {
if (actionListener.getData() != null) {
AsyncResponse asyncResponse = (AsyncResponse) actionListener.getData();
FriendsList friendsList = JSON2Entity.userFriends2(asyncResponse.getDataString());
if (friendsList != null) {
session.setFriendsList(friendsList);
callBackListener.onListener(new ActionListener(friendsList));
} else {
getFriendsList(callBackListener, tryTime);
}
} else {
getFriendsList(callBackListener, tryTime);
}
}

});
}

/**
* 为当前好友列表数据查询在线状态
* <p>Function: getOnlineStatus</p>
Expand All @@ -72,6 +111,7 @@ public FriendsList getFriendsList() {
* @date 2017年6月14日 下午2:46:17
* @version 1.0
*/
@Deprecated
public FriendsList getOnlineStatus() {

FriendsList friendsList = session.getFriendsList();
Expand All @@ -96,6 +136,41 @@ public FriendsList getOnlineStatus() {
return null;
}

public void getOnlineStatus(final CallBackListener callBackListener, final Integer... tryTimes) {

final int tryTime = tryTimes == null || tryTimes.length == 0 ? 1 : tryTimes[0] + 1;
if (tryTime >= ConfigParams.EXCEPTION_RETRY_MAX_TIME) {
logger.error("getOnlineBuddies2 失败 (已尝试重试)");
callBackListener.onListener(new ActionListener(null));
return;
}

getOnlineBuddies2.doRequest(new CallBackListener() {

@Override
public void onListener(ActionListener actionListener) {
FriendsList friendsList = session.getFriendsList();
if (friendsList == null) {
callBackListener.onListener(new ActionListener(null));
return;
}
if (actionListener.getData() != null) {
AsyncResponse asyncResponse = (AsyncResponse) actionListener.getData();
friendsList = JSON2Entity.onlineStatus(friendsList, asyncResponse.getDataString());
if (friendsList != null) {
session.setFriendsList(friendsList);
callBackListener.onListener(new ActionListener(friendsList));
} else {
getOnlineStatus(callBackListener, tryTime);
}
} else {
getOnlineStatus(callBackListener, tryTime);
}
}

});
}

/**
* 获取讨论组列表
* <p>Function: getDiscusList</p>
Expand Down Expand Up @@ -133,6 +208,7 @@ public DiscusList getDiscusList() {
* @date 2016年12月22日 下午1:56:17
* @version 1.0
*/
@Deprecated
public GroupsList getGroupsList() {
AsyncResponse response = null;
GroupsList groupList = null;
Expand All @@ -150,6 +226,36 @@ public GroupsList getGroupsList() {
return null;
}

public void getGroupsList(final CallBackListener callBackListener, final Integer... tryTimes) {

final int tryTime = tryTimes == null || tryTimes.length == 0 ? 1 : tryTimes[0] + 1;

if (tryTime >= ConfigParams.EXCEPTION_RETRY_MAX_TIME) {
logger.error("getGroupNameListMask2 失败 (已尝试重试)");
callBackListener.onListener(new ActionListener(null));
return;
}

getGroupNameListMask2.doRequest(new CallBackListener() {
@Override
public void onListener(ActionListener actionListener) {
if (actionListener.getData() != null) {
AsyncResponse asyncResponse = (AsyncResponse) actionListener.getData();
GroupsList groupList = JSON2Entity.getGroupsList(asyncResponse.getDataString());
if (groupList != null) {
session.setGroupsList(groupList);
callBackListener.onListener(new ActionListener(groupList));
} else {
getOnlineStatus(callBackListener, tryTime);
}
} else {
getOnlineStatus(callBackListener, tryTime);
}
}

});
}

/**
* 获取个人信息(登录人)
* <p>Function: getSelfInfo</p>
Expand Down Expand Up @@ -178,6 +284,9 @@ public DetailedInfo getSelfInfo() {
return null;
}

public void getSelfInfo(final CallBackListener callBackListener, final Integer... tryTimes) {
}

void getRecentList() {
getRecentList2.doRequest(null).isEmptyDataString();
}
Expand Down
53 changes: 43 additions & 10 deletions src/main/java/com/thankjava/wqq/core/action/LoginAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,52 @@ private boolean beginLogin() {

if (ConfigParams.INIT_LOGIN_INFO) {

FriendsList friendsList = getInfo.getFriendsList();
if (friendsList == null) {
logger.error("获取好友列表失败");
} else {
friendsList = getInfo.getOnlineStatus();
if (friendsList == null) {
logger.error("为好友列表查询在线状态失败");
getInfo.getFriendsList(new CallBackListener() {
@Override
public void onListener(ActionListener actionListener) {
if (actionListener.getData() == null) {
logger.error("获取好友列表失败");
} else {
logger.debug("获取好友列表成功");
getInfo.getOnlineStatus(new CallBackListener() {
@Override
public void onListener(ActionListener actionListener) {
if (actionListener.getData() == null) {
logger.error("查询好友状态失败");
} else {
logger.error("查询好友状态失败");
}
}
});
}
}
}
getInfo.getGroupsList();
getInfo.getDiscusList();
});

getInfo.getGroupsList(new CallBackListener() {
@Override
public void onListener(ActionListener actionListener) {
if (actionListener.getData() != null) {
logger.debug("获取群列表成功");
}
}
});

// FriendsList friendsList = getInfo.getFriendsList();
// if (friendsList == null) {
// logger.error("获取好友列表失败");
// } else {
// friendsList = getInfo.getOnlineStatus();
// if (friendsList == null) {
// logger.error("为好友列表查询在线状态失败");
// }
// }
// getInfo.getGroupsList();
// getInfo.getDiscusList();
getInfo.getSelfInfo();
getInfo.getRecentList();



}


Expand Down
26 changes: 24 additions & 2 deletions src/main/java/com/thankjava/wqq/core/request/aop/DoRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.lang.reflect.Method;

import com.thankjava.toolkit3d.http.async.entity.AsyncResponse;
import com.thankjava.toolkit3d.http.async.entity.AsyncResponseCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -27,7 +29,7 @@ public AopParam doRequest(AopParam aopParam) {
aopParam.setInvokeProxyMethod(false);

// 获取被代理的函数的参数列
CallBackListener listener = (CallBackListener) aopParam.getParams()[0];
final CallBackListener listener = (CallBackListener) aopParam.getParams()[0];

// 执行buildRequestParams 得到请求的参数体
Object proxyInstance = aopParam.getProxyInstance();
Expand All @@ -36,9 +38,28 @@ public AopParam doRequest(AopParam aopParam) {
AsyncRequest asyncRequest = (AsyncRequest) ReflectHelper.invokeMethod(proxyInstance, method);

if (listener != null) {

// 如果传递了listener 则通过listener的方式回调返回
try {
listener.onListener(new ActionListener((asyncHttpClient.syncRequestWithSession(asyncRequest))));

asyncHttpClient.asyncRequestWithSession(asyncRequest, new AsyncResponseCallback() {

@Override
public void completed(AsyncResponse asyncResponse) {
listener.onListener(new ActionListener(asyncResponse));
}

@Override
public void failed(Exception e) {
listener.onListener(new ActionListener(null));
}

@Override
public void cancelled() {
listener.onListener(new ActionListener(null));
}

});
} catch (Throwable e) {
logger.error("http request error", e);
listener.onListener(new ActionListener());
Expand All @@ -52,6 +73,7 @@ public AopParam doRequest(AopParam aopParam) {
aopParam.setResult(null);
logger.error("http request error", e);
}

}

// 通过普通的方式返回结果
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import com.thankjava.toolkit3d.http.async.AsyncHttpClient;
import com.thankjava.toolkit3d.http.async.AsyncHttpClientBuilder;
import com.thankjava.toolkit3d.http.async.consts.CookieCheckLevel;
import com.thankjava.toolkit3d.http.async.entity.AsyncRequest;
import com.thankjava.toolkit3d.http.async.entity.CookieCheckLevel;
import com.thankjava.wqq.consts.ConstsParams;
import com.thankjava.wqq.core.request.RequestBuilder;
import com.thankjava.wqq.entity.Session;
Expand Down

0 comments on commit 64247ba

Please sign in to comment.