From 0caeffcd5432ac6ee475e9e265db24bf89bc4714 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 27 Nov 2014 18:28:16 +0100 Subject: [PATCH] Polishing (cherry picked from commit 7e07f3d) --- .../web/socket/CloseStatus.java | 32 +++++++++---------- .../socket/messaging/SessionConnectEvent.java | 7 ++-- .../messaging/SessionConnectedEvent.java | 10 +++--- .../messaging/SessionDisconnectEvent.java | 11 +++++-- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java b/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java index 11b1984d38..c34307370e 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,14 @@ package org.springframework.web.socket; -import org.eclipse.jetty.websocket.api.StatusCode; - import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; /** * Represents a WebSocket close status code and reason. Status codes in the 1xxx range are * pre-defined by the protocol. Optionally, a status code may be sent with a reason. - *

- * See RFC 6455, Section 7.4.1 + * + *

See RFC 6455, Section 7.4.1 * "Defined Status Codes". * * @author Rossen Stoyanchev @@ -134,17 +132,16 @@ public final class CloseStatus { */ public static final CloseStatus TLS_HANDSHAKE_FAILURE = new CloseStatus(1015); - /** * A status code for use within the framework the indicate a session has * become unreliable (e.g. timed out while sending a message) and extra * care should be exercised, e.g. avoid sending any further data to the * client that may be done during normal shutdown. + * @since 4.0.3 */ public static final CloseStatus SESSION_NOT_RELIABLE = new CloseStatus(4500); - private final int code; private final String reason; @@ -164,39 +161,39 @@ public final class CloseStatus { * @param reason the reason */ public CloseStatus(int code, String reason) { - Assert.isTrue((code >= 1000 && code < 5000), "Invalid code"); + Assert.isTrue((code >= 1000 && code < 5000), "Invalid status code"); this.code = code; this.reason = reason; } /** - * Returns the status code. + * Return the status code. */ public int getCode() { return this.code; } /** - * Returns the reason or {@code null}. + * Return the reason, or {@code null} if none. */ public String getReason() { return this.reason; } /** - * Crate a new {@link CloseStatus} from this one with the specified reason. + * Create a new {@link CloseStatus} from this one with the specified reason. * @param reason the reason - * @return a new {@link StatusCode} instance + * @return a new {@link CloseStatus} instance */ public CloseStatus withReason(String reason) { Assert.hasText(reason, "Reason must not be empty"); return new CloseStatus(this.code, reason); } - @Override - public int hashCode() { - return this.code * 29 + ObjectUtils.nullSafeHashCode(this.reason); + + public boolean equalsCode(CloseStatus other) { + return (this.code == other.code); } @Override @@ -211,8 +208,9 @@ public final class CloseStatus { return (this.code == otherStatus.code && ObjectUtils.nullSafeEquals(this.reason, otherStatus.reason)); } - public boolean equalsCode(CloseStatus other) { - return this.code == other.code; + @Override + public int hashCode() { + return this.code * 29 + ObjectUtils.nullSafeHashCode(this.reason); } @Override diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionConnectEvent.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionConnectEvent.java index fbc4d34d3a..8d4cdcb901 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionConnectEvent.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionConnectEvent.java @@ -16,7 +16,6 @@ package org.springframework.web.socket.messaging; - import org.springframework.messaging.Message; /** @@ -33,7 +32,11 @@ import org.springframework.messaging.Message; @SuppressWarnings("serial") public class SessionConnectEvent extends AbstractSubProtocolEvent { - + /** + * Create a new SessionConnectEvent. + * @param source the component that published the event (never {@code null}) + * @param message the connect message + */ public SessionConnectEvent(Object source, Message message) { super(source, message); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionConnectedEvent.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionConnectedEvent.java index 06ef4c8cfc..1a5c9279ac 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionConnectedEvent.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionConnectedEvent.java @@ -16,13 +16,11 @@ package org.springframework.web.socket.messaging; - import org.springframework.messaging.Message; /** * A connected event represents the server response to a client's connect request. - * See {@link org.springframework.web.socket.messaging.SessionConnectEvent - * SessionConnectEvent}. + * See {@link org.springframework.web.socket.messaging.SessionConnectEvent}. * * @author Rossen Stoyanchev * @since 4.0.3 @@ -30,7 +28,11 @@ import org.springframework.messaging.Message; @SuppressWarnings("serial") public class SessionConnectedEvent extends AbstractSubProtocolEvent { - + /** + * Create a new SessionConnectedEvent. + * @param source the component that published the event (never {@code null}) + * @param message the connected message + */ public SessionConnectedEvent(Object source, Message message) { super(source, message); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionDisconnectEvent.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionDisconnectEvent.java index eed87ef06e..733349c6e7 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionDisconnectEvent.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionDisconnectEvent.java @@ -16,7 +16,6 @@ package org.springframework.web.socket.messaging; - import org.springframework.messaging.Message; import org.springframework.util.Assert; import org.springframework.web.socket.CloseStatus; @@ -26,7 +25,7 @@ import org.springframework.web.socket.CloseStatus; * Protocol (e.g. STOMP) as the WebSocket sub-protocol is closed. * *

Note that this event may be raised more than once for a single session and - * therefore event consumers should be idempotent and ignore a duplicate event.. + * therefore event consumers should be idempotent and ignore a duplicate event. * * @author Rossen Stoyanchev * @since 4.0.3 @@ -40,7 +39,11 @@ public class SessionDisconnectEvent extends AbstractSubProtocolEvent { /** - * Create a new event. + * Create a new SessionDisconnectEvent. + * @param source the component that published the event (never {@code null}) + * @param message the message + * @param sessionId the disconnect message + * @param closeStatus the status object */ public SessionDisconnectEvent(Object source, Message message, String sessionId, CloseStatus closeStatus) { super(source, message); @@ -49,6 +52,7 @@ public class SessionDisconnectEvent extends AbstractSubProtocolEvent { this.status = closeStatus; } + /** * Return the session id. */ @@ -68,4 +72,5 @@ public class SessionDisconnectEvent extends AbstractSubProtocolEvent { return "SessionDisconnectEvent[sessionId=" + this.sessionId + ", " + (this.status != null ? this.status.toString() : "closeStatus=null") + "]"; } + }