public class NetworkManager extends Object
Modifier and Type | Field and Description |
---|---|
static int |
ACCESS_POINT_TYPE_CABLE
Indicates an access point based on a cable
|
static int |
ACCESS_POINT_TYPE_CORPORATE
Indicates a corporate routing server access point type (e.g.
|
static int |
ACCESS_POINT_TYPE_NETWORK2G
Indicates a 2g network access point type
|
static int |
ACCESS_POINT_TYPE_NETWORK3G
Indicates a 3g network access point type
|
static int |
ACCESS_POINT_TYPE_UNKNOWN
Indicates an unknown access point type
|
static int |
ACCESS_POINT_TYPE_WLAN
Indicates a wlan (802.11b/c/g/n) access point type
|
Modifier and Type | Method and Description |
---|---|
void |
addDefaultHeader(String key,
String value)
Adds a header to the global default headers, this header will be implicitly added
to all requests going out from this point onwards.
|
void |
addErrorListener(ActionListener e)
Adds a generic listener to a network error that is invoked before the exception is propogated.
|
void |
addProgressListener(ActionListener al)
Adds a listener to be notified when progress updates
|
void |
addToQueue(ConnectionRequest request)
Adds the given network connection to the queue of execution
|
void |
addToQueueAndWait(ConnectionRequest request)
Identical to add to queue but waits until the request is processed in the queue,
this is useful for completely synchronous operations.
|
void |
assignToThread(Class requestType,
int offset)
Makes sure the given class (subclass of ConnectionRequest) is always assigned
to the given thread number.
|
Enumeration |
enumurateQueue()
This method returns all pending ConnectioRequest connections.
|
String[] |
getAPIds()
Returns the ids of the access points available if supported
|
String |
getAPName(String id)
Returns the user displayable name for the given access point
|
int |
getAPType(String id)
Returns the type of the access point
|
static String |
getAutoDetectURL()
This URL is used to check whether an Internet connection is available
|
String |
getCurrentAccessPoint()
Returns the id of the current access point
|
static NetworkManager |
getInstance()
Returns the singleton instance of this class
|
int |
getThreadCount()
The number of threads
|
int |
getTimeout()
Returns the timeout duration
|
boolean |
isAPSupported()
Indicates whether looking up an access point is supported by this device
|
boolean |
isQueueIdle()
Indicates that the network queue is idle
|
void |
killAndWait(ConnectionRequest request)
Kills the given request and waits until the request is killed if it is
being processed by one of the threads.
|
void |
removeErrorListener(ActionListener e)
Removes the given error listener
|
void |
removeProgressListener(ActionListener al)
Adds a listener to be notified when progress updates
|
static void |
setAutoDetectURL(String aAutoDetectURL)
This URL is used to check whether an Internet connection is available
|
void |
setCurrentAccessPoint(String id)
Returns the id of the current access point
|
void |
setThreadCount(int threadCount)
Thread count should never be changed when the network is running since it will have no effect.
|
void |
setTimeout(int t)
Sets the timeout in milliseconds for network connections, a timeout may be "faked"
for platforms that don't support the notion of a timeout such as MIDP
|
void |
shutdown()
Shuts down the network thread
|
void |
shutdownSync()
Shuts down the network thread and waits for shutdown to complete
|
void |
start()
There is no need to invoke this method since the network manager is started
implicitly.
|
public static final int ACCESS_POINT_TYPE_UNKNOWN
public static final int ACCESS_POINT_TYPE_WLAN
public static final int ACCESS_POINT_TYPE_CABLE
public static final int ACCESS_POINT_TYPE_NETWORK3G
public static final int ACCESS_POINT_TYPE_NETWORK2G
public static final int ACCESS_POINT_TYPE_CORPORATE
public static String getAutoDetectURL()
public static void setAutoDetectURL(String aAutoDetectURL)
aAutoDetectURL
- the autoDetectURL to setpublic int getThreadCount()
public void setThreadCount(int threadCount)
threadCount
- the threadCount to setpublic void start()
public void shutdown()
public void shutdownSync()
public static NetworkManager getInstance()
public void addDefaultHeader(String key, String value)
key
- the key of the headervalue
- the value of the headerpublic void addToQueueAndWait(ConnectionRequest request)
request
- the request object to addpublic void addToQueue(ConnectionRequest request)
request
- network request for executionpublic void killAndWait(ConnectionRequest request)
request
- public void setTimeout(int t)
t
- the timeout durationpublic int getTimeout()
public void addErrorListener(ActionListener e)
e
- callback will be invoked with the Exception as the source objectpublic void removeErrorListener(ActionListener e)
e
- callback to removepublic void addProgressListener(ActionListener al)
al
- action listenerpublic void removeProgressListener(ActionListener al)
al
- action listenerpublic void assignToThread(Class requestType, int offset)
requestType
- the class of the specific connection requestoffset
- the offset of the thread starting from 0 and smaller than thread countpublic Enumeration enumurateQueue()
public boolean isQueueIdle()
public boolean isAPSupported()
public String[] getAPIds()
public int getAPType(String id)
id
- access point idpublic String getAPName(String id)
id
- the id of the access pointpublic String getCurrentAccessPoint()
public void setCurrentAccessPoint(String id)
id
- id of the current access point