public class DefaultHttpKit extends Object implements HttpKit
HttpKit implementation.
Restrictions:
DefaultHttpKit uses the same ParserWriters to parse
data as the cache. Therefore DefaultHttpKit has not a own mime type -
parser map, but uses Cache.getParserWriterPool() DefaultHttpKit expects that every http response contains a
correct mime type as content type. This mime type is used to find the correct
parser for thisHybridCache does) you need also WRITE_EXTERNAL_STORAGE| Modifier and Type | Class and Description |
|---|---|
class |
DefaultHttpKit.DefaultCacheRetriever<T>
This
Runnable is responsible to load data from cache. |
| Modifier and Type | Field and Description |
|---|---|
protected Cache<String,Object> |
cache
The cache
|
protected CacheRetrieverExecutor |
cacheExecutor
The cache executor, that retrieve data from the cache asynchronously
|
protected android.net.ConnectivityManager |
connectivityManager |
protected android.content.Context |
context |
protected org.apache.http.impl.client.AbstractHttpClient |
httpClient
Apaches
HttpClient |
protected HttpExecutor |
httpExecutor
The http Executor, that will execute the
HttpRequests
asynchronously |
protected android.os.Handler |
uiThreadHandler
The handler to send the result back to the ui thread
|
| Constructor and Description |
|---|
DefaultHttpKit(android.content.Context context) |
DefaultHttpKit(android.content.Context context,
String userAgent) |
| Modifier and Type | Method and Description |
|---|---|
void |
addParserWriter(String mimeType,
ParserWriter<?> parser)
Adds a parser for the given mime type
|
void |
cancelAllOfOwner(Object owner)
Cancels all pending
HttpRequest that were tagged |
<T> void |
execute(HttpRequest request,
HttpResponseReceiver<T> receiver)
Executes a
HttpRequest with parsing the result according the
returned mime type. |
android.content.Context |
getApplicationContext() |
Cache<String,Object> |
getCache()
Get the cache that is uses
|
org.apache.http.client.HttpClient |
getHttpClient() |
boolean |
isNetworkAvailable() |
void |
removeParserWriter(String mimeType)
Removes the parser for the given mime type
|
protected <T> void |
scheduleHttpRequest(HttpRequest request,
HttpResponseReceiver<T> receiver)
Schedules a HttpRequest to be executed to check the cache
|
void |
setCache(Cache<String,Object> cache)
Sets the internal cache
|
void |
setHttpExecutor(HttpExecutor executor)
Set the
HttpExecutor for async http data transfer |
protected <T> void |
startHttpRequestAsync(HttpRequest request,
HttpResponseReceiver<T> receiver)
Starts the http request asynchronously in a new thread.
|
protected final android.content.Context context
protected final org.apache.http.impl.client.AbstractHttpClient httpClient
HttpClientprotected final android.os.Handler uiThreadHandler
protected HttpExecutor httpExecutor
HttpRequests
asynchronouslyprotected final CacheRetrieverExecutor cacheExecutor
protected final android.net.ConnectivityManager connectivityManager
public DefaultHttpKit(android.content.Context context)
public DefaultHttpKit(android.content.Context context,
String userAgent)
public void setCache(Cache<String,Object> cache)
HttpKitpublic Cache<String,Object> getCache()
HttpKitpublic org.apache.http.client.HttpClient getHttpClient()
protected <T> void scheduleHttpRequest(HttpRequest request, HttpResponseReceiver<T> receiver)
public void addParserWriter(String mimeType, ParserWriter<?> parser)
HttpKitaddParserWriter in interface HttpKitmimeType - The mimetype. The passed parser will be used for this mime
typeparser - The parserpublic void removeParserWriter(String mimeType)
HttpKitremoveParserWriter in interface HttpKitpublic <T> void execute(HttpRequest request, HttpResponseReceiver<T> receiver)
HttpKitHttpRequest with parsing the result according the
returned mime type. To make this work it's necessary, that the server
returns a correct mime type or was setted in the HttpRequest and
that a parser has been added to this HttpKit for the returned
mime typeexecute in interface HttpKitHttpKit.addParserWriter(String, ParserWriter)public boolean isNetworkAvailable()
public void setHttpExecutor(HttpExecutor executor)
HttpKitHttpExecutor for async http data transfersetHttpExecutor in interface HttpKitprotected <T> void startHttpRequestAsync(HttpRequest request, HttpResponseReceiver<T> receiver)
HttpExecutorpublic void cancelAllOfOwner(Object owner)
HttpKitHttpRequest that were taggedcancelAllOfOwner in interface HttpKitpublic android.content.Context getApplicationContext()
Copyright © 2015 Hannes Dorfmann. All rights reserved.