From 61dc6e54c41c175c69486064935ca95c3ae1accf Mon Sep 17 00:00:00 2001 From: liqi Date: Wed, 26 Jul 2017 11:10:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=93=E5=8D=B0=E6=9C=AA?= =?UTF-8?q?=E7=9F=A5=E9=94=99=E8=AF=AF=E6=97=A5=E5=BF=97=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=9B=A0=E4=B8=BA=E6=9C=AA=E7=9F=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=BC=95=E5=8F=91=E7=9A=84=E8=AF=B7=E6=B1=82=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E6=B1=A0=E6=9C=80=E5=A4=A7=E5=B9=B6=E5=8F=91=E9=87=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加打印未知错误日志,修改因为未知错误引发的请求线程池最大并发量问题。 --- .../com/liqi/nohttputils/nohttp/RxNoHttp.java | 8 +++++ .../nohttp/RxThreadInterchange.java | 16 +++++---- .../thread/RxThreadDispatch.java | 9 ++++- .../nohttprxutils/GetPostDemoActivity.java | 34 ++++++++++++++++++- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/nohttputils/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java b/nohttputils/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java index a3ad1af..1953ccb 100644 --- a/nohttputils/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java +++ b/nohttputils/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java @@ -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; @@ -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; diff --git a/nohttputils/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java b/nohttputils/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java index 2211e02..f33073a 100644 --- a/nohttputils/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java +++ b/nohttputils/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java @@ -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; @@ -65,7 +65,7 @@ static RxThreadInterchange getRxThreadInterchange() { * @param onRxMessageGetListener 数据源对内暴露接口 * @param */ - void start(@NonNull OnRxMessageGetListener onRxMessageGetListener) { + void start(@NonNull OnRxMessageGetListener onRxMessageGetListener) { if (null == mOnRxMessageDisListener) { selectOkState(onRxMessageGetListener); } else { @@ -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); } diff --git a/nohttputils/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/thread/RxThreadDispatch.java b/nohttputils/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/thread/RxThreadDispatch.java index 4d11285..f7d695a 100644 --- a/nohttputils/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/thread/RxThreadDispatch.java +++ b/nohttputils/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/thread/RxThreadDispatch.java @@ -14,7 +14,9 @@ */ public class RxThreadDispatch extends Thread { - //并发最大值 + //固定并发最大值 + private int mFixedRunSize; + //要操作的并发最大值 private int mRunSize; //数据源 private List mList; @@ -29,6 +31,7 @@ public class RxThreadDispatch extends Thread { public RxThreadDispatch(int runSize, @NonNull List list) { this.mRunSize = runSize; + this.mFixedRunSize = runSize; this.mList = list; } @@ -126,6 +129,10 @@ public void run() { public void addRunSize() { synchronized (this) { ++mRunSize; + + if (mRunSize > mFixedRunSize) { + mRunSize = mFixedRunSize; + } //Logger.e("运行次数:++运行次数相加" + mRunSize); } } diff --git a/sample/src/main/java/com/liqi/nohttprxutils/GetPostDemoActivity.java b/sample/src/main/java/com/liqi/nohttprxutils/GetPostDemoActivity.java index eb0dc17..3343168 100644 --- a/sample/src/main/java/com/liqi/nohttprxutils/GetPostDemoActivity.java +++ b/sample/src/main/java/com/liqi/nohttprxutils/GetPostDemoActivity.java @@ -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 @@ -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; @@ -63,7 +95,7 @@ public void onClick(View v) { .setSign(this) .builder(String.class, this) .requestRxNoHttp(); - RxNoHttpUtils.cancel(this); + //RxNoHttpUtils.cancel(this); break; } }