Skip to content

Commit

Permalink
增加打印未知错误日志,修改因为未知错误引发的请求线程池最大并发量问题。
Browse files Browse the repository at this point in the history
增加打印未知错误日志,修改因为未知错误引发的请求线程池最大并发量问题。
  • Loading branch information
liqi committed Jul 26, 2017
1 parent 9d3a146 commit 61dc6e5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.liqi.nohttputils.R;
import com.liqi.nohttputils.interfa.DialogGetListener;
import com.liqi.nohttputils.interfa.OnIsRequestListener;
import com.yanzhenjie.nohttp.Logger;
import com.yanzhenjie.nohttp.NoHttp;
import com.yanzhenjie.nohttp.error.NetworkError;
import com.yanzhenjie.nohttp.error.NotFoundCacheError;
Expand Down Expand Up @@ -106,6 +107,13 @@ public void onError(Throwable e) {
} else if (e instanceof ProtocolException) {
show(R.string.error_system_unsupport_method);
} else {
Logger.e("NoHttpUtils捕获异常:"+e.toString());
StackTraceElement[] stackTrace = e.getStackTrace();
if (null!=stackTrace) {
for (StackTraceElement traceElement : stackTrace) {
Logger.e("NoHttpUtils捕获异常:"+traceElement.toString());
}
}
show(R.string.error_unknow);
}
dialog = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* Created by LiQi on 2017/3/20.
*/

public class RxThreadInterchange implements RxThreadDispatch.OnRunDataDisListener {
public class RxThreadInterchange implements RxThreadDispatch.OnRunDataDisListener {
//Rx线程池并发数量处理值
private static final int RUNSIZE = RxUtilsConfig.ConfigBuilder.getConfigBuilder().getRxUtilsConfig().getRunRequestSize();
private static RxThreadInterchange mRxThreadInterchange;
Expand Down Expand Up @@ -65,7 +65,7 @@ static RxThreadInterchange getRxThreadInterchange() {
* @param onRxMessageGetListener 数据源对内暴露接口
* @param <T>
*/
<T extends BaseRxRequestModel> void start(@NonNull OnRxMessageGetListener<T> onRxMessageGetListener) {
<T extends BaseRxRequestModel> void start(@NonNull OnRxMessageGetListener<T> onRxMessageGetListener) {
if (null == mOnRxMessageDisListener) {
selectOkState(onRxMessageGetListener);
} else {
Expand Down Expand Up @@ -163,12 +163,14 @@ public void onError(Throwable e) {
} else if (e instanceof ProtocolException) {
show(dialog, R.string.error_system_unsupport_method);
} else {
//撤销请求
if (e.getMessage().contains(REQUEST_REVOCATION)) {
Logger.e(e.getMessage());
} else {
show(dialog, R.string.error_unknow);
Logger.e("NoHttpUtils捕获异常:"+e.toString());
StackTraceElement[] stackTrace = e.getStackTrace();
if (null!=stackTrace) {
for (StackTraceElement traceElement : stackTrace) {
Logger.e("NoHttpUtils捕获异常:"+traceElement.toString());
}
}
show(dialog, R.string.error_unknow);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
*/

public class RxThreadDispatch extends Thread {
//并发最大值
//固定并发最大值
private int mFixedRunSize;
//要操作的并发最大值
private int mRunSize;
//数据源
private List<BaseRxRequestModel> mList;
Expand All @@ -29,6 +31,7 @@ public class RxThreadDispatch extends Thread {

public RxThreadDispatch(int runSize, @NonNull List<BaseRxRequestModel> list) {
this.mRunSize = runSize;
this.mFixedRunSize = runSize;
this.mList = list;
}

Expand Down Expand Up @@ -126,6 +129,10 @@ public void run() {
public void addRunSize() {
synchronized (this) {
++mRunSize;

if (mRunSize > mFixedRunSize) {
mRunSize = mFixedRunSize;
}
//Logger.e("运行次数:++运行次数相加" + mRunSize);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ protected void onCreate() {
mPost.setOnClickListener(this);
mPost.setAlpha(0.6f);
mContent = $(R.id.content);
//清除对应的key的缓存数据
// RxNoHttpUtils.removeKeyCacheData("Cachekey");
//清除所有缓存数据
// RxNoHttpUtils.removeAllCacheData();
}

@Override
Expand All @@ -47,6 +51,34 @@ public void onClick(View v) {
//.setCacheKey("get请求Key")
//单个请求设置缓存模式
// .setCacheMode(CacheMode.REQUEST_NETWORK_FAILED_READ_CACHE)
//设置请求bodyEntity为StringEntity,并传请求类型。
//.requestStringEntity(Content-Type)
//为StringEntity添加body中String值
//.addStringEntityParameter("请求的String")
//从bodyEntity切换到请求配置对象
// .transitionToRequest()
//设置请求bodyEntity为JsonObjectEntity.json格式:{"xx":"xxx","yy":"yyy"}
// .requestJsonObjectEntity()
//给JsonObjectEntity添加参数和值
//.addEntityParameter("key","Valu")
//从bodyEntity切换到请求配置对象
// .transitionToRequest()
//设置请求bodyEntity为JsonListEntity.json格式:[{"xx":"xxx"},{"yy":"yyy"}]
//.requestJsonListEntity()
//给JsonList创造对象,并传键值参数
//.addObjectEntityParameter("key","Valu")
//在创造对象的上添加键值参数
//.addEntityParameter("key","Valu")
//把创造对象刷进进JsonList里面
//.objectBrushIntoList()
//从bodyEntity切换到请求配置对象
//.transitionToRequest()
//设置请求bodyEntity为InputStreamEntity
//.requestInputStreamEntity(Content-Type)
//给InputStreamEntity添加输入流
//.addEntityInputStreamParameter(InputStream)
//从bodyEntity切换到请求配置对象
//.transitionToRequest()
.builder(String.class, this)
.requestRxNoHttp();
break;
Expand All @@ -63,7 +95,7 @@ public void onClick(View v) {
.setSign(this)
.builder(String.class, this)
.requestRxNoHttp();
RxNoHttpUtils.cancel(this);
//RxNoHttpUtils.cancel(this);
break;
}
}
Expand Down

0 comments on commit 61dc6e5

Please sign in to comment.