Class 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 to Promise.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 of Promise which may be awaited.

    The three classes, Script, Promise and Sender are designed to allow for the creation of 'Asynchronous Scripts' that may be executed and made to appear to be synchronous through the Promise.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


    • Field Summary

       
      Serializable ID
      Modifier and Type Field
      protected static long serialVersionUID
       
      Static Field: Used to Handle CDP Commands which Do not Have Return-Values
      Modifier and Type Field
      static Function<JsonObject,​Void> NO_RETURN_VALUES
       
      Instance Fields: Browser Command Information assigned to this Script
      Modifier and Type Field
      String commandName
      Domains domain
       
      Instance Fields: Exact Script Request Information
      Modifier and Type Field
      String requestJSONString
       
      Instance Fields: Json Response Processor / Converter, and the RESULT Type
      Modifier and Type Field
      Function<JsonObject,​RESULT> receiver
      Class<RESULT> resultClass
    • Constructor Summary

      Constructors 
      Constructor
      Script​(Domains domain, String commandName, String requestJSONString, Function<JsonObject,​RESULT> receiver, Class<?> resultClass)
    • Method Summary

       
      Execute this Request, and make a Promise
      Modifier and Type Method
      Promise<RESULT> exec​(WebSocketSender wss)
       
      Alternate Constructor, as a Static-Builder Method
      Modifier and Type Method
      static Script<Void> NO_RET​(Domains domain, String commandName, String requestJSONString)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • serialVersionUID

        🡇     🗕  🗗  🗖
        protected static final long serialVersionUID
        This fulfils the SerialVersion UID requirement for all classes that implement Java's interface java.io.Serializable. Using the Serializable Implementation 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

        🡅  🡇     🗕  🗗  🗖
        public final Domains domain
        The Browser or Java-Script Domain which maintains the external browser command.
        Code:
        Exact Field Declaration Expression:
         public final Domains domain;
        
      • commandName

        🡅  🡇     🗕  🗗  🗖
        public final java.lang.String commandName
        The Name of the Web-Browser Command that is being executed by this Script.
        Code:
        Exact Field Declaration Expression:
         public final String commandName;
        
      • requestJSONString

        🡅  🡇     🗕  🗗  🗖
        public final java.lang.String requestJSONString
        The request-String that 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-generated JsonObject into 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. This public, final field 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;
        
    • 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 defined
        commandName - The name of the command, as per the Google CDP API
        requestJSONString - The command, formulated a a JSON request
        receiver - This is a function pointer which "translates" the browser's JSON response into a Java RetN POJO.
        resultClass - This is used solely to facilate javac's type 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 parameter RESULT is restricted to the class Ret0.
        Parameters:
        domain - The domain in which this command is defined
        commandName - The name of the command, as per the Google CDP API
        requestJSONString - 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<RESULTexec​(WebSocketSender wss)
        If there are reasons to use a different sender - because certain configurations need to change - then using this exec method allows a user to change senders.
        Parameters:
        wss - The WebSocketSender Instance to use when executing this Script object-instance.

        In the Browser Remote Debug Package (Headless Chrome), the 'Script' instances which are generated expect the user to provide their own constructed WebSocketSender instances 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 returned Promise' method Promise.await() is how to actually retrieve the 'RESULT' that was transmitted by the channel.

        Note: It isn't mandatory to call Promise.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;