This is the main class for handling the connection to the CloudPlugs server on the Java platform.
An instance of RestClient manages the HTTP requests flow by creating a thread spooler for each server to connect. Such spooler will send enqueued HTTP requests one by one following the FIFO order. An instance of this class will also emit events about the internal spooler behavior, so that any attached com.cloudplugs.util.Listener to a RestClient will be notified about what's happening in the execution flow.
The primary usage of this class is to invoke the method getManager(Opts) for obtaining an instance of RestManager able to enqueue asynchronous HTTP requests (executed in an underlying thread spooler) using the preferred options Opts.
Android developers should avoid a direct use of this class, they should use com.cloudplugs.rest.android.RestClient (unavailable on Java platform), because it supports reliable background execution of HTTP requests through a dedicated Android service and CPU wake locks. By using a direct instance of this class, an Android app could lose the ability to send HTTP requests and to receive the responses when the app is not in foreground.
More...
This is the main class for handling the connection to the CloudPlugs server on the Java platform.
An instance of RestClient manages the HTTP requests flow by creating a thread spooler for each server to connect. Such spooler will send enqueued HTTP requests one by one following the FIFO order. An instance of this class will also emit events about the internal spooler behavior, so that any attached com.cloudplugs.util.Listener to a RestClient will be notified about what's happening in the execution flow.
The primary usage of this class is to invoke the method getManager(Opts) for obtaining an instance of RestManager able to enqueue asynchronous HTTP requests (executed in an underlying thread spooler) using the preferred options Opts.
Android developers should avoid a direct use of this class, they should use com.cloudplugs.rest.android.RestClient (unavailable on Java platform), because it supports reliable background execution of HTTP requests through a dedicated Android service and CPU wake locks. By using a direct instance of this class, an Android app could lose the ability to send HTTP requests and to receive the responses when the app is not in foreground.
◆ RestClient() [1/2]
Create a new instance of this class.
◆ RestClient() [2/2]
◆ destroy()
◆ getManager()
Create a new instance of RestManager able to make HTTP requests using the specified options in opts
.
- Parameters
-
- Returns
- a new RestManager
◆ isStarted()
- Returns
- true if at least one of the underlying thread spoolers has been started
◆ onStop()
Override base class implementation. Do not call this method.
Implements Listener.
◆ pause()
Pause the execution of all threads of the underlying spoolers, if any is running. All already and future enqueued HTTP requests won't be sent over the network until this REST client will be resumed by calling resume().
- Returns
- true if at least one spooler thread was been paused, false if no spooler thread was running
◆ resume()
Resume the execution of all threads of the underlying spoolers, if any has been paused.
- Returns
- true if at least one spooler thread was been resumed, false if no spooler thread was paused
◆ stop()
Stop the execution of all threads of the underlying spoolers (if any) and clear all enqueued HTTP requests to send. This operation cannot be undone.
- Returns
- true if at least one thread spooler has been stopped, false otherwise
◆ waitForStop() [1/2]
boolean waitForStop |
( |
long |
timeout | ) |
|
Wait for the end of execution of all spoolers. The current thread will be suspended until all spoolers are stopped, but not more than timeout
milliseconds. If this client has no spoolers, this method will return immediately.
- Parameters
-
timeout | expiration timeout: maximum milliseconds to wait or 0 to have no expiration |
- Returns
- true if all spoolers have beeen stopped, false if the
timeout
is expired
◆ waitForStop() [2/2]
◆ EVT_IDLE
final String EVT_IDLE = "idle" |
|
static |
Event String emitted each time an underlying spooler become idle (the internal HTTP request queue becomes empty).
◆ EVT_PAUSE
final String EVT_PAUSE = "pause" |
|
static |
Event String emitted each time an underlying spooler is paused.
◆ EVT_RESUME
final String EVT_RESUME = "resume" |
|
static |
Event String emitted each time an underlying spooler is resumed.
◆ EVT_START
final String EVT_START = "start" |
|
static |
Event String emitted each time a new underlying spooler is started from the first time.
◆ EVT_STOP
final String EVT_STOP = "stop" |
|
static |
Event String emitted each time an underlying spooler is stopped.
◆ spoolers