001package Torello.Java.Additional;
002
003/**
004 * This functional-interface should have the code/logic for sending an {@code 'INPUT'} message or
005 * request to the asynchronous I/O system/channel.
006 * 
007 * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=SENDER>
008 * 
009 * @param <INPUT> <EMBED CLASS='external-html' DATA-FILE-ID=INPUT>
010 */
011@FunctionalInterface
012public interface Sender<INPUT>
013{
014    /**
015     * This needs to contain the logic for sending a message with an id over the asynchronous I/O
016     * channel.
017     * 
018     * <BR /><BR /><B STYLE='color: red;'>NOTE:</B> So far, the use of the classes {@link Promise},
019     * {@link Script} and {@link Sender} has solely been for the Browser Remote Debug Protocol.
020     * For that use, the instance of {@code Sender} used is the {@code 'send'} method will simply
021     * transmit a Json {@code java.lang.String} to over a {@code WebSocket}.
022     * 
023     * <BR /><BR /><B STYLE='color: red;'>ALSO:</B> See that the {@code 'promise'} that is
024     * ultimately returned to the user needs to be passed as a parameter here.
025     * 
026     * @param requestID The ID of the request-message.  This ID allows the asynchronous logic to
027     * match responses to requests, since they are received asynchronously.
028     * 
029     * @param requestMessage The message to be sent.  For the Browser RPD System, this message will
030     * always be a JSON {@code java.lang.String}.
031     * 
032     * @param promise The promise that's going to be returned to the user.
033     * 
034     * <BR /><BR /><B>NOTE:</B> It may be obvious that the instance of {@code Promise} here is a
035     * {@code Raw-Type} instance of a generic class.  The reason that the {@code Promise} is 
036     * instantiated inside the {@link Script#exec()} method is precisely because the generic
037     * types are not used here.
038     * 
039     * <BR /><BR />Because the class {@code Script} creates the {@code Promise}, and immediately
040     * returns it to the user, the generic-type parameters are much easier to ignore.  Note that,
041     * currently, the only implementing class of {@code Sender} is the {@code WebSocketSender}.
042     */
043    public void send
044        (int requestID, INPUT requestMessage, @SuppressWarnings("rawtypes") Promise promise);
045}