lightstreamer_client/client_listener.rs
1use std::fmt::Debug;
2
3/// Interface to be implemented to listen to `LightstreamerClient` events comprehending notifications
4/// of connection activity and errors.
5///
6/// Events for these listeners are dispatched by a different thread than the one that generates them.
7/// This means that, upon reception of an event, it is possible that the internal state of the client
8/// has changed. On the other hand, all the notifications for a single `LightstreamerClient`,
9/// including notifications to `ClientListener`, `SubscriptionListener` and `ClientMessageListener`
10/// will be dispatched by the same thread.
11pub trait ClientListener: Debug + Send {
12 /// Event handler that receives a notification when the `ClientListener` instance is removed
13 /// from a `LightstreamerClient` through `LightstreamerClient.removeListener()`. This is the
14 /// last event to be fired on the listener.
15 fn on_listen_end(&self) {
16 // Implementation for on_listen_end
17 }
18
19 /// Event handler that receives a notification when the `ClientListener` instance is added
20 /// to a `LightstreamerClient` through `LightstreamerClient.addListener()`. This is the first
21 /// event to be fired on the listener.
22 fn on_listen_start(&self) {
23 // Implementation for on_listen_start
24 }
25
26 /// Event handler that receives a notification each time the value of a property of
27 /// `LightstreamerClient.connectionDetails` or `LightstreamerClient.connectionOptions` is changed.
28 ///
29 /// Properties of these objects can be modified by direct calls to them or by server sent events.
30 ///
31 /// # Parameters
32 ///
33 /// * `property`: the name of the changed property.
34 ///
35 /// Possible values are:
36 ///
37 /// - `adapterSet`
38 /// - `serverAddress`
39 /// - `user`
40 /// - `password`
41 /// - `serverInstanceAddress`
42 /// - `serverSocketName`
43 /// - `clientIp`
44 /// - `sessionId`
45 /// - `contentLength`
46 /// - `idleTimeout`
47 /// - `keepaliveInterval`
48 /// - `requestedMaxBandwidth`
49 /// - `realMaxBandwidth`
50 /// - `pollingInterval`
51 /// - `reconnectTimeout`
52 /// - `stalledTimeout`
53 /// - `retryDelay`
54 /// - `firstRetryMaxDelay`
55 /// - `slowingEnabled`
56 /// - `forcedTransport`
57 /// - `serverInstanceAddressIgnored`
58 /// - `reverseHeartbeatInterval`
59 /// - `earlyWSOpenEnabled`
60 /// - `httpExtraHeaders`
61 /// - `httpExtraHeadersOnSessionCreationOnly`
62 ///
63 /// See also `LightstreamerClient.connectionDetails`
64 ///
65 /// See also `LightstreamerClient.connectionOptions`
66 fn on_property_change(&self, _property: &str) {
67 // Implementation for on_property_change
68 unimplemented!("Implement on_property_change method for ClientListener");
69 }
70
71 /// Event handler that is called when the Server notifies a refusal on the client attempt
72 /// to open a new connection or the interruption of a streaming connection. In both cases,
73 /// the `onStatusChange()` event handler has already been invoked with a "DISCONNECTED" status
74 /// and no recovery attempt has been performed. By setting a custom handler, however, it is
75 /// possible to override this and perform custom recovery actions.
76 ///
77 /// # Parameters
78 ///
79 /// * `code`: The error code. It can be one of the following:
80 /// - `1`: user/password check failed
81 /// - `2`: requested Adapter Set not available
82 /// - `7`: licensed maximum number of sessions reached (this can only happen with some licenses)
83 /// - `8`: configured maximum number of sessions reached
84 /// - `9`: configured maximum server load reached
85 /// - `10`: new sessions temporarily blocked
86 /// - `11`: streaming is not available because of Server license restrictions (this can only happen with special licenses).
87 /// - `21`: a request for this session has unexpectedly reached a wrong Server instance, which suggests that a routing issue may be in place.
88 /// - `30-41`: the current connection or the whole session has been closed by external agents; the possible cause may be:
89 /// - The session was closed on the Server side (via software or by the administrator) (32), or through a client "destroy" request (31);
90 /// - The Metadata Adapter imposes limits on the overall open sessions for the current user and has requested the closure of the current session upon opening of a new session for the same user on a different browser window (35);
91 /// - An unexpected error occurred on the Server while the session was in activity (33, 34);
92 /// - An unknown or unexpected cause; any code different from the ones identified in the above cases could be issued. A detailed description for the specific cause is currently not supplied (i.e. `errorMessage` is `None` in this case).
93 /// - `60`: this version of the client is not allowed by the current license terms.
94 /// - `61`: there was an error in the parsing of the server response thus the client cannot continue with the current session.
95 /// - `66`: an unexpected exception was thrown by the Metadata Adapter while authorizing the connection.
96 /// - `68`: the Server could not open or continue with the session because of an internal error.
97 /// - `70`: an unusable port was configured on the server address.
98 /// - `71`: this kind of client is not allowed by the current license terms.
99 /// - `<= 0`: the Metadata Adapter has refused the user connection; the code value is dependent on the specific Metadata Adapter implementation
100 /// * `message`: The description of the error as sent by the Server.
101 ///
102 /// See also `onStatusChange()`
103 ///
104 /// See also `ConnectionDetails.setAdapterSet()`
105 fn on_server_error(&self, _code: i32, _message: &str) {
106 // Implementation for on_server_error
107 unimplemented!("Implement on_server_error method for ClientListener");
108 }
109
110 /// Event handler that receives a notification each time the `LightstreamerClient` status has changed.
111 /// The status changes may be originated either by custom actions (e.g. by calling `LightstreamerClient.disconnect()`)
112 /// or by internal actions.
113 ///
114 /// The normal cases are the following:
115 ///
116 /// After issuing `connect()` when the current status is `DISCONNECTED*`, the client will switch to `CONNECTING`
117 /// first and to `CONNECTED:STREAM-SENSING` as soon as the pre-flight request receives its answer. As soon as
118 /// the new session is established, it will switch to `CONNECTED:WS-STREAMING` if the environment permits WebSockets;
119 /// otherwise it will switch to `CONNECTED:HTTP-STREAMING` if the environment permits streaming or to
120 /// `CONNECTED:HTTP-POLLING` as a last resort.
121 ///
122 /// On the other hand, after issuing `connect` when the status is already `CONNECTED:*` a switch to `CONNECTING`
123 /// is usually not needed and the current session is kept.
124 ///
125 /// After issuing `LightstreamerClient.disconnect()`, the status will switch to `DISCONNECTED`.
126 ///
127 /// In case of a server connection refusal, the status may switch from `CONNECTING` directly to `DISCONNECTED`.
128 /// After that, the `onServerError()` event handler will be invoked.
129 ///
130 /// Possible special cases are the following:
131 ///
132 /// - In case of Server unavailability during streaming, the status may switch from `CONNECTED:*-STREAMING` to
133 /// `STALLED` (see `ConnectionOptions.setStalledTimeout()`). If the unavailability ceases, the status will
134 /// switch back to `CONNECTED:*-STREAMING`; otherwise, if the unavailability persists (see `ConnectionOptions.setReconnectTimeout()`),
135 /// the status will switch to `DISCONNECTED:TRYING-RECOVERY` and eventually to `CONNECTED:*-STREAMING`.
136 /// - In case the connection or the whole session is forcibly closed by the Server, the status may switch from
137 /// `CONNECTED:*-STREAMING` or `CONNECTED:*-POLLING` directly to `DISCONNECTED`. After that, the `onServerError()`
138 /// event handler will be invoked.
139 /// - Depending on the setting in `ConnectionOptions.setSlowingEnabled()`, in case of slow update processing,
140 /// the status may switch from `CONNECTED:WS-STREAMING` to `CONNECTED:WS-POLLING` or from `CONNECTED:HTTP-STREAMING`
141 /// to `CONNECTED:HTTP-POLLING`.
142 /// - If the status is `CONNECTED:*-POLLING` and any problem during an intermediate poll occurs, the status may
143 /// switch to `CONNECTING` and eventually to `CONNECTED:*-POLLING`. The same may hold for the `CONNECTED:*-STREAMING`
144 /// case, when a rebind is needed.
145 /// - In case a forced transport was set through `ConnectionOptions.setForcedTransport()`, only the related final
146 /// status or statuses are possible.
147 /// - In case of connection problems, the status may switch from any value to `DISCONNECTED:WILL-RETRY`
148 /// (see `ConnectionOptions.setRetryDelay()`), then to `CONNECTING` and a new attempt will start. However,
149 /// in most cases, the client will try to recover the current session; hence, the `DISCONNECTED:TRYING-RECOVERY`
150 /// status will be entered and the recovery attempt will start.
151 /// - In case of connection problems during a recovery attempt, the status may stay in `DISCONNECTED:TRYING-RECOVERY`
152 /// for long time, while further attempts are made. If the recovery is no longer possible, the current session
153 /// will be abandoned and the status will switch to `DISCONNECTED:WILL-RETRY` before the next attempts.
154 ///
155 /// By setting a custom handler it is possible to perform actions related to connection and disconnection
156 /// occurrences. Note that `LightstreamerClient.connect()` and `LightstreamerClient.disconnect()`, as any other
157 /// method, can be issued directly from within a handler.
158 ///
159 /// # Parameters
160 ///
161 /// * `status`: The new status. It can be one of the following values:
162 /// - `CONNECTING`: the client has started a connection attempt and is waiting for a Server answer.
163 /// - `CONNECTED:STREAM-SENSING`: the client received a first response from the server and is now evaluating
164 /// if a streaming connection is fully functional.
165 /// - `CONNECTED:WS-STREAMING`: a streaming connection over WebSocket has been established.
166 /// - `CONNECTED:HTTP-STREAMING`: a streaming connection over HTTP has been established.
167 /// - `CONNECTED:WS-POLLING`: a polling connection over WebSocket has been started. Note that, unlike polling
168 /// over HTTP, in this case only one connection is actually opened (see `ConnectionOptions.setSlowingEnabled()`).
169 /// - `CONNECTED:HTTP-POLLING`: a polling connection over HTTP has been started.
170 /// - `STALLED`: a streaming session has been silent for a while, the status will eventually return to its
171 /// previous `CONNECTED:*-STREAMING` status or will switch to `DISCONNECTED:WILL-RETRY` / `DISCONNECTED:TRYING-RECOVERY`.
172 /// - `DISCONNECTED:WILL-RETRY`: a connection or connection attempt has been closed; a new attempt will be
173 /// performed (possibly after a timeout).
174 /// - `DISCONNECTED:TRYING-RECOVERY`: a connection has been closed and the client has started a connection
175 /// attempt and is waiting for a Server answer; if successful, the underlying session will be kept.
176 /// - `DISCONNECTED`: a connection or connection attempt has been closed. The client will not connect anymore
177 /// until a new `LightstreamerClient.connect()` call is issued.
178 ///
179 /// See also `LightstreamerClient.connect()`
180 ///
181 /// See also `LightstreamerClient.disconnect()`
182 ///
183 /// See also `LightstreamerClient.getStatus()`
184 fn on_status_change(&self, _status: &str) {
185 // Implementation for on_status_change
186 unimplemented!("Implement on_status_change method for ClientListener");
187 }
188}