CloudPlugs REST Library  1.0.0
for Java
RestBaseManager Class Referenceabstract

Base class for handling HTTP requests. This class is not intended for direct usage, the developer should use a subclass of this one.

An instance of this class will also emit events about the internal spooler behavoir, so that any attached com.cloudplugs.util.Listener to a RestBaseManager will be notified about what's happening in the execution flow.

See also RestManager. More...

Inheritance diagram for RestBaseManager:

Public Member Functions

Opts getOpts ()
 
String getAuthId ()
 
boolean isEmpty ()
 
RestJob getJobOf (int id)
 
Response sync (int id, long timeout)
 
Response sync (int id)
 
boolean cancel (int id)
 
boolean cancel (Request request)
 
boolean waitFor (int id, long timeout)
 
boolean waitFor (int id)
 
boolean waitForIdle (long timeout)
 
boolean waitForIdle ()
 
boolean waitForStop (long timeout)
 
boolean waitForStop ()
 
- 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 int ID_NULL = RestSpooler.ID_NULL
 

Protected Member Functions

 RestBaseManager (RestSpooler spooler, Opts opts)
 
RestSpooler getSpooler ()
 
int execRequest (Request request, RestCallback cb)
 
int execGet (String action, String path, RestCallback cb)
 
int execPut (String action, String path, String body, RestCallback cb)
 
int execPost (String action, String path, String body, RestCallback cb)
 
int execPatch (String action, String path, String body, RestCallback cb)
 
int execDelete (String action, String path, String body, RestCallback cb)
 
int execRequest (String method, String action, String path, String body, RestCallback cb)
 
int execRequest (String method, String action, String path, RestCallback cb, Object... body)
 
void finalize () throws Throwable
 
void wantAuth ()
 
void wantBasicAuth ()
 
void wantEmailAuth ()
 
void wantMasterAuth ()
 
void wantDeviceAuth ()
 
void wantNoEmailAuth ()
 
void wantNoAuth ()
 
void wantNoDeviceAuth ()
 

Static Protected Member Functions

static String bodyGen (Object... args)
 
static String queryGen (Object... args)
 
static String pathQuery (String path, String query)
 
static String esc (Object s) throws UnsupportedEncodingException
 
static Object queryCast (Object o) throws UnsupportedEncodingException
 
static Object ts (Object val, String err)
 
static Object tso (Object val, String err)
 
static Object tsp (Object val, String err)
 
static void runOnCb (RestCallback cb, Runnable runnable)
 

Protected Attributes

final Opts opts
 
final RestSpooler spooler
 
- Protected Attributes inherited from MetaListener
Listener listener
 

Detailed Description

Base class for handling HTTP requests. This class is not intended for direct usage, the developer should use a subclass of this one.

An instance of this class will also emit events about the internal spooler behavoir, so that any attached com.cloudplugs.util.Listener to a RestBaseManager will be notified about what's happening in the execution flow.

See also RestManager.

Constructor & Destructor Documentation

◆ RestBaseManager()

RestBaseManager ( RestSpooler  spooler,
Opts  opts 
)
protected

Member Function Documentation

◆ bodyGen()

static String bodyGen ( Object...  args)
staticprotected

◆ cancel() [1/2]

boolean cancel ( int  id)

Cancel the execution of a previously enqueued request. If successfull, all information about the enqueued request will be lost.

Parameters
idthe identifier asynchronous request to cancel
Returns
true if the specified request has been canceled, false if that request is unknown or already executed

◆ cancel() [2/2]

boolean cancel ( Request  request)

Cancel the execution of a previously enqueued request. If successful, all information about the enqueued request will be lost.

Parameters
requestthe request to cancel
Returns
true if the specified request has been canceled, false if that request is unknown or already executed

◆ esc()

static String esc ( Object  s) throws UnsupportedEncodingException
staticprotected

◆ execDelete()

int execDelete ( String  action,
String  path,
String  body,
RestCallback  cb 
)
protected

◆ execGet()

int execGet ( String  action,
String  path,
RestCallback  cb 
)
protected

◆ execPatch()

int execPatch ( String  action,
String  path,
String  body,
RestCallback  cb 
)
protected

◆ execPost()

int execPost ( String  action,
String  path,
String  body,
RestCallback  cb 
)
protected

◆ execPut()

int execPut ( String  action,
String  path,
String  body,
RestCallback  cb 
)
protected

◆ execRequest() [1/3]

int execRequest ( Request  request,
RestCallback  cb 
)
protected

◆ execRequest() [2/3]

int execRequest ( String  method,
String  action,
String  path,
String  body,
RestCallback  cb 
)
protected

◆ execRequest() [3/3]

int execRequest ( String  method,
String  action,
String  path,
RestCallback  cb,
Object...  body 
)
protected

◆ finalize()

void finalize ( ) throws Throwable
protected

◆ getAuthId()

String getAuthId ( )

Shortcut for getting the authentication identifier (PlugID or email) associated in the Opts of this manager. It's just like calling this.getOpts().getAuthId().

Returns
authentication identifier or null if there is no authentication associated to this manager

◆ getJobOf()

RestJob getJobOf ( int  id)

Retrieve an enqueued and pending asynchronous request as an instance of RestJob.

Parameters
idthe identifier of the asynchronous execution to obtain
Returns
the pending exection or null if not found (for unknown id or already executed requests)

◆ getOpts()

Opts getOpts ( )
Returns
options associated to this manager

◆ getSpooler()

RestSpooler getSpooler ( )
protected

◆ isEmpty()

boolean isEmpty ( )
Returns
false if there is at least one pending request to execute, otherwise true

◆ pathQuery()

static String pathQuery ( String  path,
String  query 
)
staticprotected

◆ queryCast()

static Object queryCast ( Object  o) throws UnsupportedEncodingException
staticprotected

◆ queryGen()

static String queryGen ( Object...  args)
staticprotected

◆ runOnCb()

static void runOnCb ( RestCallback  cb,
Runnable  runnable 
)
staticprotected

◆ sync() [1/2]

Response sync ( int  id,
long  timeout 
)

Wait for the end of execution of the specified asynchronous pending request and return its Response. The current thread will be suspended until the request is completed or canceled, but not more than timeout milliseconds. If the specified pending request identifier is not valid, this method will return immediately. This method is like waitFor(int, long) but it returns the obtained response.

Parameters
idthe identifier asynchronous request to synchronize
timeoutexpiration timeout: maximum milliseconds to wait or 0 to have no expiration
Returns
the obtained response or null if the asyncronous execution id is unknown or if timeout is expired

◆ sync() [2/2]

Response sync ( int  id)

Like sync(int, long), but without any timeout expiration.

Parameters
idthe identifier asynchronous request to synchronize
Returns
the obtained response or null if the asyncronous execution id is unknown

◆ ts()

static Object ts ( Object  val,
String  err 
)
staticprotected

◆ tso()

static Object tso ( Object  val,
String  err 
)
staticprotected

◆ tsp()

static Object tsp ( Object  val,
String  err 
)
staticprotected

◆ waitFor() [1/2]

boolean waitFor ( int  id,
long  timeout 
)

Wait for the end of execution of the specified asynchronous pending request. The current thread will be suspended until the request is completed or canceled, but not more than timeout milliseconds. If the specified pending request identifier is not valid, this method will return immediately.

Parameters
idthe identifier asynchronous request to synchronize
timeoutexpiration timeout: maximum milliseconds to wait or 0 to have no expiration
Returns
true if the asynchronous request has been completed or canceled, false if unknown

◆ waitFor() [2/2]

boolean waitFor ( int  id)

Like waitFor(int, long), but without any timeout expiration.

Parameters
idthe identifier asynchronous request to synchronize
Returns
true if the asynchronous request has been completed or canceled, false if unknown

◆ waitForIdle() [1/2]

boolean waitForIdle ( long  timeout)

Wait for the end of execution of all asynchronous enqueued pending requests. The current thread will be suspended until all requests are completed, but not more than timeout milliseconds.

Parameters
timeoutexpiration timeout: maximum milliseconds to wait or 0 to have no expiration
Returns
true if all asynchronous requests have been completed or canceled, false if the spooler thread is not running (for example for empty queue) or if the timeout is expired

◆ waitForIdle() [2/2]

boolean waitForIdle ( )

Like waitForIdle(long) but without expiration.

Returns
true if all asynchronous requests have been completed or canceled, false if the spooler thread is not running (for example for empty queue)

◆ waitForStop() [1/2]

boolean waitForStop ( long  timeout)

Wait for the end of execution of the underlying spooler thread of asynchronous requests. The current thread will be suspended until the underlying spooler will be stopped, but not more than timeout milliseconds.

Parameters
timeoutexpiration timeout: maximum milliseconds to wait or 0 to have no expiration
Returns
false if the underlying spooler was already stopped

◆ waitForStop() [2/2]

boolean waitForStop ( )

Like waitForStop(long) but without expiration.

Returns
false if the underlying spooler was already stopped

◆ wantAuth()

void wantAuth ( )
protected

◆ wantBasicAuth()

void wantBasicAuth ( )
protected

◆ wantDeviceAuth()

void wantDeviceAuth ( )
protected

◆ wantEmailAuth()

void wantEmailAuth ( )
protected

◆ wantMasterAuth()

void wantMasterAuth ( )
protected

◆ wantNoAuth()

void wantNoAuth ( )
protected

◆ wantNoDeviceAuth()

void wantNoDeviceAuth ( )
protected

◆ wantNoEmailAuth()

void wantNoEmailAuth ( )
protected

Member Data Documentation

◆ ID_NULL

final int ID_NULL = RestSpooler.ID_NULL
static

Constant to indicate an invalid asynchronous execution identifier.

◆ opts

final Opts opts
protected

◆ spooler

final RestSpooler spooler
protected