public class WSConnectionImpl extends javax.websocket.Endpoint implements WSConnection
| Constructor and Description |
|---|
WSConnectionImpl() |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close this connection with 1000 status which indicates a normal closure.
|
void |
close(int status,
String message)
Close this connection with specified status and message.
|
Object |
getAttribute(String name)
Returns the object bound with the specified name in this connection, or
null if no object is bound under the name. |
Collection<String> |
getChannels()
Get optional set of channels assigned for this connection.
|
int |
getCloseStatus()
Get connection close status.
|
javax.servlet.http.HttpSession |
getHttpSession()
Get HTTP session associated to this connection.
|
Long |
getId()
Get unique connection identifier.
|
javax.websocket.Session |
getWsSession() |
boolean |
isConnected()
Check connection state.
|
void |
onClose(javax.websocket.Session session,
javax.websocket.CloseReason closeReason) |
void |
onError(javax.websocket.Session session,
Throwable thr) |
void |
onOpen(javax.websocket.Session session,
javax.websocket.EndpointConfig config) |
void |
registerMessageReceiver(WSMessageReceiver messageReceiver)
Register new WSMessageReceiver for this connection.
|
void |
removeAttribute(String name)
Removes the object bound with the specified name from this connection.
|
void |
removeMessageReceiver(WSMessageReceiver messageReceiver)
Unregister WSMessageReceiver.
|
void |
sendMessage(OutputMessage output)
Send message to client.
|
void |
setAttribute(String name,
Object value)
Binds an object to this connection, using the name specified.
|
boolean |
subscribeToChannel(String channel)
Subscribe this connection to specified channel.
|
String |
toString() |
boolean |
unsubscribeFromChannel(String channel)
Unsubscribe this connection from specified channel.
|
public void onOpen(javax.websocket.Session session,
javax.websocket.EndpointConfig config)
onOpen in class javax.websocket.Endpointpublic void onClose(javax.websocket.Session session,
javax.websocket.CloseReason closeReason)
onClose in class javax.websocket.Endpointpublic void onError(javax.websocket.Session session,
Throwable thr)
onError in class javax.websocket.Endpointpublic Long getId()
WSConnectiongetId in interface WSConnectionpublic javax.servlet.http.HttpSession getHttpSession()
WSConnectiongetHttpSession in interface WSConnectionpublic javax.websocket.Session getWsSession()
getWsSession in interface WSConnectionpublic boolean subscribeToChannel(String channel)
WSConnectionsubscribeToChannel in interface WSConnectionchannel - channel nametrue if this connection is subscribed to channel successfully and false if
connection already subscribed to specified channelWSConnectionContext.sendMessage(org.everrest.websockets.message.ChannelBroadcastMessage)public boolean unsubscribeFromChannel(String channel)
WSConnectionunsubscribeFromChannel in interface WSConnectionchannel - channel nametrue if this connection is unsubscribed from channel successfully and false if
connection is not subscribed to specified channelWSConnectionContext.sendMessage(org.everrest.websockets.message.ChannelBroadcastMessage)public Collection<String> getChannels()
WSConnectiongetChannels in interface WSConnectionWSConnectionContext.sendMessage(org.everrest.websockets.message.ChannelBroadcastMessage)public boolean isConnected()
WSConnectionisConnected in interface WSConnectiontrue if connection is alive and false if connection already closed.public void close()
throws IOException
WSConnectionclose in interface WSConnectionIOException - if any i/o error occurspublic void close(int status,
String message)
throws IOException
WSConnectionclose in interface WSConnectionstatus - connection close statusmessage - optional messageIOException - if any i/o error occurspublic int getCloseStatus()
WSConnection0.getCloseStatus in interface WSConnection0 if connection is alive or not opened yetpublic void sendMessage(OutputMessage output) throws javax.websocket.EncodeException, IOException
WSConnectionsendMessage in interface WSConnectionoutput - output messagejavax.websocket.EncodeException - if message cannot be serializedIOException - if any i/o error occurs when try to send message to clientpublic void registerMessageReceiver(WSMessageReceiver messageReceiver)
WSConnectionregisterMessageReceiver in interface WSConnectionmessageReceiver - message receiverpublic void removeMessageReceiver(WSMessageReceiver messageReceiver)
WSConnectionremoveMessageReceiver in interface WSConnectionmessageReceiver - message receiverpublic Object getAttribute(String name)
WSConnectionnull if no object is bound under the name.getAttribute in interface WSConnectionname - a string specifying the name of the objectpublic void setAttribute(String name, Object value)
WSConnectionsetAttribute in interface WSConnectionname - the name to which the object is bound; cannot be nullvalue - the object to be boundpublic void removeAttribute(String name)
WSConnectionremoveAttribute in interface WSConnectionname - the name of the object to remove from this connectionCopyright © 2012–2016 Codenvy, S.A.. All rights reserved.