1
1
package io .avaje .jex .http .sse ;
2
2
3
- import java .io .Closeable ;
4
- import java .util .function .Consumer ;
5
-
6
3
import io .avaje .jex .http .Context ;
7
4
import io .avaje .jex .http .ExchangeHandler ;
8
5
import io .avaje .jex .spi .JsonService ;
6
+ import java .io .Closeable ;
7
+ import java .util .function .Consumer ;
9
8
10
9
/**
11
- * A client for Server-Sent Events (SSE). This class handles the setup of the SSE connection,
12
- * sending events and comments to the client, and managing the lifecycle of the connection. It
13
- * ensures proper headers are set and provides methods for sending various types of data.
10
+ * A client for Server-Sent Events (SSE). This class handles the setup of the SSE connection, sending events and
11
+ * comments to the client, and managing the lifecycle of the connection. It ensures proper headers are set and provides
12
+ * methods for sending various types of data.
14
13
*
15
- * <p>This class implements {@link Closeable} to allow for proper resource management. The
16
- * connection is automatically closed if the client disconnects or if an error occurs during event
17
- * emission.
14
+ * <p>This class implements {@link Closeable} to allow for proper resource management. The connection is automatically
15
+ * closed if the client disconnects or if an error occurs during event emission.
18
16
*/
19
17
public interface SseClient extends Closeable {
20
18
@@ -35,23 +33,22 @@ static ExchangeHandler handler(Consumer<SseClient> consumer) {
35
33
Context ctx ();
36
34
37
35
/**
38
- * By blocking the SSE connection, you can share this client outside the handler to notify it from
39
- * other sources. Keep in mind that this function will block the handler until the SSE client is
40
- * released by another thread.
36
+ * By blocking the SSE connection, you can share this client outside the handler to notify it from other sources.
37
+ * Keep in mind that this function will block the handler until the SSE client is released by another thread.
41
38
*/
42
39
void keepAlive ();
43
40
44
41
/**
45
- * Add a callback that will be called either when connection is closed through {@link #close()},
46
- * or when the {@link Emitter} is detected as closed.
42
+ * Add a callback that will be called either when connection is closed through {@link #close()}, or when the
43
+ * {@link Emitter} is detected as closed.
47
44
*
48
45
* @param task task to run
49
46
*/
50
47
void onClose (Runnable task );
51
48
52
49
/**
53
- * Attempt to send a comment. If the {@link Emitter} fails to emit (remote client has
54
- * disconnected), the {@link #close()} function will be called instead.
50
+ * Attempt to send a comment. If the {@link Emitter} fails to emit (remote client has disconnected), the
51
+ * {@link #close()} function will be called instead.
55
52
*/
56
53
void sendComment (String comment );
57
54
@@ -62,19 +59,19 @@ static ExchangeHandler handler(Consumer<SseClient> consumer) {
62
59
void sendEvent (String event , Object data );
63
60
64
61
/**
65
- * Attempt to send an event. If the {@link Emitter} fails to emit (remote client has
66
- * disconnected), the {@link #close()} function will be called instead.
62
+ * Attempt to send an event. If the {@link Emitter} fails to emit (remote client has disconnected), the
63
+ * {@link #close()} function will be called instead.
67
64
*
68
65
* @param event The name of the event.
69
- * @param data The data to send in the event. This can be a String, an InputStream, or any object
70
- * that can be serialized to JSON using the configured {@link JsonService}.
66
+ * @param data The data to send in the event. This can be a String, an InputStream, or any object that can be
67
+ * serialized to JSON using the configured {@link JsonService}.
71
68
* @param id The ID of the event.
72
69
*/
73
70
void sendEvent (String event , Object data , String id );
74
71
75
72
/**
76
- * Returns true if {@link #close()} has been called. This can either be by the user, or by Jex
77
- * upon detecting that the {@link Emitter} is closed.
73
+ * Returns true if {@link #close()} has been called. This can either be by the user, or by Jex upon detecting that
74
+ * the {@link Emitter} is closed.
78
75
*/
79
76
boolean terminated ();
80
77
}
0 commit comments