|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.glassfish.grizzly.websockets.DefaultWebSocket
public class DefaultWebSocket
| Field Summary | |
|---|---|
protected ProtocolHandler |
protocolHandler
|
protected HttpRequestPacket |
request
|
| Fields inherited from interface org.glassfish.grizzly.websockets.WebSocket |
|---|
ABNORMAL_CLOSE, END_POINT_GOING_DOWN, INVALID_DATA, MESSAGE_TOO_LARGE, NO_STATUS_CODE, NORMAL_CLOSURE, PROTOCOL_ERROR |
| Constructor Summary | |
|---|---|
DefaultWebSocket(ProtocolHandler protocolHandler,
HttpRequestPacket request,
WebSocketListener... listeners)
|
|
DefaultWebSocket(ProtocolHandler protocolHandler,
WebSocketListener... listeners)
|
|
| Method Summary | |
|---|---|
boolean |
add(WebSocketListener listener)
Adds a WebSocketListener to be notified of events of interest. |
void |
close()
Closes this WebSocket. |
void |
close(int code)
Closes this WebSocket using the specified status code. |
void |
close(int code,
String reason)
Closes this WebSocket using the specified status code and
reason. |
Collection<WebSocketListener> |
getListeners()
|
HttpRequestPacket |
getUpgradeRequest()
Returns the upgrade request for this WebSocket. |
boolean |
isConnected()
Convenience method to determine if this WebSocket is connected. |
void |
onClose(DataFrame frame)
This callback will be invoked when the remote end-point sent a closing frame. |
void |
onConnect()
This callback will be invoked when the opening handshake between both endpoints has been completed. |
void |
onFragment(boolean last,
byte[] fragment)
This callback will be invoked when a fragmented binary message has been received. |
void |
onFragment(boolean last,
String fragment)
This callback will be invoked when a fragmented textual message has been received. |
void |
onMessage(byte[] data)
This callback will be invoked when a binary message has been received. |
void |
onMessage(String text)
This callback will be invoked when a text message has been received. |
void |
onPing(DataFrame frame)
This callback will be invoked when the remote end-point has sent a ping frame. |
void |
onPong(DataFrame frame)
This callback will be invoked when the remote end-point has sent a pong frame. |
boolean |
remove(WebSocketListener listener)
Removes the specified WebSocketListener as a target of event
notification. |
GrizzlyFuture<DataFrame> |
send(byte[] data)
Send a binary frame to the remote end-point. |
GrizzlyFuture<DataFrame> |
send(String data)
Send a text frame to the remote end-point. |
GrizzlyFuture<DataFrame> |
sendPing(byte[] data)
Sends a ping frame with the specified payload (if any). |
GrizzlyFuture<DataFrame> |
sendPong(byte[] data)
Sends a ping frame with the specified payload (if any). |
void |
setClosed()
|
GrizzlyFuture<DataFrame> |
stream(boolean last,
byte[] bytes,
int off,
int len)
Sends a fragment of a complete message. |
GrizzlyFuture<DataFrame> |
stream(boolean last,
String fragment)
Sends a fragment of a complete message. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final ProtocolHandler protocolHandler
protected final HttpRequestPacket request
| Constructor Detail |
|---|
public DefaultWebSocket(ProtocolHandler protocolHandler,
WebSocketListener... listeners)
public DefaultWebSocket(ProtocolHandler protocolHandler,
HttpRequestPacket request,
WebSocketListener... listeners)
| Method Detail |
|---|
public HttpRequestPacket getUpgradeRequest()
WebSocket. This method
may return null depending on the context under which this
WebSocket was created.public Collection<WebSocketListener> getListeners()
public final boolean add(WebSocketListener listener)
WebSocketWebSocketListener to be notified of events of interest.
add in interface WebSocketlistener - the WebSocketListener to add.
true if the listener was added, otherwise
falseWebSocketListenerpublic final boolean remove(WebSocketListener listener)
WebSocketWebSocketListener as a target of event
notification.
remove in interface WebSocketlistener - the WebSocketListener to remote.
true if the listener was removed, otherwise
falseWebSocketListenerpublic boolean isConnected()
WebSocket
Convenience method to determine if this WebSocket is connected.
isConnected in interface WebSockettrue if the WebSocket is connected, otherwise
falsepublic void setClosed()
public void onClose(DataFrame frame)
WebSocketThis callback will be invoked when the remote end-point sent a closing frame.
onClose in interface WebSocketframe - the close frame from the remote end-point.DataFramepublic void onConnect()
WebSocketThis callback will be invoked when the opening handshake between both endpoints has been completed.
onConnect in interface WebSocket
public void onFragment(boolean last,
byte[] fragment)
WebSocketThis callback will be invoked when a fragmented binary message has been received.
onFragment in interface WebSocketlast - flag indicating whether or not the payload received is the
final fragment of a message.fragment - the binary data received from the remote end-point.
public void onFragment(boolean last,
String fragment)
WebSocketThis callback will be invoked when a fragmented textual message has been received.
onFragment in interface WebSocketlast - flag indicating whether or not the payload received is the
final fragment of a message.fragment - the text received from the remote end-point.public void onMessage(byte[] data)
WebSocketThis callback will be invoked when a binary message has been received.
onMessage in interface WebSocketdata - the binary data received from the remote end-point.public void onMessage(String text)
WebSocketThis callback will be invoked when a text message has been received.
onMessage in interface WebSockettext - the text received from the remote end-point.public void onPing(DataFrame frame)
WebSocketThis callback will be invoked when the remote end-point has sent a ping frame.
onPing in interface WebSocketframe - the ping frame from the remote end-point.DataFramepublic void onPong(DataFrame frame)
WebSocketThis callback will be invoked when the remote end-point has sent a pong frame.
onPong in interface WebSocketframe - the pong frame from the remote end-point.DataFramepublic void close()
WebSocket
Closes this WebSocket.
close in interface WebSocketpublic void close(int code)
WebSocket
Closes this WebSocket using the specified status code.
close in interface WebSocketcode - the closing status code.
public void close(int code,
String reason)
WebSocket
Closes this WebSocket using the specified status code and
reason.
close in interface WebSocketcode - the closing status code.reason - the reason, if any.public GrizzlyFuture<DataFrame> send(byte[] data)
WebSocketSend a binary frame to the remote end-point.
send in interface WebSocketGrizzlyFuture which could be used to control/check the sending completion state.public GrizzlyFuture<DataFrame> send(String data)
WebSocketSend a text frame to the remote end-point.
send in interface WebSocketGrizzlyFuture which could be used to control/check the sending completion state.public GrizzlyFuture<DataFrame> sendPing(byte[] data)
Sends a ping frame with the specified payload (if any).
sendPing in interface WebSocketdata - optional payload. Note that payload length is restricted
to 125 bytes or less.
GrizzlyFuture which could be used to control/check the sending completion state.public GrizzlyFuture<DataFrame> sendPong(byte[] data)
Sends a ping frame with the specified payload (if any).
It may seem odd to send a pong frame, however, RFC-6455 states:
"A Pong frame MAY be sent unsolicited. This serves as a unidirectional heartbeat. A response to an unsolicited Pong frame is not expected."
sendPong in interface WebSocketdata - optional payload. Note that payload length is restricted
to 125 bytes or less.
GrizzlyFuture which could be used to control/check the sending completion state.
public GrizzlyFuture<DataFrame> stream(boolean last,
String fragment)
WebSocketSends a fragment of a complete message.
stream in interface WebSocketlast - boolean indicating if this message fragment is the last.fragment - the textual fragment to send.
GrizzlyFuture which could be used to control/check the sending completion state.
public GrizzlyFuture<DataFrame> stream(boolean last,
byte[] bytes,
int off,
int len)
WebSocketSends a fragment of a complete message.
stream in interface WebSocketlast - boolean indicating if this message fragment is the last.bytes - the binary fragment to send.off - the offset within the fragment to send.len - the number of bytes of the fragment to send.
GrizzlyFuture which could be used to control/check the sending completion state.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||