public abstract class WebSocket extends AtmosphereInterceptorWriter implements KeepOpenStreamAware
Modifier and Type | Field and Description |
---|---|
protected ByteBuffer |
bb |
protected boolean |
binaryWrite |
protected CharBuffer |
cb |
static String |
CLEAN_CLOSE |
protected long |
lastWrite |
protected static org.slf4j.Logger |
logger |
static String |
NOT_SUPPORTED |
protected String |
uuid |
static String |
WEBSOCKET_ACCEPT_DONE |
static String |
WEBSOCKET_INITIATED |
static String |
WEBSOCKET_RESUME |
static String |
WEBSOCKET_SUSPEND |
filters, reversedFilters
Constructor and Description |
---|
WebSocket(AtmosphereConfig config) |
Modifier and Type | Method and Description |
---|---|
Object |
attachment()
Return the attachment
|
WebSocket |
attachment(Object attachment)
Attach an object.
|
Map<String,Object> |
attributes()
Return the attribute that was set during the websocket's open operation.
|
WebSocket |
binaryWrite(boolean binaryWrite)
Switch to binary write, or go back to text write.
|
WebSocket |
broadcast(Object o)
Broadcast, using the
AtmosphereResource.getBroadcaster() the object to all
WebSocket associated with the Broadcaster . |
abstract void |
close()
Close the underlying WebSocket
|
void |
close(AtmosphereResponse r)
Close the underlying connection.
|
AtmosphereConfig |
config() |
WebSocket |
flush(AtmosphereResponse r)
Flush the buffered content.
|
abstract boolean |
isOpen()
Is the underlying WebSocket open.
|
long |
lastWriteTimeStampInMilliseconds()
The last time, in milliseconds, a write operation occurred.
|
static void |
notSupported(AtmosphereRequest request,
AtmosphereResponse response) |
WebSocket |
redirect(AtmosphereResponse r,
String location)
Redirect a WebSocket request to another location.
|
AtmosphereResource |
resource()
Return the an
AtmosphereResource used by this WebSocket, or null if the WebSocket has been closed
before the WebSocket message has been processed. |
WebSocket |
resource(AtmosphereResource r)
Associate an
AtmosphereResource to this WebSocket |
WebSocket |
sendPing(byte[] payload)
Send a WebSocket Ping
|
WebSocket |
sendPong(byte[] payload)
Send a WebSocket Pong
|
WebSocket |
shiftAttributes()
Copy
AtmosphereRequestImpl.localAttributes() that where set when the websocket was opened. |
protected byte[] |
transform(AtmosphereResponse response,
byte[] b,
int offset,
int length) |
protected byte[] |
transform(byte[] b,
int offset,
int length) |
String |
uuid() |
WebSocketHandler |
webSocketHandler() |
protected WebSocket |
webSocketHandler(WebSocketHandler webSocketHandler) |
WebSocket |
write(AtmosphereResponse r,
byte[] data)
Write a WebSocket message.
|
WebSocket |
write(AtmosphereResponse r,
byte[] b,
int offset,
int length)
Write a WebSocket message.
|
WebSocket |
write(AtmosphereResponse r,
String data)
Write a WebSocket message.
|
WebSocket |
write(byte[] b)
Use the underlying container's websocket to write the byte.
|
abstract WebSocket |
write(byte[] b,
int offset,
int length)
Use the underlying container's websocket to write the byte.
|
abstract WebSocket |
write(String s)
Use the underlying container's websocket to write the String.
|
WebSocket |
writeError(AtmosphereResponse r,
int errorCode,
String message)
Write an error code.
|
filters, interceptor, interceptor, invokeInterceptor, writeReady
protected static final org.slf4j.Logger logger
public static final String WEBSOCKET_INITIATED
public static final String WEBSOCKET_SUSPEND
public static final String WEBSOCKET_RESUME
public static final String WEBSOCKET_ACCEPT_DONE
public static final String NOT_SUPPORTED
public static final String CLEAN_CLOSE
protected long lastWrite
protected boolean binaryWrite
protected ByteBuffer bb
protected CharBuffer cb
protected String uuid
public WebSocket(AtmosphereConfig config)
public AtmosphereConfig config()
protected WebSocket webSocketHandler(WebSocketHandler webSocketHandler)
public WebSocket binaryWrite(boolean binaryWrite)
binaryWrite
- true to switch to binary write.public WebSocketHandler webSocketHandler()
public WebSocket resource(AtmosphereResource r)
AtmosphereResource
to this WebSocketr
- an AtmosphereResource
to this WebSocketpublic WebSocket shiftAttributes()
AtmosphereRequestImpl.localAttributes()
that where set when the websocket was opened.public Map<String,Object> attributes()
public AtmosphereResource resource()
AtmosphereResource
used by this WebSocket, or null if the WebSocket has been closed
before the WebSocket message has been processed.AtmosphereResource
public long lastWriteTimeStampInMilliseconds()
protected byte[] transform(byte[] b, int offset, int length) throws IOException
IOException
protected byte[] transform(AtmosphereResponse response, byte[] b, int offset, int length) throws IOException
IOException
public WebSocket write(AtmosphereResponse r, String data) throws IOException
AsyncIOWriter
write
in interface AsyncIOWriter
write
in class AtmosphereInterceptorWriter
data
- the WebSocket messageIOException
public WebSocket write(AtmosphereResponse r, byte[] data) throws IOException
AsyncIOWriter
write
in interface AsyncIOWriter
write
in class AtmosphereInterceptorWriter
data
- the WebSocket messageIOException
public WebSocket write(AtmosphereResponse r, byte[] b, int offset, int length) throws IOException
AsyncIOWriter
write
in interface AsyncIOWriter
write
in class AtmosphereInterceptorWriter
b
- the WebSocket messageoffset
- offset of the messagelength
- length of the messageIOException
public WebSocket broadcast(Object o)
AtmosphereResource.getBroadcaster()
the object to all
WebSocket
associated with the Broadcaster
. This method does the same as
websocket.resource().getBroadcaster().broadcast(o).o
- An object to broadcast to all WebSockets.public WebSocket writeError(AtmosphereResponse r, int errorCode, String message) throws IOException
AsyncIOWriter
writeError
in interface AsyncIOWriter
writeError
in class AtmosphereInterceptorWriter
errorCode
- the error codeIOException
public WebSocket redirect(AtmosphereResponse r, String location) throws IOException
AsyncIOWriter
redirect
in interface AsyncIOWriter
redirect
in class AtmosphereInterceptorWriter
IOException
public void close(AtmosphereResponse r) throws IOException
AsyncIOWriter
close
in interface AsyncIOWriter
close
in class AtmosphereInterceptorWriter
IOException
public WebSocket flush(AtmosphereResponse r) throws IOException
AsyncIOWriter
flush
in interface AsyncIOWriter
flush
in class AtmosphereInterceptorWriter
IOException
public abstract boolean isOpen()
public abstract WebSocket write(String s) throws IOException
s
- a websocket String messageIOException
public abstract WebSocket write(byte[] b, int offset, int length) throws IOException
b
- a websocket byte messageoffset
- startlength
- endIOException
public WebSocket write(byte[] b) throws IOException
b
- a websocket byte messageIOException
public abstract void close()
public String uuid()
public static void notSupported(AtmosphereRequest request, AtmosphereResponse response) throws IOException
IOException
public WebSocket sendPing(byte[] payload)
payload
- the bytes to sendpublic WebSocket sendPong(byte[] payload)
payload
- the bytes to sendpublic WebSocket attachment(Object attachment)
public Object attachment()
Copyright © 2016. All rights reserved.