CloudPlugs REST Library  1.0.0
for Java
RestClient Class Reference

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...

Inheritance diagram for RestClient:

Public Member Functions

 RestClient ()
 
RestManager getManager (Opts opts)
 
boolean isStarted ()
 
boolean pause ()
 
boolean resume ()
 
boolean stop ()
 
void destroy ()
 
boolean waitForStop (long timeout)
 
void waitForStop ()
 
void onStop ()
 
- Public Member Functions inherited from MultiListener
 MultiListener ()
 
boolean hasListener (Listener l)
 
Listener getListener (int location)
 
void addListener (Listener l)
 
boolean removeListener (Listener l)
 
Listener removeListener (int location)
 
void clearListeners ()
 
Listener getListener ()
 
final void setListener (Listener l)
 
void onStart ()
 
void onStop ()
 
void onPause ()
 
void onResume ()
 
void onReady ()
 
void onIdle ()
 
void onEvt (Object evt, Object value)
 
void onErr (Throwable t)
 
- Public Member Functions inherited from MetaListener
 MetaListener ()
 
 MetaListener (Listener l)
 
Listener getListener ()
 
void setListener (Listener l)
 
void onStart ()
 
void onStop ()
 
void onPause ()
 
void onResume ()
 
void onReady ()
 
void onIdle ()
 
void onEvt (Object evt, Object value)
 
void onErr (Throwable t)
 

Static Public Attributes

static final String EVT_START = "start"
 
static final String EVT_STOP = "stop"
 
static final String EVT_PAUSE = "pause"
 
static final String EVT_RESUME = "resume"
 
static final String EVT_IDLE = "idle"
 

Protected Member Functions

 RestClient (Class<? extends RestSpooler > cls)
 

Protected Attributes

final Map< String, RestSpoolerspoolers = new HashMap<String,RestSpooler>()
 
- Protected Attributes inherited from MetaListener
Listener listener
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ RestClient() [1/2]

Create a new instance of this class.

◆ RestClient() [2/2]

RestClient ( Class<? extends RestSpooler cls)
protected

Member Function Documentation

◆ destroy()

void destroy ( )

Stop this client (see stop() for more details) and remove all com.cloudplugs.util.Listeners attached to this instance, if any.

◆ getManager()

RestManager getManager ( Opts  opts)

Create a new instance of RestManager able to make HTTP requests using the specified options in opts.

Parameters
optsthe options used by the new RestManager
Returns
a new RestManager

◆ isStarted()

boolean isStarted ( )
Returns
true if at least one of the underlying thread spoolers has been started

◆ onStop()

void onStop ( )

Override base class implementation. Do not call this method.

Implements Listener.

◆ pause()

boolean 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()

boolean 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()

boolean 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
timeoutexpiration 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]

void waitForStop ( )

Like waitForStop(long), but without any timeout expiration.

Member Data Documentation

◆ 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

final Map<String,RestSpooler> spoolers = new HashMap<String,RestSpooler>()
protected