Save volley from anything, By Agera to save. Thus, derived the AgeraVolley . (?>﹏<?)
gson: 2.7
fastjson: 1.1.52.android
agera: 1.1.0
okhttp3: 3.3.1
dependencies {
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.okhttp3:okhttp:3.3.1'
compile 'com.google.android.agera:agera:1.1.0'
// for okhttp3
compile 'com.camnter.savevolley:okhttp3:1.6.6'
// for gson
compile 'com.camnter.savevolley:savevolley-okhttp3-agera-gson:1.6.6'
}
可使用 SaveVolley
Flow 和 agera
Flow 。
SaveVolley saveVolley = SaveVolleys
.<GankData>request(TEST_URL)
.method(Method.GET)
.parseStyle(GSON)
.classOf(GankData.class)
.createRequest()
.context(this)
.compile();
final Repository<GankResultData> repository = Repositories.repositoryWithInitialValue(
INITIAL_VALUE)
.observe(saveVolley.getReservoir())
.onUpdatesPerLoop()
.goTo(executor)
.attemptGetFrom(saveVolley.getReservoir())
.orSkip()
.thenAttemptTransform(new Function<Object, Result<GankResultData>>() {
/**
* Returns the result of applying this function to {@code input}.
*/
@NonNull @Override public Result<GankResultData> apply(@NonNull Object input) {
if (input instanceof GankData) {
return Result.success(((GankData) input).results.get(0));
} else if (input instanceof VolleyError) {
return Result.failure((VolleyError) input);
}
return Result.failure();
}
})
.orSkip()
.compile();
repository.addUpdatable(new Updatable() {
@Override public void update() {
getContentText.setText(repository.get().toString());
}
});
dependencies {
compile 'com.alibaba:fastjson:1.1.52.android'
compile 'com.squareup.okhttp3:okhttp:3.3.1'
compile 'com.google.android.agera:agera:1.1.0'
// for okhttp3
compile 'com.camnter.savevolley:okhttp3:1.6.6'
// for fastjson
compile 'com.camnter.savevolley:savevolley-okhttp3-agera-fastjson:1.6.6'
}
SaveVolley saveVolley = SaveVolleys
.<GankData>request(TEST_URL)
.method(Method.GET)
.parseStyle(FASTJSON)
.classOf(GankData.class)
.createRequest()
.context(this)
.compile();
final Repository<GankResultData> repository = Repositories
.repositoryWithInitialValue(INITIAL_VALUE)
.observe(saveVolley.getReservoir())
.onUpdatesPerLoop()
.goTo(executor)
.attemptGetFrom(saveVolley.getReservoir())
.orSkip()
.thenAttemptTransform(new Function<Object, Result<GankResultData>>() {
/**
* Returns the result of applying this function to {@code input}.
*/
@NonNull @Override public Result<GankResultData> apply(@NonNull Object input) {
if (input instanceof GankData) {
return Result.success(((GankData) input).results.get(0));
} else if (input instanceof VolleyError) {
return Result.failure((VolleyError) input);
}
return Result.failure();
}
})
.orSkip()
.compile();
repository.addUpdatable(new Updatable() {
@Override public void update() {
getContentText.setText(repository.get().toString());
}
});
可使用 SaveVolley
Flow 和 agera
Flow 。
dependencies {
compile 'com.google.code.gson:gson:2.7'
compile 'com.google.android.agera:agera:1.1.0'
// for hurl
compile 'com.camnter.savevolley:hurl:1.6.6'
// for gson
compile 'com.camnter.savevolley:savevolley-hurl-agera-gson:1.6.6'
}
SaveVolley saveVolley = SaveVolleys
.<GankData>request(TEST_URL)
.method(Method.GET)
.parseStyle(GSON)
.classOf(GankData.class)
.createRequest()
.context(this)
.compile();
final Repository<GankResultData> repository = Repositories.repositoryWithInitialValue(
INITIAL_VALUE)
.observe(saveVolley.getReservoir())
.onUpdatesPerLoop()
.goTo(executor)
.attemptGetFrom(saveVolley.getReservoir())
.orSkip()
.thenAttemptTransform(new Function<Object, Result<GankResultData>>() {
/**
* Returns the result of applying this function to {@code input}.
*/
@NonNull @Override public Result<GankResultData> apply(@NonNull Object input) {
if (input instanceof GankData) {
return Result.success(((GankData) input).results.get(0));
} else if (input instanceof VolleyError) {
return Result.failure((VolleyError) input);
}
return Result.failure();
}
})
.orSkip()
.compile();
repository.addUpdatable(new Updatable() {
@Override public void update() {
getContentText.setText(repository.get().toString());
}
});
dependencies {
compile 'com.alibaba:fastjson:1.1.52.android'
compile 'com.google.android.agera:agera:1.1.0'
// for hurl
compile 'com.camnter.savevolley:hurl:1.6.6'
// for fastjson
compile 'com.camnter.savevolley:savevolley-hurl-agera-fastjson:1.6.6'
}
SaveVolley saveVolley = SaveVolleys
.<GankData>request(TEST_URL)
.method(Method.GET)
.parseStyle(FASTJSON)
.classOf(GankData.class)
.createRequest()
.context(this)
.compile();
final Repository<GankResultData> repository = Repositories
.repositoryWithInitialValue(INITIAL_VALUE)
.observe(saveVolley.getReservoir())
.onUpdatesPerLoop()
.goTo(executor)
.attemptGetFrom(saveVolley.getReservoir())
.orSkip()
.thenAttemptTransform(new Function<Object, Result<GankResultData>>() {
/**
* Returns the result of applying this function to {@code input}.
*/
@NonNull @Override public Result<GankResultData> apply(@NonNull Object input) {
if (input instanceof GankData) {
return Result.success(((GankData) input).results.get(0));
} else if (input instanceof VolleyError) {
return Result.failure((VolleyError) input);
}
return Result.failure();
}
})
.orSkip()
.compile();
repository.addUpdatable(new Updatable() {
@Override public void update() {
getContentText.setText(repository.get().toString());
}
});
dependencies {
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.okhttp3:okhttp:3.3.1'
// for okhttp3
compile 'com.camnter.savevolley:okhttp3:1.6.6'
// for gson
compile 'com.camnter.savevolley:savevolley-okhttp3-gson:1.6.6'
}
可使用 OkHttp3GsonRequest
。
RequestQueue queue = Volley.newRequestQueue(this);
queue.add(new OkHttp3GsonRequest<GankData>(TEST_URL,
GankData.class) {
/**
* Called when a response is received.
*/
@Override public void onResponse(GankData response) {
getContentText.setText(response.toString());
}
/**
* Callback method that an error has been occurred with the
* provided error code and optional user-readable message.
*/
@Override public void onErrorResponse(VolleyError error) {
Toast.makeText(Okhttp3GsonActivity.this,
error != null && error.getMessage() != null
? error.getMessage()
: "No error message", Toast.LENGTH_LONG)
.show();
Log.d("GsonRequest", error != null && error.getMessage() != null
? error.getMessage()
: "No error message");
}
});
dependencies {
compile 'com.alibaba:fastjson:1.1.52.android'
// for okhttp3
compile 'com.camnter.savevolley:okhttp3:1.6.6'
// for fastjson
compile 'com.camnter.savevolley:savevolley-okhttp3-fastjson:1.6.6'
}
可使用 Okhttp3FastjsonRequest
。
RequestQueue queue = Volley.newRequestQueue(this);
queue.add(new OkHttp3FastjsonRequest<GankData>(TEST_URL, GankData.class) {
/**
* Called when a response is received.
*/
@Override public void onResponse(GankData response) {
getContentText.setText(response.toString());
}
/**
* Callback method that an error has been occurred with the
* provided error code and optional user-readable message.
*/
@Override public void onErrorResponse(VolleyError error) {
Toast.makeText(Okhttp3FastjsonActivity.this,
error != null && error.getMessage() != null
? error.getMessage()
: "No error message", Toast.LENGTH_LONG)
.show();
Log.d("GsonRequest", error != null && error.getMessage() != null
? error.getMessage()
: "No error message");
}
});
dependencies {
compile 'com.google.code.gson:gson:2.7'
// for hurl
compile 'com.camnter.savevolley:hurl:1.6.6'
// for gson
compile 'com.camnter.savevolley:savevolley-hurl-gson:1.6.6'
}
可使用 HurlGsonRequest
。
RequestQueue queue = Volley.newRequestQueue(this);
queue.add(new HurlGsonRequest<GankData>(TEST_URL,
GankData.class) {
/**
* Called when a response is received.
*/
@Override public void onResponse(GankData response) {
getContentText.setText(response.toString());
}
/**
* Callback method that an error has been occurred with the
* provided error code and optional user-readable message.
*/
@Override public void onErrorResponse(VolleyError error) {
Toast.makeText(HurlGsonActivity.this,
error != null && error.getMessage() != null
? error.getMessage()
: "No error message", Toast.LENGTH_LONG)
.show();
Log.d("GsonRequest", error != null && error.getMessage() != null
? error.getMessage()
: "No error message");
}
});
dependencies {
compile 'com.alibaba:fastjson:1.1.52.android'
// for hurl
compile 'com.camnter.savevolley:hurl:1.6.6'
// for fastjson
compile 'com.camnter.savevolley:savevolley-hurl-fastjson:1.6.6'
}
可使用 HurlFastjsonRequest
。
RequestQueue queue = Volley.newRequestQueue(this);
queue.add(new HurlFastjsonRequest<GankData>(TEST_URL, GankData.class) {
/**
* Called when a response is received.
*/
@Override public void onResponse(GankData response) {
getContentText.setText(response.toString());
}
/**
* Callback method that an error has been occurred with the
* provided error code and optional user-readable message.
*/
@Override public void onErrorResponse(VolleyError error) {
Toast.makeText(HurlFastjsonActivity.this,
error != null && error.getMessage() != null
? error.getMessage()
: "No error message", Toast.LENGTH_LONG)
.show();
Log.d("GsonRequest", error != null && error.getMessage() != null
? error.getMessage()
: "No error message");
}
});
dependencies {
// for okhttp3
compile 'com.camnter.savevolley:okhttp3:1.6.6'
}
savevolley-okhttp3
將 原版的 google/volley 中 網絡實現層 的 Apache HttpClient 和 原生的 HttpUrlConnection 都移除。
換成 square/okhttp3 作為實現網絡要求。
dependencies {
// for hurl
compile 'com.camnter.savevolley:hurl:1.6.6'
}
API >= 9
savevolley-hurl
移除 原版 google/volley 中的,所有相干與 HttpClient 的邏輯,全版本的網絡通訊接入到 HttpUrlConnection 內。
savevolley-network-core
由于,網絡底層實現( 網絡要求實現 )可以通過不同框架( okhttp、HttpUrlConnection、Apache HttpClient … )去實現。
所以,只是拿到 不同框架的響應結果。
但是 Volley 的緩存層是 通用的,所以需要定義1套 通用的 HTTP Response API,然后將 不同框架的響應結果 轉換為
通用的 HTTP Response API。
這個模塊還需要與 savevolley-network-adapter 的子模塊( savevolley-network-okhttp3-adapter, savevolley-network-hurl-adapter )1起協作。
savevolley-network-adapter
目的是為了定義1些接口: 不同框架的響應結果 >> 通用的 HTTP Response API。
子模塊有: savevolley-network-okhttp3-adapter, savevolley-network-hurl-adapter 。
savevolley-network-okhttp3-adapter
savevolley-network-adapter 的子模塊,square/okhttp Response >> 通用的 HTTP Response API。
savevolley-network-hurl-adapter
savevolley-network-adapter 的子模塊,HttpConnection >> 通用的 HTTP Response API。
savevolley-hurl-agera-core
作用: 提供1些 hurl 與 agera 協作需要的基礎類。
savevolley-okhttp3-agera-core
作用: 提供1些 okhttp3 與 agera 協作需要的基礎類。
savevolley-okhttp3-agera-gson
作用: agera >> savevolley-okhttp3 << gson , 為 savevolley-okhttp3 橋接了 agera 和 gson 。
savevolley-hurl-agera-gson
作用: agera >> savevolley-hurl << gson , 為 savevolley-hurl 橋接了 agera 和 gson 。
savevolley-okhttp3-agera-fastjson
作用: agera >> savevolley-okhttp3 << fastjson , 為 savevolley-okhttp3 橋接了 agera 和 fastjson 。
savevolley-hurl-agera-fastjson
作用: agera >> savevolley-hurl << fastjson , 為 savevolley-hurl 橋接了 agera 和 fastjson 。
savevolley-hurl-fastjson
作用: fastjson >> savevolley-hurl 。
savevolley-okhttp3-fastjson
作用: fastjson >> savevolley-okhttp3 。
savevolley-hurl-gson
作用: gson >> savevolley-hurl 。
savevolley-okhttp3-gson
作用: gson >> savevolley-okhttp3 。
square/okhttp Version: 3.3.1
google/agera Version: 1.1.0-beta2
volley-comments
原版的 google/volley,全部代碼加上了注釋。
Volley:Volley 框架使用的入口,用于創建1個 RequestQueue。
1. RequestQueue queue = Volley.newRequestQueue(this)
2. queue.add(request)
RequestQueue:RequestQueue
被定義為 要求隊列。用于操作 緩存要求履行線程( CacheDispatcher
)和 網絡要求履行線程( NetworkDispatcher
)。默許的情況下:
1. 啟動 1 個 緩存要求履行線程( CacheDispatcher
)。
2. 根據 DEFAULT_NETWORK_THREAD_POOL_SIZE
的值,啟動 4 個 網絡要求履行線程( NetworkDispatcher
)。
3. 這些線程同享 緩存要求隊列 ( mCacheQueue
)和 網絡要求隊列( mNetworkQueue
),當 RequestQueue
進行 要求的 添加、結束時,都會進入同步操作,保證線程安全。所以,RequestQueue
進行 要求的 添加、結束。是直接影響 CacheDispatcher 和 NetworkDispatcher 的履行。
NetworkDispatcher:是用于處理 Volley 中的網絡要求 的 網絡線程,會將 網絡 Request
隊列的 Request
逐一抽出,然落后行網絡要求:
1. 成功,拿到數據進行解析,然后將 Response
進行硬盤緩存,緩存成 Cache.Entry
的情勢,最后 傳遞 Request
和 Response
數據。
2. 失敗,失敗的話,1般會拋出異常,然落后行 記錄要求時長 和 傳遞毛病( VolleyError )。
CacheDispatcher:是用于處理 Volley 中的緩存數據 的 緩存線程。
1.1. 檢查緩存。從 緩存 Request
隊列中取出 緩存 Request,然后 根據 緩存 Request CacheKey 去硬盤緩存( DiskBasedCache
)映照過來的內存緩存中尋覓 是不是存在 Entry
( Response
)。
1.2. 存在的話,通過 DefaultRetryPolicy
回傳相干數據。
1.3. 存在但緩存需要刷新的話,放入 網絡 Request 隊列 內,會在 NetworkDispatcher
的循環體中被用來 重新要求。
1.4. 不存在的話,將該 Request,放入 網絡 Request 隊列 內,會在 NetworkDispatcher
的循環體中被用來 重新要求。
2. CacheDispatcher
只做緩存相干的操作,不做網絡的操作。所以 CacheDispatcher
,只觸及到 緩存 Response 的增刪改查 和 查詢成功后的數據分發( 傳遞 )。
Network:在 Volley 中,是處理 網絡要求 的表層使用接口。只有1個方法:performRequest(...)
履行要求,
BasicNetwork:BasicNetwork
是 目前 Volley 內,Network
接口的唯1實現類,在 Volley 內,處理了 網絡要求 的表層使用接口。實現了 performRequest(...)
方法的具體功能,performRequest(...)
要做的事情是:
1. 調用 HttpStack
接口的實現類 ( HurlStack
, HttpClientStack
) 去履行網絡要求實現,會拿到1個 Apache HttpResponse
。
2. 然后,將 Apache HttpResponse -> Volley NetworkResponse 進行轉化,并返回。
HttpStack:HttpStack
是 Volley 內 履行 網絡要求 的 底層實現接口。實現類有:
1. HttpClientStack
:基于 org.apache.http
的網絡要求實現。負責 系統版本 2.3 以下 的 網絡要求實現。
2. HurlStack
:基于 HttpURLConnection
的網絡要求實現。負責 系統版本 2.3 以上 的 網絡要求實現。
HttpClientStack:HttpClientStack
實現了 HttpStack
接口。封裝了基于 org.apache.http.HttpClient
提供的網絡實現( performRequest(...)
),處理了 2.3 版本以下的 各種網絡要求( GET、POST、DEL … )的實現。
HurlStack:HurlStack
實現了 HttpStack
接口。封裝了基于 javax.net.ssl.HttpsURLConnection
提供的網絡實現( performRequest(...)
),處理了 2.3 版本以上的 各種網絡要求( GET、POST、DEL … )的實現。
Request:Volley 內所有抽象要求的 基類。
StringRequest:繼承擴大了 Request
,指定了泛型為 <String>
。會將要求結果解析成 String
類型數據,并且 需要你 傳入1個 Response.Listener<String>
進行解析結果數據進行回調。
JsonRequest:JsonRequest<T>
抽象繼承了 Request<T>
類。
1. 進行了Request<T>
-> JsonRequest<T>
的轉換。
2. 將要求結果數據 根據 “charset=utf⑻” 轉換為 byte[]。
3. 通過覆寫 getBodyContentType()
方法,將 Content-Type 設置為 application/json; charset=utf⑻。
JsonObjectRequest:JsonObjectRequest
繼承自 JsonRequest<JSONObject>
,將 JsonRequest<T>
的泛型 T,設置為 JSONObject
。JsonRequest<T>
沒有解析 body 內的數據為 真實的 Json 數據。所以,JsonObjectRequest
要單獨將 body 內的數據解析為 JSONObject
類型。
JsonArrayRequest:JsonArrayRequest
繼承自 JsonRequest<JSONArray>
,將 JsonRequest<T>
的泛型 T,設置為 JSONArray
。JsonRequest<T>
沒有解析 body 內的數據為 真實的 Json 數據。所以,JsonArrayRequest
要單獨將 body 內的數據解析為 JSONArray
類型。
ImageRequest:繼承擴大了 Request
,指定了泛型為 <Bitmap>
,會將要求結果解析成 Bitmap 類型數據。并且需要你傳入:
1. Response.Listener<Bitmap>
:將解析結果數據 進行回調。
2. maxWidth
:最大寬度。
3. maxHeight
:最大高度。
4. ScaleType
:ImageView
的 ScaleType
( CENTER_CROP, FIT_XY … )。
5. Config
:Bitmap 的 Config
( ALPHA_8, RGB_565, ARGB_4444, ARGB_8888 )。
6. Response.ErrorListener
:要求結果 Response 產生毛病的回調接口。
ClearCacheRequest:ClearCacheRequest
繼承自 Request<Object>
,用于清空 HTTP 緩存的要求。如果該要求被添加到 要求隊列( RequestQueue )中,由于覆寫了 getPriority()
方法,將優先級設置為 Priority.IMMEDIATE ( 立即履行 )。
Response:要求結果(響應)類。
1. 寄存 要求結果數據 和 緩存 key;或 毛病信息( VolleyError )。
2. 提供1個 Listener
接口。當接遭到 要求結果(響應)時,將 解析結果 返回。
3. 再提供1個 ErrorListener
接口。產生毛病時,將調用該方法,將返回 VolleyError
。
4. 提供1個靜態方法 success(...)
,實例1個有 要求結果數據 的 Response 對象。
5. 再提供1個靜態方法 error(...)
,實例1個只有 毛病信息( VolleyError ) 的 Response
對象
Cache:Volley 緩存的接口。提供1些接口方法,需要子類去實現,全 Volley 中主要實現類,只有1個 DiskBasedCache
。
DiskBasedCache:DiskBasedCache
是 Cache
的實現類。用于將保存緩存文件在硬盤上的指定目錄中,默許的緩存大小是 5MB,緩存大小是可以手動配置的。
1. 實例化了1個 LinkedHashMap<String, CacheHeader>
,accessOrder
設置為 true。即,依照訪問順序對數據進行排序,就是 LRU 的簡單時間。容量 initialCapacity
為默許值 16,雖然手動寫了 16。負載因子 loadFactor
默許值 0.75f,雖然手動寫了 0.75。負載因子是 當容量超過這個百分比就會擴容,0.75f 的話,就是容量超過75%就會擴容。
2. 在 initialize()
的時候:<1>.:判斷緩存目錄是不是存在,不存在則創建1系列文件夾,然后返回。<2>.:存在緩存文件,開始讀取緩存文件內容。每個緩存文件內容對應1個 CacheHeader
。會給上述的 LinkedHashMap<String, CacheHeader>
, CacheHeader
緩存的內容進行添加,把文件緩存的內容映照過來。
NoCache:繼承了 Cache
,不做任何操作的緩存實現類。可以作為 RequestQueue
構造方法的參數,實現1個不帶緩存的要求隊列。
ResponseDelivery:ResponseDelivery 接口的作用 -> 從 內存緩存 或 服務器 獲得要求結果數據,由 ResponseDelivery
去做結果分發和回調解理。
ExecutorDelivery:ExecutorDelivery
實現了 ResponseDelivery
接口。
主要功能就是:
1. 傳遞 要求、要求結果 or 相應毛病 和 可能有自定義的 Runnable
履行回調操作。
2. 定義了1個 Executor
,由于可能會有自定義的 Runnable
履行回調操作,所以需要它的存在。
3. 由于有 Executor
和 Runnable
的存在,但是都在子線程內。所以,還需要傳入1個 UI 線程的 Handler
(大多情況回調都是跟 UI 線程通訊),可以在 RequestQueue
類中 搜搜 new Handler(Looper.getMainLooper()) 關鍵句。
構造方法也是有趣設計:
1. Handler
作為參數的構造方法。全 Volley 只有 RequestQueue
內使用,并且傳入1個 UI 線程的 Handler
。可以簡單得出:這個構造方法可以指定( 不只是 UI 線程 )線程的 Handler
去處理這個 Runnable
。看過 Handler
源碼的都知道:你給我1個 Runnable
,我會 拿到這個 Handler
實例化時的 Looper
。再拿到 MessageQueue
去添加1條 Message
,Runnable
則作為 這個 Message.callback
保存在這,然后再 Handler.dispatchMessage(…) 的時候,會履行 Message.callback.run()。所以,這里(不只是 UI 線程)線程的 Handler
,說明了可以給其他線程傳遞( 通訊 )。
2. Executor
作為參數的構造方法。這里由于 Executor
作為外部提供的參數,那末 Handler
也在外面提供了,更具有可定制性。Handler
作為參數的構造方法 就是 這個 Executor
作為參數的構造方法 的升級版。由于,ExecutorDelivery
需要 Executor
和 Handler
,Handler
作為參數的構造方法:實例化了 Executor
,Handler
由外部提供,這里 Executor
是默許履行 handler.post(Runnable command)。Executor
作為參數的構造方法:都需要外部提供。
HttpHeaderParser:Http header 的解析工具類。
1. 解析 Header
,判斷返回結果是不是需要緩存。需要緩存的話,從網絡要求回來的要求結果 NetworkResponse
的 Header
中提取出1個用于緩存的 Cache.Entry
。
2. 解析編碼集,在 Content-Type 中獲得編碼集( charset ),可以根據 編碼 解析 Response.data 的 byte[] 數據。
RequestFuture:RequestFuture<T>
實現了 Future<T>
接口,用于對 Request
解析數據的結果 進行 取消、查詢是不是完成、獲得結果。
ByteArrayPool:1個 byte[] 緩存池,用于 byte[] 的回收再利用,減少內存分配和回收。
1. 內置1個 LinkedList
, 采取 LRU 的機制,最少使用的放在 index=0
,最近使用的 放在 index=size()⑴
。
2. 再內置1個 LinkedList
,緩存 byte[] 緩存 List,采取根據 byte[].length 由小到大的方式排序。排序使用 Collections.binarySearch(...)
,對應 Comparator<byte[]> BUF_COMPARATOR
。
PoolingByteArrayOutputStream:PoolingByteArrayOutputStream
繼承了 原生的 ByteArrayOutputStream
,使用了 ByteArrayPool
回收利用1些 byte[],避免了 byte[] 的重復內存分配和回收。
RetryPolicy:重試策略接口。具體實現可以自定義,也有默許的 DefaultRetryPolicy
。
DefaultRetryPolicy:DefaultRetryPolicy
繼承自 RetryPolicy
。注意的地方就是 -> mBackoffMultiplier
和 DEFAULT_BACKOFF_MULT
用于設置 退避乘數,跟 “指數退避” 有關。
VolleyLog:VolleyLog
是 Volley 的1個工具類。根據 Log.isLoggable(String tag,int level)
設置 Log 的開關。
level >= INFO 時 isLoggable
返回 true,反之則返回 false,所以,開關 默許 關閉。
public static final int VERBOSE = 2
public static final int DEBUG = 3
public static final int INFO = 4
public static final int WARN = 5
public static final int ERROR = 6
public static final int ASSERT = 7
MarkerLog:VolleyLog 提供的1個簡單的靜態內部 Log 類。可以通過 add(...)
添加1個 MarkerLog
的 Log 單位( Marker
),然后調用 finish(...)
打印已添加的所有 Log。
Authenticator:1個身份認證接口,用于基本認證或摘要認證。在 Volley 內,是用于和身份認證,比如 OAuth。
AndroidAuthenticator:實現了 Authenticator
接口,基于 Android 上的 AccountManager
,實現了認證交互。
VolleyError:所有 Volley 毛病的基類。繼承自 Exception
,用于描寫 Volley 中所有的毛病異常,可以設置 NetworkResponse
和 要求消耗時間。
AuthFailureError:AuthFailureError
繼承了 VolleyError
。表示:要求認證失敗毛病,如 RespondCode 的 401 和 403。
TimeoutError:TimeoutError
繼承了 VolleyError
。表示:要求超時毛病。但是甚么都沒有實現,作為1個標識存在。
ServerError:ServerError
繼承了 VolleyError
。表示:服務端毛病。
ClientError:ClientError
擴大了 ServerError
的概念。表示:客戶端毛病,即 4xx 毛病。
ParseError:ParseError
繼承了 VolleyError
。表示:內容解析毛病。
NoConnectionError:NoConnectionError
繼承了 NetworkError
。表示:網絡連接毛病。
NetworkError:NetworkError
繼承了 VolleyError
,表示:網絡毛病。
Copyright (C) 2016 CaMnter yuanyu.camnter@gmail.com
Copyright (C) 2015 Google Inc. All Rights Reserved.
Copyright (C) 2012 Square, Inc.
Copyright (C) 2011 The Android Open Source Project
Copyright (C) 2008 The Apache Software Foundation (ASF)
Copyright (C) 2007 The Guava Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE⑵.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.