public class WebSocketContext extends ActContext.Base<WebSocketContext> implements WebSocketConnection
Destroyable.Util
ActContext.Base<CTX extends ActContext.Base>, ActContext.Listener
logger
ATTR_CUR_METHOD
Constructor and Description |
---|
WebSocketContext(java.lang.String url,
WebSocketConnection connection,
WebSocketConnectionManager manager,
ActionContext actionContext,
App app) |
Modifier and Type | Method and Description |
---|---|
org.osgl.http.H.Format |
accept() |
WebSocketContext |
accept(org.osgl.http.H.Format fmt) |
ActionContext |
actionContext() |
void |
close()
Close the connection.
|
boolean |
closed()
Check if the connection has been closed
|
WebSocketConnection |
connection() |
static WebSocketContext |
current() |
static void |
current(WebSocketContext ctx) |
boolean |
isJson() |
WebSocketConnectionManager |
manager() |
WebSocketContext |
messageReceived(java.lang.String receivedMessage)
Called when remote end send a message to this connection
|
java.lang.String |
methodPath() |
java.util.Set<java.lang.String> |
paramKeys() |
java.lang.String |
paramVal(java.lang.String key) |
java.lang.String[] |
paramVals(java.lang.String key) |
void |
send(java.lang.String message)
Send a text message through websocket
|
WebSocketContext |
sendJsonToPeers(java.lang.Object data)
Send JSON representation of a data object to all connections connected to the same URL of this context with the connection of this context excluded
|
WebSocketContext |
sendJsonToPeers(java.lang.Object data,
boolean excludeSelf)
Send JSON representation of a data object to all connections connected to the same URL of this context with the connection of this context excluded
|
WebSocketContext |
sendJsonToSelf(java.lang.Object data)
Send JSON representation of a data object to the connection of this context
|
WebSocketContext |
sendJsonToTagged(java.lang.Object data,
java.lang.String tag)
Send JSON representation of a data object to all connections connected to the same URL of this context with the connection of this context excluded
|
WebSocketContext |
sendJsonToTagged(java.lang.Object data,
java.lang.String tag,
boolean excludeSelf)
Send JSON representation of a data object to all connections connected to the same URL of this context with the connection of this context excluded
|
WebSocketContext |
sendJsonToUser(java.lang.Object data,
java.lang.String username)
Send JSON representation of a data object to all connections of a certain user
|
WebSocketContext |
sendToPeers(java.lang.String message)
Send message to all connections connected to the same URL of this context with the connection of this context excluded
|
WebSocketContext |
sendToPeers(java.lang.String message,
boolean excludeSelf)
Send message to all connections connected to the same URL of this context
|
WebSocketContext |
sendToSelf(java.lang.String message)
Send a message to the connection of this context
|
WebSocketContext |
sendToTagged(java.lang.String message,
java.lang.String tag)
Send message to all connections labeled with tag specified with self connection excluded
|
WebSocketContext |
sendToTagged(java.lang.String message,
java.lang.String tag,
boolean excludeSelf)
Send message to all connections labeled with tag specified.
|
WebSocketContext |
sendToUser(java.lang.String message,
java.lang.String username)
Send message to all connections of a certain user
|
java.lang.String |
sessionId()
Default session id is
null |
java.lang.String |
stringMessage() |
WebSocketContext |
tag(java.lang.String label)
Tag the websocket connection hold by this context with label specified
|
java.lang.String |
url() |
java.lang.String |
username()
Returns the username which is gained when connection is setup by calling
H.KV.get(String) with AppConfig.sessionKeyUsername() |
_act_i18n, addDestroyable, addListener, addViolation, addViolations, app, attribute, attribute, attributes, cachedTemplate, cacheTemplate, config, currentContext, currentContextType, dataPattern, disableTemplateCaching, fieldOutputVarCount, fieldOutputVarCount, handlerMethod, handlerMethod, hasRenderArgs, hasViolation, i18n, i18n, i18n, i18n, i18n, i18n, i18n, i18n, i18n, i18n, locale, locale, locale, me, pattern, pattern, progress, releaseResources, removeAttribute, renderArg, renderArg, renderArgs, setJobId, strBuf, templateContent, templateContent, templateContext, templateContext, templateLiteral, templatePath, templatePath, templatePathIsImplicit, violation, violations
addSubResource, destroy, isDestroyed, reload, scope
debug, debug, error, error, fatal, fatal, info, info, isDebugEnabled, isTraceEnabled, trace, trace, warn, warn
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
destroy, isDestroyed, scope
public WebSocketContext(java.lang.String url, WebSocketConnection connection, WebSocketConnectionManager manager, ActionContext actionContext, App app)
public java.lang.String url()
public java.lang.String sessionId()
ActContext.Base
Default session id is null
sessionId
in interface ActContext<WebSocketContext>
sessionId
in interface WebSocketConnection
sessionId
in class ActContext.Base<WebSocketContext>
public java.lang.String username()
WebSocketConnection
Returns the username which is gained when connection is setup by calling H.KV.get(String)
with AppConfig.sessionKeyUsername()
username
in interface WebSocketConnection
null
if there is no logged in user when connection is setuppublic WebSocketConnectionManager manager()
public WebSocketConnection connection()
public ActionContext actionContext()
public WebSocketContext messageReceived(java.lang.String receivedMessage)
Called when remote end send a message to this connection
receivedMessage
- the message receivedpublic WebSocketContext tag(java.lang.String label)
Tag the websocket connection hold by this context with label specified
label
- the label used to tag the websocket connectionpublic java.lang.String stringMessage()
public boolean isJson()
public WebSocketContext sendToSelf(java.lang.String message)
Send a message to the connection of this context
message
- the message to be sentpublic WebSocketContext sendJsonToSelf(java.lang.Object data)
Send JSON representation of a data object to the connection of this context
data
- the data to be sentpublic WebSocketContext sendToPeers(java.lang.String message)
Send message to all connections connected to the same URL of this context with the connection of this context excluded
message
- the message to be sentpublic WebSocketContext sendToPeers(java.lang.String message, boolean excludeSelf)
Send message to all connections connected to the same URL of this context
message
- the message to be sentexcludeSelf
- whether the connection of this context should be sent topublic WebSocketContext sendJsonToPeers(java.lang.Object data)
Send JSON representation of a data object to all connections connected to the same URL of this context with the connection of this context excluded
data
- the data to be sentpublic WebSocketContext sendJsonToPeers(java.lang.Object data, boolean excludeSelf)
Send JSON representation of a data object to all connections connected to the same URL of this context with the connection of this context excluded
data
- the data to be sentexcludeSelf
- whether it should send to the connection of this contextpublic WebSocketContext sendToTagged(java.lang.String message, java.lang.String tag)
Send message to all connections labeled with tag specified with self connection excluded
message
- the message to be senttag
- the string that tag the connections to be sentpublic WebSocketContext sendToTagged(java.lang.String message, java.lang.String tag, boolean excludeSelf)
Send message to all connections labeled with tag specified.
message
- the message to be senttag
- the string that tag the connections to be sentexcludeSelf
- specify whether the connection of this context should be sendpublic WebSocketContext sendJsonToTagged(java.lang.Object data, java.lang.String tag)
Send JSON representation of a data object to all connections connected to the same URL of this context with the connection of this context excluded
data
- the data to be senttag
- the tag labelpublic WebSocketContext sendJsonToTagged(java.lang.Object data, java.lang.String tag, boolean excludeSelf)
Send JSON representation of a data object to all connections connected to the same URL of this context with the connection of this context excluded
data
- the data to be senttag
- the tag labelexcludeSelf
- whether it should send to the connection of this contextpublic WebSocketContext sendToUser(java.lang.String message, java.lang.String username)
Send message to all connections of a certain user
message
- the message to be sentusername
- the usernamepublic WebSocketContext sendJsonToUser(java.lang.Object data, java.lang.String username)
Send JSON representation of a data object to all connections of a certain user
data
- the data to be sentusername
- the usernamepublic void send(java.lang.String message)
WebSocketConnection
Send a text message through websocket
send
in interface WebSocketConnection
message
- the text messagepublic void close()
WebSocketConnection
Close the connection. Note if there are any IOException
raised by the underline network layer, it will be ignored
close
in interface WebSocketConnection
public boolean closed()
WebSocketConnection
Check if the connection has been closed
closed
in interface WebSocketConnection
true
if connection is closedpublic WebSocketContext accept(org.osgl.http.H.Format fmt)
accept
in interface ActContext<WebSocketContext>
public org.osgl.http.H.Format accept()
accept
in interface ActContext<WebSocketContext>
public java.lang.String methodPath()
methodPath
in interface ActContext<WebSocketContext>
public java.util.Set<java.lang.String> paramKeys()
paramKeys
in interface org.osgl.mvc.util.ParamValueProvider
public java.lang.String paramVal(java.lang.String key)
paramVal
in interface org.osgl.mvc.util.ParamValueProvider
public java.lang.String[] paramVals(java.lang.String key)
paramVals
in interface org.osgl.mvc.util.ParamValueProvider
public static WebSocketContext current()
public static void current(WebSocketContext ctx)
Copyright © 2014–2017 ActFramework. All rights reserved.