Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wd1105040417
retrofit
提交
80654d75
R
retrofit
项目概览
wd1105040417
/
retrofit
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
retrofit
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
80654d75
编写于
10月 10, 2014
作者:
J
Jesse Wilson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #633 from square/jw/client-provider-death
Remove Client provider indirection.
上级
6a65f89a
47316ec1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
24 addition
and
73 deletion
+24
-73
retrofit/src/main/java/retrofit/Platform.java
retrofit/src/main/java/retrofit/Platform.java
+12
-30
retrofit/src/main/java/retrofit/RestAdapter.java
retrofit/src/main/java/retrofit/RestAdapter.java
+12
-34
retrofit/src/main/java/retrofit/client/Client.java
retrofit/src/main/java/retrofit/client/Client.java
+0
-9
未找到文件。
retrofit/src/main/java/retrofit/Platform.java
浏览文件 @
80654d75
...
...
@@ -60,7 +60,7 @@ abstract class Platform {
}
abstract
Converter
defaultConverter
();
abstract
Client
.
Provider
defaultClient
();
abstract
Client
defaultClient
();
abstract
Executor
defaultHttpExecutor
();
abstract
Executor
defaultCallbackExecutor
();
abstract
RestAdapter
.
Log
defaultLog
();
...
...
@@ -71,18 +71,11 @@ abstract class Platform {
return
new
GsonConverter
(
new
Gson
());
}
@Override
Client
.
Provider
defaultClient
()
{
final
Client
client
;
@Override
Client
defaultClient
()
{
if
(
hasOkHttpOnClasspath
())
{
client
=
OkClientInstantiator
.
instantiate
();
}
else
{
client
=
new
UrlConnectionClient
();
return
OkClientInstantiator
.
instantiate
();
}
return
new
Client
.
Provider
()
{
@Override
public
Client
get
()
{
return
client
;
}
};
return
new
UrlConnectionClient
();
}
@Override
Executor
defaultHttpExecutor
()
{
...
...
@@ -117,20 +110,14 @@ abstract class Platform {
return
new
GsonConverter
(
new
Gson
());
}
@Override
Client
.
Provider
defaultClient
()
{
final
Client
client
;
@Override
Client
defaultClient
()
{
if
(
hasOkHttpOnClasspath
())
{
client
=
OkClientInstantiator
.
instantiate
();
}
else
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
GINGERBREAD
)
{
client
=
new
AndroidApacheClient
();
}
else
{
client
=
new
UrlConnectionClient
();
return
OkClientInstantiator
.
instantiate
();
}
return
new
Client
.
Provider
()
{
@Override
public
Client
get
()
{
return
client
;
}
};
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
GINGERBREAD
)
{
return
new
AndroidApacheClient
();
}
return
new
UrlConnectionClient
();
}
@Override
Executor
defaultHttpExecutor
()
{
...
...
@@ -156,13 +143,8 @@ abstract class Platform {
}
private
static
class
AppEngine
extends
Base
{
@Override
Client
.
Provider
defaultClient
()
{
final
UrlFetchClient
client
=
new
UrlFetchClient
();
return
new
Client
.
Provider
()
{
@Override
public
Client
get
()
{
return
client
;
}
};
@Override
Client
defaultClient
()
{
return
new
UrlFetchClient
();
}
}
...
...
retrofit/src/main/java/retrofit/RestAdapter.java
浏览文件 @
80654d75
...
...
@@ -153,17 +153,17 @@ public class RestAdapter {
final
Log
log
;
final
ErrorHandler
errorHandler
;
private
final
Client
.
Provider
clientProvider
;
private
final
Client
client
;
private
final
Profiler
profiler
;
private
RxSupport
rxSupport
;
volatile
LogLevel
logLevel
;
private
RestAdapter
(
Endpoint
server
,
Client
.
Provider
clientProvider
,
Executor
httpExecutor
,
private
RestAdapter
(
Endpoint
server
,
Client
client
,
Executor
httpExecutor
,
Executor
callbackExecutor
,
RequestInterceptor
requestInterceptor
,
Converter
converter
,
Profiler
profiler
,
ErrorHandler
errorHandler
,
Log
log
,
LogLevel
logLevel
)
{
this
.
server
=
server
;
this
.
client
Provider
=
clientProvider
;
this
.
client
=
client
;
this
.
httpExecutor
=
httpExecutor
;
this
.
callbackExecutor
=
callbackExecutor
;
this
.
requestInterceptor
=
requestInterceptor
;
...
...
@@ -318,7 +318,7 @@ public class RestAdapter {
}
long
start
=
System
.
nanoTime
();
Response
response
=
client
Provider
.
get
()
.
execute
(
request
);
Response
response
=
client
.
execute
(
request
);
long
elapsedTime
=
TimeUnit
.
NANOSECONDS
.
toMillis
(
System
.
nanoTime
()
-
start
);
int
statusCode
=
response
.
getStatus
();
...
...
@@ -527,22 +527,12 @@ public class RestAdapter {
/**
* Build a new {@link RestAdapter}.
* <p>
* Calling the following methods is required before calling {@link #build()}:
* <ul>
* <li>{@link #setEndpoint(Endpoint)}</li>
* <li>{@link #setClient(Client.Provider)}</li>
* <li>{@link #setConverter(Converter)}</li>
* </ul>
* <p>
* If you are using asynchronous execution (i.e., with {@link Callback Callbacks}) the following
* is also required:
* <ul>
* <li>{@link #setExecutors(java.util.concurrent.Executor, java.util.concurrent.Executor)}</li>
* </ul>
* Calling {@link #setEndpoint} is required before calling {@link #build()}. All other methods
* are optional.
*/
public
static
class
Builder
{
private
Endpoint
endpoint
;
private
Client
.
Provider
clientProvider
;
private
Client
client
;
private
Executor
httpExecutor
;
private
Executor
callbackExecutor
;
private
RequestInterceptor
requestInterceptor
;
...
...
@@ -571,23 +561,11 @@ public class RestAdapter {
}
/** The HTTP client used for requests. */
public
Builder
setClient
(
final
Client
client
)
{
public
Builder
setClient
(
Client
client
)
{
if
(
client
==
null
)
{
throw
new
NullPointerException
(
"Client may not be null."
);
}
return
setClient
(
new
Client
.
Provider
()
{
@Override
public
Client
get
()
{
return
client
;
}
});
}
/** The HTTP client used for requests. */
public
Builder
setClient
(
Client
.
Provider
clientProvider
)
{
if
(
clientProvider
==
null
)
{
throw
new
NullPointerException
(
"Client provider may not be null."
);
}
this
.
clientProvider
=
clientProvider
;
this
.
client
=
client
;
return
this
;
}
...
...
@@ -674,7 +652,7 @@ public class RestAdapter {
throw
new
IllegalArgumentException
(
"Endpoint may not be null."
);
}
ensureSaneDefaults
();
return
new
RestAdapter
(
endpoint
,
client
Provider
,
httpExecutor
,
callbackExecutor
,
return
new
RestAdapter
(
endpoint
,
client
,
httpExecutor
,
callbackExecutor
,
requestInterceptor
,
converter
,
profiler
,
errorHandler
,
log
,
logLevel
);
}
...
...
@@ -682,8 +660,8 @@ public class RestAdapter {
if
(
converter
==
null
)
{
converter
=
Platform
.
get
().
defaultConverter
();
}
if
(
client
Provider
==
null
)
{
client
Provider
=
Platform
.
get
().
defaultClient
();
if
(
client
==
null
)
{
client
=
Platform
.
get
().
defaultClient
();
}
if
(
httpExecutor
==
null
)
{
httpExecutor
=
Platform
.
get
().
defaultHttpExecutor
();
...
...
retrofit/src/main/java/retrofit/client/Client.java
浏览文件 @
80654d75
...
...
@@ -31,13 +31,4 @@ public interface Client {
* these values as they might have been set as a result of an application-level configuration.
*/
Response
execute
(
Request
request
)
throws
IOException
;
/**
* Deferred means of obtaining a {@link Client}. For asynchronous requests this will always be
* called on a background thread.
*/
interface
Provider
{
/** Obtain an HTTP client. Called once for each request. */
Client
get
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录