Skip to content

Commit 0caeffc

Browse files
committed
Polishing
(cherry picked from commit 7e07f3d)
1 parent eacd4a1 commit 0caeffc

File tree

4 files changed

+34
-26
lines changed

4 files changed

+34
-26
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,16 +16,14 @@
1616

1717
package org.springframework.web.socket;
1818

19-
import org.eclipse.jetty.websocket.api.StatusCode;
20-
2119
import org.springframework.util.Assert;
2220
import org.springframework.util.ObjectUtils;
2321

2422
/**
2523
* Represents a WebSocket close status code and reason. Status codes in the 1xxx range are
2624
* pre-defined by the protocol. Optionally, a status code may be sent with a reason.
27-
* <p>
28-
* See <a href="https://tools.ietf.org/html/rfc6455#section-7.4.1">RFC 6455, Section 7.4.1
25+
*
26+
* <p>See <a href="https://tools.ietf.org/html/rfc6455#section-7.4.1">RFC 6455, Section 7.4.1
2927
* "Defined Status Codes"</a>.
3028
*
3129
* @author Rossen Stoyanchev
@@ -134,17 +132,16 @@ public final class CloseStatus {
134132
*/
135133
public static final CloseStatus TLS_HANDSHAKE_FAILURE = new CloseStatus(1015);
136134

137-
138135
/**
139136
* A status code for use within the framework the indicate a session has
140137
* become unreliable (e.g. timed out while sending a message) and extra
141138
* care should be exercised, e.g. avoid sending any further data to the
142139
* client that may be done during normal shutdown.
140+
* @since 4.0.3
143141
*/
144142
public static final CloseStatus SESSION_NOT_RELIABLE = new CloseStatus(4500);
145143

146144

147-
148145
private final int code;
149146

150147
private final String reason;
@@ -164,39 +161,39 @@ public CloseStatus(int code) {
164161
* @param reason the reason
165162
*/
166163
public CloseStatus(int code, String reason) {
167-
Assert.isTrue((code >= 1000 && code < 5000), "Invalid code");
164+
Assert.isTrue((code >= 1000 && code < 5000), "Invalid status code");
168165
this.code = code;
169166
this.reason = reason;
170167
}
171168

172169

173170
/**
174-
* Returns the status code.
171+
* Return the status code.
175172
*/
176173
public int getCode() {
177174
return this.code;
178175
}
179176

180177
/**
181-
* Returns the reason or {@code null}.
178+
* Return the reason, or {@code null} if none.
182179
*/
183180
public String getReason() {
184181
return this.reason;
185182
}
186183

187184
/**
188-
* Crate a new {@link CloseStatus} from this one with the specified reason.
185+
* Create a new {@link CloseStatus} from this one with the specified reason.
189186
* @param reason the reason
190-
* @return a new {@link StatusCode} instance
187+
* @return a new {@link CloseStatus} instance
191188
*/
192189
public CloseStatus withReason(String reason) {
193190
Assert.hasText(reason, "Reason must not be empty");
194191
return new CloseStatus(this.code, reason);
195192
}
196193

197-
@Override
198-
public int hashCode() {
199-
return this.code * 29 + ObjectUtils.nullSafeHashCode(this.reason);
194+
195+
public boolean equalsCode(CloseStatus other) {
196+
return (this.code == other.code);
200197
}
201198

202199
@Override
@@ -211,8 +208,9 @@ public boolean equals(Object other) {
211208
return (this.code == otherStatus.code && ObjectUtils.nullSafeEquals(this.reason, otherStatus.reason));
212209
}
213210

214-
public boolean equalsCode(CloseStatus other) {
215-
return this.code == other.code;
211+
@Override
212+
public int hashCode() {
213+
return this.code * 29 + ObjectUtils.nullSafeHashCode(this.reason);
216214
}
217215

218216
@Override

spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionConnectEvent.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.web.socket.messaging;
1818

19-
2019
import org.springframework.messaging.Message;
2120

2221
/**
@@ -33,7 +32,11 @@
3332
@SuppressWarnings("serial")
3433
public class SessionConnectEvent extends AbstractSubProtocolEvent {
3534

36-
35+
/**
36+
* Create a new SessionConnectEvent.
37+
* @param source the component that published the event (never {@code null})
38+
* @param message the connect message
39+
*/
3740
public SessionConnectEvent(Object source, Message<byte[]> message) {
3841
super(source, message);
3942
}

spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionConnectedEvent.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,23 @@
1616

1717
package org.springframework.web.socket.messaging;
1818

19-
2019
import org.springframework.messaging.Message;
2120

2221
/**
2322
* A connected event represents the server response to a client's connect request.
24-
* See {@link org.springframework.web.socket.messaging.SessionConnectEvent
25-
* SessionConnectEvent}.
23+
* See {@link org.springframework.web.socket.messaging.SessionConnectEvent}.
2624
*
2725
* @author Rossen Stoyanchev
2826
* @since 4.0.3
2927
*/
3028
@SuppressWarnings("serial")
3129
public class SessionConnectedEvent extends AbstractSubProtocolEvent {
3230

33-
31+
/**
32+
* Create a new SessionConnectedEvent.
33+
* @param source the component that published the event (never {@code null})
34+
* @param message the connected message
35+
*/
3436
public SessionConnectedEvent(Object source, Message<byte[]> message) {
3537
super(source, message);
3638
}

spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionDisconnectEvent.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.web.socket.messaging;
1818

19-
2019
import org.springframework.messaging.Message;
2120
import org.springframework.util.Assert;
2221
import org.springframework.web.socket.CloseStatus;
@@ -26,7 +25,7 @@
2625
* Protocol (e.g. STOMP) as the WebSocket sub-protocol is closed.
2726
*
2827
* <p>Note that this event may be raised more than once for a single session and
29-
* therefore event consumers should be idempotent and ignore a duplicate event..
28+
* therefore event consumers should be idempotent and ignore a duplicate event.
3029
*
3130
* @author Rossen Stoyanchev
3231
* @since 4.0.3
@@ -40,7 +39,11 @@ public class SessionDisconnectEvent extends AbstractSubProtocolEvent {
4039

4140

4241
/**
43-
* Create a new event.
42+
* Create a new SessionDisconnectEvent.
43+
* @param source the component that published the event (never {@code null})
44+
* @param message the message
45+
* @param sessionId the disconnect message
46+
* @param closeStatus the status object
4447
*/
4548
public SessionDisconnectEvent(Object source, Message<byte[]> message, String sessionId, CloseStatus closeStatus) {
4649
super(source, message);
@@ -49,6 +52,7 @@ public SessionDisconnectEvent(Object source, Message<byte[]> message, String ses
4952
this.status = closeStatus;
5053
}
5154

55+
5256
/**
5357
* Return the session id.
5458
*/
@@ -68,4 +72,5 @@ public String toString() {
6872
return "SessionDisconnectEvent[sessionId=" + this.sessionId + ", " +
6973
(this.status != null ? this.status.toString() : "closeStatus=null") + "]";
7074
}
75+
7176
}

0 commit comments

Comments
 (0)