Skip to content

Commit 7e07f3d

Browse files
committed
Polishing
1 parent e039185 commit 7e07f3d

File tree

4 files changed

+35
-39
lines changed

4 files changed

+35
-39
lines changed

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

Lines changed: 20 additions & 22 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,15 +16,14 @@
1616

1717
package org.springframework.web.socket;
1818

19-
import org.eclipse.jetty.websocket.api.StatusCode;
2019
import org.springframework.util.Assert;
2120
import org.springframework.util.ObjectUtils;
2221

2322
/**
2423
* Represents a WebSocket close status code and reason. Status codes in the 1xxx range are
2524
* pre-defined by the protocol. Optionally, a status code may be sent with a reason.
26-
* <p>
27-
* 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
2827
* "Defined Status Codes"</a>.
2928
*
3029
* @author Rossen Stoyanchev
@@ -133,18 +132,16 @@ public final class CloseStatus {
133132
*/
134133
public static final CloseStatus TLS_HANDSHAKE_FAILURE = new CloseStatus(1015);
135134

136-
137135
/**
138-
* Indicates that a session has become unreliable (e.g. timed out while sending
139-
* a message) and extra care should be exercised while closing the session in
140-
* order to avoid locking additional threads.
141-
*
142-
* <p><strong>NOTE:</strong> Spring Framework specific status code.
136+
* A status code for use within the framework the indicate a session has
137+
* become unreliable (e.g. timed out while sending a message) and extra
138+
* care should be exercised, e.g. avoid sending any further data to the
139+
* 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,13 +208,14 @@ 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
219217
public String toString() {
220-
return "CloseStatus [code=" + this.code + ", reason=" + this.reason + "]";
218+
return "CloseStatus[code=" + this.code + ", reason=" + this.reason + "]";
221219
}
222220

223221
}

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

Lines changed: 4 additions & 5 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.context.ApplicationEvent;
2120
import org.springframework.messaging.Message;
2221
import org.springframework.util.Assert;
@@ -53,26 +52,26 @@ public class SessionConnectEvent extends ApplicationEvent {
5352

5453
/**
5554
* Create a new SessionConnectEvent.
56-
*
5755
* @param source the component that published the event (never {@code null})
5856
* @param message the connect message
5957
*/
6058
public SessionConnectEvent(Object source, Message<byte[]> message) {
6159
super(source);
62-
Assert.notNull(message, "'message' must not be null");
60+
Assert.notNull(message, "Message must not be null");
6361
this.message = message;
6462
}
6563

64+
6665
/**
6766
* Return the connect message.
6867
*/
6968
public Message<byte[]> getMessage() {
7069
return this.message;
7170
}
7271

73-
7472
@Override
7573
public String toString() {
76-
return "SessionConnectEvent: message=" + message;
74+
return "SessionConnectEvent: message=" + this.message;
7775
}
76+
7877
}

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

Lines changed: 5 additions & 6 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.context.ApplicationEvent;
2120
import org.springframework.messaging.Message;
2221
import org.springframework.util.Assert;
@@ -35,27 +34,27 @@ public class SessionConnectedEvent extends ApplicationEvent {
3534

3635

3736
/**
38-
* Create a new event.
39-
*
37+
* Create a new SessionConnectedEvent.
4038
* @param source the component that published the event (never {@code null})
4139
* @param message the connected message
4240
*/
4341
public SessionConnectedEvent(Object source, Message<byte[]> message) {
4442
super(source);
45-
Assert.notNull(message, "'message' must not be null");
43+
Assert.notNull(message, "Message must not be null");
4644
this.message = message;
4745
}
4846

47+
4948
/**
5049
* Return the connected message.
5150
*/
5251
public Message<byte[]> getMessage() {
5352
return this.message;
5453
}
5554

56-
5755
@Override
5856
public String toString() {
59-
return "SessionConnectedEvent: message=" + message;
57+
return "SessionConnectedEvent: message=" + this.message;
6058
}
59+
6160
}

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

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

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

19-
2019
import org.springframework.context.ApplicationEvent;
21-
import org.springframework.messaging.Message;
2220
import org.springframework.util.Assert;
2321
import org.springframework.web.socket.CloseStatus;
2422

@@ -27,7 +25,7 @@
2725
* Protocol (e.g. STOMP) as the WebSocket sub-protocol is closed.
2826
*
2927
* <p>Note that this event may be raised more than once for a single session and
30-
* therefore event consumers should be idempotent and ignore a duplicate event..
28+
* therefore event consumers should be idempotent and ignore a duplicate event.
3129
*
3230
* @author Rossen Stoyanchev
3331
* @since 4.0.3
@@ -39,12 +37,12 @@ public class SessionDisconnectEvent extends ApplicationEvent {
3937

4038
private final CloseStatus status;
4139

40+
4241
/**
43-
* Create a new event.
44-
*
42+
* Create a new SessionDisconnectEvent.
4543
* @param source the component that published the event (never {@code null})
4644
* @param sessionId the disconnect message
47-
* @param closeStatus
45+
* @param closeStatus the status object
4846
*/
4947
public SessionDisconnectEvent(Object source, String sessionId, CloseStatus closeStatus) {
5048
super(source);
@@ -53,6 +51,7 @@ public SessionDisconnectEvent(Object source, String sessionId, CloseStatus close
5351
this.status = closeStatus;
5452
}
5553

54+
5655
/**
5756
* Return the session id.
5857
*/
@@ -71,4 +70,5 @@ public CloseStatus getCloseStatus() {
7170
public String toString() {
7271
return "SessionDisconnectEvent: sessionId=" + this.sessionId;
7372
}
73+
7474
}

0 commit comments

Comments
 (0)