/
CoreSession.java
309 lines (265 loc) · 8.25 KB
/
CoreSession.java
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
//
// ========================================================================
// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.websocket.core;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URI;
import java.util.List;
import java.util.Map;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.Callback;
/**
* Represents the outgoing Frames.
*/
public interface CoreSession extends OutgoingFrames, Configuration
{
/**
* The negotiated WebSocket Sub-Protocol for this session.
*
* @return the negotiated WebSocket Sub-Protocol for this session.
*/
String getNegotiatedSubProtocol();
/**
* The negotiated WebSocket Extension Configurations for this session.
*
* @return the list of Negotiated Extension Configurations for this session.
*/
List<ExtensionConfig> getNegotiatedExtensions();
/**
* The parameter map (from URI Query) for the active session.
*
* @return the immutable map of parameters
*/
Map<String, List<String>> getParameterMap();
/**
* The active {@code Sec-WebSocket-Version} (protocol version) in use.
*
* @return the protocol version in use.
*/
String getProtocolVersion();
/**
* The active connection's Request URI.
* This is the URI of the upgrade request and is typically http: or https: rather than
* the ws: or wss: scheme.
*
* @return the absolute URI (including Query string)
*/
URI getRequestURI();
/**
* The active connection's Secure status indicator.
*
* @return true if connection is secure (similar in role to {@code HttpServletRequest.isSecure()})
*/
boolean isSecure();
/**
* @return Client or Server behaviour
*/
Behavior getBehavior();
/**
* @return the WebSocketComponents instance in use for this Connection.
*/
WebSocketComponents getWebSocketComponents();
/**
* @return The shared ByteBufferPool
*/
ByteBufferPool getByteBufferPool();
/**
* The Local Socket Address for the connection
* <p>
* Do not assume that this will return a {@link InetSocketAddress} in all cases.
* Use of various proxies, and even UnixSockets can result a SocketAddress being returned
* without supporting {@link InetSocketAddress}
* </p>
*
* @return the SocketAddress for the local connection, or null if not supported by Session
*/
SocketAddress getLocalAddress();
/**
* The Remote Socket Address for the connection
* <p>
* Do not assume that this will return a {@link InetSocketAddress} in all cases.
* Use of various proxies, and even UnixSockets can result a SocketAddress being returned
* without supporting {@link InetSocketAddress}
* </p>
*
* @return the SocketAddress for the remote connection, or null if not supported by Session
*/
SocketAddress getRemoteAddress();
/**
* @return True if the websocket is open outbound
*/
boolean isOutputOpen();
/**
* If using BatchMode.ON or BatchMode.AUTO, trigger a flush of enqueued / batched frames.
*
* @param callback the callback to track close frame sent (or failed)
*/
void flush(Callback callback);
/**
* Initiate close handshake, no payload (no declared status code or reason phrase)
*
* @param callback the callback to track close frame sent (or failed)
*/
void close(Callback callback);
/**
* Initiate close handshake with provide status code and optional reason phrase.
*
* @param statusCode the status code (should be a valid status code that can be sent)
* @param reason optional reason phrase (will be truncated automatically by implementation to fit within limits of protocol)
* @param callback the callback to track close frame sent (or failed)
*/
void close(int statusCode, String reason, Callback callback);
/**
* Issue a harsh abort of the underlying connection.
* <p>
* This will terminate the connection, without sending a websocket close frame.
* No WebSocket Protocol close handshake will be performed.
* </p>
* <p>
* Once called, any read/write activity on the websocket from this point will be indeterminate.
* This can result in the {@link FrameHandler#onError(Throwable, Callback)} event being called indicating any issue that arises.
* </p>
* <p>
* Once the underlying connection has been determined to be closed, the {@link FrameHandler#onClosed(CloseStatus, Callback)} event will be called.
* </p>
*/
void abort();
/**
* Manage flow control by indicating demand for handling Frames. A call to
* {@link FrameHandler#onFrame(Frame, Callback)} will only be made if a
* corresponding demand has been signaled. It is an error to call this method
* if {@link FrameHandler#isDemanding()} returns false.
*
* @param n The number of frames that can be handled (in sequential calls to
* {@link FrameHandler#onFrame(Frame, Callback)}). May not be negative.
*/
void demand(long n);
/**
* @return true if an extension has been negotiated which uses the RSV1 bit.
*/
boolean isRsv1Used();
/**
* @return true if an extension has been negotiated which uses the RSV2 bit.
*/
boolean isRsv2Used();
/**
* @return true if an extension has been negotiated which uses the RSV3 bit.
*/
boolean isRsv3Used();
class Empty extends ConfigurationCustomizer implements CoreSession
{
@Override
public String getNegotiatedSubProtocol()
{
return null;
}
@Override
public List<ExtensionConfig> getNegotiatedExtensions()
{
return null;
}
@Override
public Map<String, List<String>> getParameterMap()
{
return null;
}
@Override
public String getProtocolVersion()
{
return null;
}
@Override
public URI getRequestURI()
{
return null;
}
@Override
public boolean isSecure()
{
return false;
}
@Override
public void abort()
{
}
@Override
public Behavior getBehavior()
{
return null;
}
@Override
public WebSocketComponents getWebSocketComponents()
{
return null;
}
@Override
public ByteBufferPool getByteBufferPool()
{
return null;
}
@Override
public SocketAddress getLocalAddress()
{
return null;
}
@Override
public SocketAddress getRemoteAddress()
{
return null;
}
@Override
public boolean isOutputOpen()
{
return true;
}
@Override
public void flush(Callback callback)
{
callback.succeeded();
}
@Override
public void close(Callback callback)
{
callback.succeeded();
}
@Override
public void close(int statusCode, String reason, Callback callback)
{
callback.succeeded();
}
@Override
public void demand(long n)
{
}
@Override
public void sendFrame(Frame frame, Callback callback, boolean batch)
{
callback.succeeded();
}
@Override
public boolean isRsv1Used()
{
return false;
}
@Override
public boolean isRsv2Used()
{
return false;
}
@Override
public boolean isRsv3Used()
{
return false;
}
}
}