Class HttpClientHelper
- java.lang.Object
-
- ptolemy.actor.lib.jjs.HelperBase
-
- ptolemy.actor.lib.jjs.VertxHelperBase
-
- ptolemy.actor.lib.jjs.modules.httpClient.HttpClientHelper
-
public class HttpClientHelper extends VertxHelperBase
A helper class for the HttpClient module in JavaScript. You should usegetOrCreateHelper(Object, ScriptObjectMirror)
to create exactly one instance of this helper per actor. This class will then ensure that response and error callbacks will occur in the same order as the queries that trigger them. To initiate a query, create an instance of the JavaScript ClientRequest object and callrequest(ScriptObjectMirror, Map)
, passing it the ClientRequest object and a Map of options (see the associated httpRequest.js JavaScript module, which defines this class and utility functions for creating it).- Since:
- Ptolemy II 11.0
- Version:
- $Id$
- Author:
- Marten Lohstroh, Edward A. Lee, contributors: Ravi Akella, Christopher Brooks, Matt Weber.
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Yellow (eal)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.actor.lib.jjs.VertxHelperBase
VertxHelperBase.AccessorVerticle
-
Nested classes/interfaces inherited from class ptolemy.actor.lib.jjs.HelperBase
HelperBase.DATA_TYPE
-
-
Field Summary
Fields Modifier and Type Field Description static int
PENDING_REQUESTS_DELAY_FACTOR
The scale factor (in milliseconds) by which requests are delayed when PENDING_REQUESTS_THRESHOLD is exceeded.static int
PENDING_REQUESTS_THRESHOLD
The threshold of number of pending requests before further requests introduce a delay.-
Fields inherited from class ptolemy.actor.lib.jjs.VertxHelperBase
_verticle, _vertx
-
Fields inherited from class ptolemy.actor.lib.jjs.HelperBase
_actor, _currentObj
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
HttpClientHelper(java.lang.Object actor, jdk.nashorn.api.scripting.ScriptObjectMirror helping)
Construct a helper for the specified actor.protected
HttpClientHelper(java.lang.Object actor, jdk.nashorn.api.scripting.ScriptObjectMirror helping, VertxHelperBase base)
Construct a helper for the specified actor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HttpClientHelper
getOrCreateHelper(java.lang.Object actor, jdk.nashorn.api.scripting.ScriptObjectMirror helping)
Get or create a helper for the specified actor.void
request(jdk.nashorn.api.scripting.ScriptObjectMirror currentObj, java.util.Map<java.lang.String,java.lang.Object> options)
Make an HTTP request on behalf of the specified JavaScript object (an instance of ClientRequest) with the specified options.void
reset()
Reset this handler.static void
reset(java.lang.Object actor)
Reset the helper associated with the specified actor.void
stop()
Stop a request.-
Methods inherited from class ptolemy.actor.lib.jjs.VertxHelperBase
_issueOrDeferResponse, _processPendingJob, _setBusy, closeVertx, getHelper, getImageTypes, submit, supportedReceiveTypes, supportedSendTypes, undeploy
-
Methods inherited from class ptolemy.actor.lib.jjs.HelperBase
_appendNumericToBuffer, _appendToBuffer, _error, _error, _error, _error, _extractFromBuffer, _issueResponse, _removeDuplicates, _sizeOfType, _toJavaBytes, _toJSArray, getHelping
-
-
-
-
Field Detail
-
PENDING_REQUESTS_THRESHOLD
public static int PENDING_REQUESTS_THRESHOLD
The threshold of number of pending requests before further requests introduce a delay.
-
PENDING_REQUESTS_DELAY_FACTOR
public static int PENDING_REQUESTS_DELAY_FACTOR
The scale factor (in milliseconds) by which requests are delayed when PENDING_REQUESTS_THRESHOLD is exceeded.
-
-
Constructor Detail
-
HttpClientHelper
protected HttpClientHelper(java.lang.Object actor, jdk.nashorn.api.scripting.ScriptObjectMirror helping)
Construct a helper for the specified actor.- Parameters:
actor
- The JavaScript actor that this helps.helping
- A JavaScript object that this helps.
-
HttpClientHelper
protected HttpClientHelper(java.lang.Object actor, jdk.nashorn.api.scripting.ScriptObjectMirror helping, VertxHelperBase base)
Construct a helper for the specified actor.- Parameters:
actor
- The JavaScript actor that this helps.helping
- A JavaScript object that this helps.base
- The helper base to share a verticle with.
-
-
Method Detail
-
request
public void request(jdk.nashorn.api.scripting.ScriptObjectMirror currentObj, java.util.Map<java.lang.String,java.lang.Object> options)
Make an HTTP request on behalf of the specified JavaScript object (an instance of ClientRequest) with the specified options. The options argument can be a string URL or a map with the following fields (this helper class assumes all fields are present, so please be sure they are):- body: The request body, if any. This supports at least strings and image data.
- headers: An object containing request headers. By default this is an empty object. Items may have a value that is an array of values, for headers with more than one value.
- keepAlive: A boolean that specified whether to keep sockets around in a pool to be used by other requests in the future. This defaults to false.
- method: A string specifying the HTTP request method. This defaults to 'GET', but can also be 'PUT', 'POST', 'DELETE', etc.
- outputCompleteResponseOnly: If false, then the multiple invocations of the callback may be invoked for each request. This defaults to true, in which case there will be only one invocation of the callback.
- proxyHost: The name of the http proxy host, if any.
- proxyPort: The port number of the proxy host, if any. A proxy host will be used only if proxyHost and proxyPort are not empty.
- timeout: The amount of time (in milliseconds) to wait for a response before triggering a null response and an error. This defaults to 5000.
- url: A string that can be parsed as a URL, or an object containing
the following fields:
- host: A string giving the domain name or IP address of the server to issue the request to. This defaults to 'localhost'.
- path: Request path as a string. This defaults to '/'. This can include a query string, e.g. '/index.html?page=12', or the query string can be specified as a separate field (see below). An exception is thrown if the request path contains illegal characters.
- protocol: The protocol. This is a string that defaults to 'http'.
- port: Port of remote server. This defaults to 80.
- query: A query string to be appended to the path, such as '?page=12'.
- Parameters:
currentObj
- The JavaScript instance using this helper (a ClientRequest).options
- The options.
-
getOrCreateHelper
public static HttpClientHelper getOrCreateHelper(java.lang.Object actor, jdk.nashorn.api.scripting.ScriptObjectMirror helping)
Get or create a helper for the specified actor. If one has been created before and has not been garbage collected, return that one. Otherwise, create a new one.- Parameters:
actor
- Either a JavaScript actor or a RestrictedJavaScriptInterface.helping
- JavaScript object this is helping.- Returns:
- A new HttpClientHelper instance.
-
reset
public void reset()
Reset this handler. This method discards any pending submitted jobs, marks the handler not busy, and resets the sequence number to zero.- Overrides:
reset
in classVertxHelperBase
-
reset
public static void reset(java.lang.Object actor)
Reset the helper associated with the specified actor. This method discards any pending submitted jobs, marks the helper not busy, and resets the sequence number to zero. If there is no HttpClientHelper associated with this actor, then do nothing.- Parameters:
actor
- the actor with the associated helper to be reset.
-
stop
public void stop()
Stop a request. This ensures that future callbacks are discarded.
-
-