Polishing

This commit is contained in:
Juergen Hoeller 2014-11-27 01:41:48 +01:00
parent e039185fec
commit 7e07f3d083
4 changed files with 35 additions and 39 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,15 +16,14 @@
package org.springframework.web.socket; package org.springframework.web.socket;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
/** /**
* Represents a WebSocket close status code and reason. Status codes in the 1xxx range are * 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. * pre-defined by the protocol. Optionally, a status code may be sent with a reason.
* <p> *
* See <a href="https://tools.ietf.org/html/rfc6455#section-7.4.1">RFC 6455, Section 7.4.1 * <p>See <a href="https://tools.ietf.org/html/rfc6455#section-7.4.1">RFC 6455, Section 7.4.1
* "Defined Status Codes"</a>. * "Defined Status Codes"</a>.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
@ -133,18 +132,16 @@ public final class CloseStatus {
*/ */
public static final CloseStatus TLS_HANDSHAKE_FAILURE = new CloseStatus(1015); public static final CloseStatus TLS_HANDSHAKE_FAILURE = new CloseStatus(1015);
/** /**
* Indicates that a session has become unreliable (e.g. timed out while sending * A status code for use within the framework the indicate a session has
* a message) and extra care should be exercised while closing the session in * become unreliable (e.g. timed out while sending a message) and extra
* order to avoid locking additional threads. * care should be exercised, e.g. avoid sending any further data to the
* * client that may be done during normal shutdown.
* <p><strong>NOTE:</strong> Spring Framework specific status code. * @since 4.0.3
*/ */
public static final CloseStatus SESSION_NOT_RELIABLE = new CloseStatus(4500); public static final CloseStatus SESSION_NOT_RELIABLE = new CloseStatus(4500);
private final int code; private final int code;
private final String reason; private final String reason;
@ -164,39 +161,39 @@ public final class CloseStatus {
* @param reason the reason * @param reason the reason
*/ */
public CloseStatus(int code, String 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.code = code;
this.reason = reason; this.reason = reason;
} }
/** /**
* Returns the status code. * Return the status code.
*/ */
public int getCode() { public int getCode() {
return this.code; return this.code;
} }
/** /**
* Returns the reason or {@code null}. * Return the reason, or {@code null} if none.
*/ */
public String getReason() { public String getReason() {
return this.reason; 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 * @param reason the reason
* @return a new {@link StatusCode} instance * @return a new {@link CloseStatus} instance
*/ */
public CloseStatus withReason(String reason) { public CloseStatus withReason(String reason) {
Assert.hasText(reason, "Reason must not be empty"); Assert.hasText(reason, "Reason must not be empty");
return new CloseStatus(this.code, reason); return new CloseStatus(this.code, reason);
} }
@Override
public int hashCode() { public boolean equalsCode(CloseStatus other) {
return this.code * 29 + ObjectUtils.nullSafeHashCode(this.reason); return (this.code == other.code);
} }
@Override @Override
@ -211,8 +208,9 @@ public final class CloseStatus {
return (this.code == otherStatus.code && ObjectUtils.nullSafeEquals(this.reason, otherStatus.reason)); return (this.code == otherStatus.code && ObjectUtils.nullSafeEquals(this.reason, otherStatus.reason));
} }
public boolean equalsCode(CloseStatus other) { @Override
return this.code == other.code; public int hashCode() {
return this.code * 29 + ObjectUtils.nullSafeHashCode(this.reason);
} }
@Override @Override

View File

@ -16,7 +16,6 @@
package org.springframework.web.socket.messaging; package org.springframework.web.socket.messaging;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -53,16 +52,16 @@ public class SessionConnectEvent extends ApplicationEvent {
/** /**
* Create a new SessionConnectEvent. * Create a new SessionConnectEvent.
*
* @param source the component that published the event (never {@code null}) * @param source the component that published the event (never {@code null})
* @param message the connect message * @param message the connect message
*/ */
public SessionConnectEvent(Object source, Message<byte[]> message) { public SessionConnectEvent(Object source, Message<byte[]> message) {
super(source); super(source);
Assert.notNull(message, "'message' must not be null"); Assert.notNull(message, "Message must not be null");
this.message = message; this.message = message;
} }
/** /**
* Return the connect message. * Return the connect message.
*/ */
@ -70,9 +69,9 @@ public class SessionConnectEvent extends ApplicationEvent {
return this.message; return this.message;
} }
@Override @Override
public String toString() { public String toString() {
return "SessionConnectEvent: message=" + message; return "SessionConnectEvent: message=" + this.message;
} }
} }

View File

@ -16,7 +16,6 @@
package org.springframework.web.socket.messaging; package org.springframework.web.socket.messaging;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -35,17 +34,17 @@ public class SessionConnectedEvent extends ApplicationEvent {
/** /**
* Create a new event. * Create a new SessionConnectedEvent.
*
* @param source the component that published the event (never {@code null}) * @param source the component that published the event (never {@code null})
* @param message the connected message * @param message the connected message
*/ */
public SessionConnectedEvent(Object source, Message<byte[]> message) { public SessionConnectedEvent(Object source, Message<byte[]> message) {
super(source); super(source);
Assert.notNull(message, "'message' must not be null"); Assert.notNull(message, "Message must not be null");
this.message = message; this.message = message;
} }
/** /**
* Return the connected message. * Return the connected message.
*/ */
@ -53,9 +52,9 @@ public class SessionConnectedEvent extends ApplicationEvent {
return this.message; return this.message;
} }
@Override @Override
public String toString() { public String toString() {
return "SessionConnectedEvent: message=" + message; return "SessionConnectedEvent: message=" + this.message;
} }
} }

View File

@ -16,9 +16,7 @@
package org.springframework.web.socket.messaging; package org.springframework.web.socket.messaging;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.messaging.Message;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.CloseStatus;
@ -27,7 +25,7 @@ import org.springframework.web.socket.CloseStatus;
* Protocol (e.g. STOMP) as the WebSocket sub-protocol is closed. * Protocol (e.g. STOMP) as the WebSocket sub-protocol is closed.
* *
* <p>Note that this event may be raised more than once for a single session and * <p>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 * @author Rossen Stoyanchev
* @since 4.0.3 * @since 4.0.3
@ -39,12 +37,12 @@ public class SessionDisconnectEvent extends ApplicationEvent {
private final CloseStatus status; private final CloseStatus status;
/** /**
* Create a new event. * Create a new SessionDisconnectEvent.
*
* @param source the component that published the event (never {@code null}) * @param source the component that published the event (never {@code null})
* @param sessionId the disconnect message * @param sessionId the disconnect message
* @param closeStatus * @param closeStatus the status object
*/ */
public SessionDisconnectEvent(Object source, String sessionId, CloseStatus closeStatus) { public SessionDisconnectEvent(Object source, String sessionId, CloseStatus closeStatus) {
super(source); super(source);
@ -53,6 +51,7 @@ public class SessionDisconnectEvent extends ApplicationEvent {
this.status = closeStatus; this.status = closeStatus;
} }
/** /**
* Return the session id. * Return the session id.
*/ */
@ -71,4 +70,5 @@ public class SessionDisconnectEvent extends ApplicationEvent {
public String toString() { public String toString() {
return "SessionDisconnectEvent: sessionId=" + this.sessionId; return "SessionDisconnectEvent: sessionId=" + this.sessionId;
} }
} }