1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package Torello.Java.Additional;

/**
 * This functional-interface should have the code/logic for sending an {@code 'INPUT'} message or
 * request to the asynchronous I/O system/channel.
 * 
 * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=SENDER>
 * 
 * @param <INPUT> <EMBED CLASS='external-html' DATA-FILE-ID=INPUT>
 */
@FunctionalInterface
public interface Sender<INPUT>
{
    /**
     * This needs to contain the logic for sending a message with an id over the asynchronous I/O
     * channel.
     * 
     * <BR /><BR /><B STYLE='color: red;'>NOTE:</B> So far, the use of the classes {@link Promise},
     * {@link Script} and {@link Sender} has solely been for the Browser Remote Debug Protocol.
     * For that use, the instance of {@code Sender} used is the {@code 'send'} method will simply
     * transmit a Json {@code java.lang.String} to over a {@code WebSocket}.
     * 
     * <BR /><BR /><B STYLE='color: red;'>ALSO:</B> See that the {@code 'promise'} that is
     * ultimately returned to the user needs to be passed as a parameter here.
     * 
     * @param requestID The ID of the request-message.  This ID allows the asynchronous logic to
     * match responses to requests, since they are received asynchronously.
     * 
     * @param requestMessage The message to be sent.  For the Browser RPD System, this message will
     * always be a JSON {@code java.lang.String}.
     * 
     * @param promise The promise that's going to be returned to the user.
     * 
     * <BR /><BR /><B>NOTE:</B> It may be obvious that the instance of {@code Promise} here is a
     * {@code Raw-Type} instance of a generic class.  The reason that the {@code Promise} is 
     * instantiated inside the {@link Script#exec()} method is precisely because the generic
     * types are not used here.
     * 
     * <BR /><BR />Because the class {@code Script} creates the {@code Promise}, and immediately
     * returns it to the user, the generic-type parameters are much easier to ignore.  Note that,
     * currently, the only implementing class of {@code Sender} is the {@code WebSocketSender}.
     */
    public void send
        (int requestID, INPUT requestMessage, @SuppressWarnings("rawtypes") Promise promise);
}