Polish SockJsFrame
This commit is contained in:
parent
b6255128bf
commit
c86f711de5
|
|
@ -21,7 +21,8 @@ import java.nio.charset.Charset;
|
|||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Represents a SockJS frame and provides factory methods for creating SockJS frames.
|
||||
* Represents a SockJS frame. Provides factory methods to create SockJS frames on
|
||||
* the server side.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
|
|
@ -30,39 +31,13 @@ public class SockJsFrame {
|
|||
|
||||
private static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
|
||||
|
||||
private static final SockJsFrame openFrame = new SockJsFrame("o");
|
||||
private static final SockJsFrame OPEN_FRAME = new SockJsFrame("o");
|
||||
|
||||
private static final SockJsFrame heartbeatFrame = new SockJsFrame("h");
|
||||
private static final SockJsFrame HEARTBEAT_FRAME = new SockJsFrame("h");
|
||||
|
||||
private static final SockJsFrame closeGoAwayFrame = closeFrame(3000, "Go away!");
|
||||
private static final SockJsFrame CLOSE_GO_AWAY_FRAME = closeFrame(3000, "Go away!");
|
||||
|
||||
private static final SockJsFrame closeAnotherConnectionOpenFrame = closeFrame(2010, "Another connection still open");
|
||||
|
||||
|
||||
public static SockJsFrame openFrame() {
|
||||
return openFrame;
|
||||
}
|
||||
|
||||
public static SockJsFrame heartbeatFrame() {
|
||||
return heartbeatFrame;
|
||||
}
|
||||
|
||||
public static SockJsFrame messageFrame(SockJsMessageCodec codec, String... messages) {
|
||||
String encoded = codec.encode(messages);
|
||||
return new SockJsFrame(encoded);
|
||||
}
|
||||
|
||||
public static SockJsFrame closeFrameGoAway() {
|
||||
return closeGoAwayFrame;
|
||||
}
|
||||
|
||||
public static SockJsFrame closeFrameAnotherConnectionOpen() {
|
||||
return closeAnotherConnectionOpenFrame;
|
||||
}
|
||||
|
||||
public static SockJsFrame closeFrame(int code, String reason) {
|
||||
return new SockJsFrame("c[" + code + ",\"" + reason + "\"]");
|
||||
}
|
||||
private static final SockJsFrame CLOSE_ANOTHER_CONNECTION_OPEN_FRAME = closeFrame(2010, "Another connection still open");
|
||||
|
||||
|
||||
private final String content;
|
||||
|
|
@ -73,6 +48,31 @@ public class SockJsFrame {
|
|||
this.content = content;
|
||||
}
|
||||
|
||||
public static SockJsFrame openFrame() {
|
||||
return OPEN_FRAME;
|
||||
}
|
||||
|
||||
public static SockJsFrame heartbeatFrame() {
|
||||
return HEARTBEAT_FRAME;
|
||||
}
|
||||
|
||||
public static SockJsFrame messageFrame(SockJsMessageCodec codec, String... messages) {
|
||||
String encoded = codec.encode(messages);
|
||||
return new SockJsFrame(encoded);
|
||||
}
|
||||
|
||||
public static SockJsFrame closeFrameGoAway() {
|
||||
return CLOSE_GO_AWAY_FRAME;
|
||||
}
|
||||
|
||||
public static SockJsFrame closeFrameAnotherConnectionOpen() {
|
||||
return CLOSE_ANOTHER_CONNECTION_OPEN_FRAME;
|
||||
}
|
||||
|
||||
public static SockJsFrame closeFrame(int code, String reason) {
|
||||
return new SockJsFrame("c[" + code + ",\"" + reason + "\"]");
|
||||
}
|
||||
|
||||
|
||||
public String getContent() {
|
||||
return this.content;
|
||||
|
|
@ -82,6 +82,7 @@ public class SockJsFrame {
|
|||
return this.content.getBytes(UTF8_CHARSET);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue