Package Torello.Browser
Class Script<RESULT>
- java.lang.Object
-
- Torello.Browser.Script<RESULT>
-
- Type Parameters:
RESULT- This type indicates the type used by return-value that's ultimately received by the user. This type is the class which is actually returned when a user makes a call toPromise.await().
- All Implemented Interfaces:
java.io.Serializable
public class Script<RESULT> extends java.lang.Object implements java.io.Serializable
The class script simply sends an asynchronous request, and returns an instance ofPromisewhich may be awaited.
The three classes,Script,PromiseandSenderare designed to allow for the creation of 'Asynchronous Scripts' that may be executed and made to appear to be synchronous through thePromise.await()method.
These three classes are made use of in the Browser Remote Debugging Protocol Package. Theoretically, they could be used by any asynchronous communication system.- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/Browser/Script.java
- Open New Browser-Tab: Torello/Browser/Script.java
File Size: 5,192 Bytes Line Count: 130 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field protected static longserialVersionUIDStatic Field: Used to Handle CDP Commands which Do not Have Return-Values Modifier and Type Field static Function<JsonObject,Void>NO_RETURN_VALUESInstance Fields: Browser Command Information assigned to this Script Modifier and Type Field StringcommandNameDomainsdomainInstance Fields: Exact Script Request Information Modifier and Type Field StringrequestJSONStringInstance Fields: Json Response Processor / Converter, and the RESULT Type Modifier and Type Field Function<JsonObject,RESULT>receiverClass<RESULT>resultClass
-
Constructor Summary
Constructors Constructor Script(Domains domain, String commandName, String requestJSONString, Function<JsonObject,RESULT> receiver, Class<?> resultClass)
-
-
-
Field Detail
-
serialVersionUID
protected static final long serialVersionUID
This fulfils the SerialVersion UID requirement for all classes that implement Java'sinterface java.io.Serializable. Using theSerializableImplementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
protected static final long serialVersionUID = 1;
-
domain
-
commandName
public final java.lang.String commandName
The Name of the Web-Browser Command that is being executed by thisScript.- Code:
- Exact Field Declaration Expression:
public final String commandName;
-
requestJSONString
public final java.lang.String requestJSONString
The request-Stringthat will be sent over the Web-Socket- Code:
- Exact Field Declaration Expression:
public final String requestJSONString;
-
receiver
public final java.util.function.Function<JsonObject,RESULT> receiver
This function pointer performs the Json-Binding needed to convert a browser-generatedJsonObjectinto a Java POJO (ultimately having type'RESULT').- Code:
- Exact Field Declaration Expression:
public final Function<JsonObject, RESULT> receiver;
-
resultClass
public final java.lang.Class<RESULT> resultClass
The Java-Class/ Type of the post-processed object which is ultimately returned by this browser command. Thispublic, finalfield is nothing more than a "reified" Java Generic Type-Parameter for this class'<RESULT>generic type.- Code:
- Exact Field Declaration Expression:
public final Class<RESULT> resultClass;
-
NO_RETURN_VALUES
public static final java.util.function.Function<JsonObject,java.lang.Void> NO_RETURN_VALUES
This is a pre-defined, and repeatedly used, CDP browser response translator function. This is defined solely for use with the static builder method namedNO_RET(Torello.Browser.Domains, java.lang.String, java.lang.String).- See Also:
NO_RET(Domains, String, String)- Code:
- Exact Field Declaration Expression:
public static final Function<JsonObject, Void> NO_RETURN_VALUES = (JsonObject jo) -> null;
-
-
Constructor Detail
-
Script
public Script(Domains domain, java.lang.String commandName, java.lang.String requestJSONString, java.util.function.Function<JsonObject,RESULT> receiver, java.lang.Class<?> resultClass)
- Parameters:
domain- The domain in which this command is definedcommandName- The name of the command, as per the Google CDP APIrequestJSONString- The command, formulated a a JSON requestreceiver- This is a function pointer which "translates" the browser's JSON response into a JavaRetNPOJO.resultClass- This is used solely to facilatejavac'stype parameter "capture" logic.
-
-
Method Detail
-
NO_RET
public static Script<java.lang.Void> NO_RET (Domains domain, java.lang.String commandName, java.lang.String requestJSONString)
This is used as an alternative to a constructor, since the type parameterRESULTis restricted to the classRet0.- Parameters:
domain- The domain in which this command is definedcommandName- The name of the command, as per the Google CDP APIrequestJSONString- The command, formulated a a JSON request- See Also:
NO_RETURN_VALUES- Code:
- Exact Method Body:
return new Script<>(domain, commandName, requestJSONString, NO_RETURN_VALUES, Void.class);
-
exec
public Promise<RESULT> exec(WebSocketSender wss)
If there are reasons to use a different sender - because certain configurations need to change - then using thisexecmethod allows a user to change senders.- Parameters:
wss- TheWebSocketSenderInstance to use when executing thisScriptobject-instance.
In the Browser Remote Debug Package (Headless Chrome), the'Script'instances which are generated expect the user to provide their own constructedWebSocketSenderinstances to facilitate:- Pre-Compiling Scripts ahead of time for future use, using future Browser-Connections
- Utilizing alternate & various Page-Connections, for different Open-Pages
- Re-using Pre-Compiled Script Components
- Returns:
- An instance of
Promise. Calling that returnedPromise' methodPromise.await()is how to actually retrieve the'RESULT'that was transmitted by the channel.Note: It isn't mandatory to callPromise.await(). The result can simply be obtained by waiting a long enough time for the'RESULT'of this call to have been both transmited, and processed. - Code:
- Exact Method Body:
final Promise<RESULT> promise = new Promise<>(this); wss.send(this, promise); return promise;
-
-