Package org.atmosphere.websocket
Class WebSocket
java.lang.Object
org.atmosphere.cpr.AsyncIOWriterAdapter
org.atmosphere.cpr.AtmosphereInterceptorWriter
org.atmosphere.websocket.WebSocket
- All Implemented Interfaces:
AsyncIOWriter,KeepOpenStreamAware
- Direct Known Subclasses:
Grizzly2WebSocket,GrizzlyWebSocket,JBossWebSocket,Jetty8WebSocket,Jetty9WebSocket,JSR356WebSocket,TomcatWebSocket,WebLogicWebSocket
Represent a portable WebSocket implementation which can be used to write message.
- Author:
- Jeanfrancois Arcand
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ByteBufferprotected booleanprotected CharBufferstatic final Stringprotected longprotected static final org.slf4j.Loggerstatic final Stringprotected Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class org.atmosphere.cpr.AtmosphereInterceptorWriter
filters, reversedFilters -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturn the attachmentattachment(Object attachment) Attach an object.Return the attribute that was set during the websocket's open operation.binaryWrite(boolean binaryWrite) Switch to binary write, or go back to text write.Broadcast, using theAtmosphereResource.getBroadcaster()the object to allWebSocketassociated with theBroadcaster.abstract voidclose()Close the underlying WebSocketvoidAllow the underlying WebSocket to close with a code and a reason.voidClose the underlying connection.config()Flush the buffered content.abstract booleanisOpen()Is the underlying WebSocket open.longThe last time, in milliseconds, a write operation occurred.static voidnotSupported(AtmosphereRequest request, AtmosphereResponse response) redirect(AtmosphereResponse r, String location) Redirect a WebSocket request to another location.resource()Return the anAtmosphereResourceused by this WebSocket, or null if the WebSocket has been closed before the WebSocket message has been processed.Associate anAtmosphereResourceto this WebSocketsendPing(byte[] payload) Send a WebSocket PingsendPong(byte[] payload) Send a WebSocket PongvoidCopyAtmosphereRequestImpl.localAttributes()that where set when the websocket was opened.protected byte[]transform(byte[] b, int offset, int length) protected byte[]transform(AtmosphereResponse response, byte[] b, int offset, int length) uuid()protected WebSocketwebSocketHandler(WebSocketHandler webSocketHandler) write(byte[] b) Use the underlying container's websocket to write the byte.abstract WebSocketwrite(byte[] b, int offset, int length) Use the underlying container's websocket to write the byte.abstract WebSocketUse the underlying container's websocket to write the String.write(AtmosphereResponse r, byte[] data) Write a WebSocket message.write(AtmosphereResponse r, byte[] b, int offset, int length) Write a WebSocket message.write(AtmosphereResponse r, String data) Write a WebSocket message.writeError(AtmosphereResponse r, int errorCode, String message) Write an error code.Methods inherited from class org.atmosphere.cpr.AtmosphereInterceptorWriter
filters, interceptor, interceptor, invokeInterceptor, writeReady
-
Field Details
-
logger
protected static final org.slf4j.Logger logger -
WEBSOCKET_INITIATED
-
WEBSOCKET_SUSPEND
-
WEBSOCKET_RESUME
-
WEBSOCKET_ACCEPT_DONE
-
NOT_SUPPORTED
- See Also:
-
CLEAN_CLOSE
- See Also:
-
lastWrite
protected long lastWrite -
binaryWrite
protected boolean binaryWrite -
bb
-
cb
-
uuid
-
-
Constructor Details
-
WebSocket
-
-
Method Details
-
config
-
webSocketHandler
-
binaryWrite
Switch to binary write, or go back to text write. Default is false.- Parameters:
binaryWrite- true to switch to binary write.- Returns:
- WebSocket
-
webSocketHandler
-
resource
Associate anAtmosphereResourceto this WebSocket- Parameters:
r- anAtmosphereResourceto this WebSocket- Returns:
- this
-
shiftAttributes
public void shiftAttributes()CopyAtmosphereRequestImpl.localAttributes()that where set when the websocket was opened. -
attributes
Return the attribute that was set during the websocket's open operation.- Returns:
- Map
-
resource
Return the anAtmosphereResourceused by this WebSocket, or null if the WebSocket has been closed before the WebSocket message has been processed.- Returns:
AtmosphereResource
-
lastWriteTimeStampInMilliseconds
public long lastWriteTimeStampInMilliseconds()The last time, in milliseconds, a write operation occurred.- Returns:
- this
-
transform
- Throws:
IOException
-
transform
protected byte[] transform(AtmosphereResponse response, byte[] b, int offset, int length) throws IOException - Throws:
IOException
-
write
Description copied from interface:AsyncIOWriterWrite a WebSocket message.- Specified by:
writein interfaceAsyncIOWriter- Overrides:
writein classAtmosphereInterceptorWriter- Parameters:
data- the WebSocket message- Throws:
IOException
-
write
Description copied from interface:AsyncIOWriterWrite a WebSocket message.- Specified by:
writein interfaceAsyncIOWriter- Overrides:
writein classAtmosphereInterceptorWriter- Parameters:
data- the WebSocket message- Throws:
IOException
-
write
Description copied from interface:AsyncIOWriterWrite a WebSocket message.- Specified by:
writein interfaceAsyncIOWriter- Overrides:
writein classAtmosphereInterceptorWriter- Parameters:
b- the WebSocket messageoffset- offset of the messagelength- length of the message- Throws:
IOException
-
broadcast
Broadcast, using theAtmosphereResource.getBroadcaster()the object to allWebSocketassociated with theBroadcaster. This method does the same as websocket.resource().getBroadcaster().broadcast(o).- Parameters:
o- An object to broadcast to all WebSockets.
-
writeError
Description copied from interface:AsyncIOWriterWrite an error code.- Specified by:
writeErrorin interfaceAsyncIOWriter- Overrides:
writeErrorin classAtmosphereInterceptorWriter- Parameters:
errorCode- the error codemessage-- Throws:
IOException
-
redirect
Description copied from interface:AsyncIOWriterRedirect a WebSocket request to another location.- Specified by:
redirectin interfaceAsyncIOWriter- Overrides:
redirectin classAtmosphereInterceptorWriter- Parameters:
location-- Throws:
IOException
-
close
Description copied from interface:AsyncIOWriterClose the underlying connection.- Specified by:
closein interfaceAsyncIOWriter- Overrides:
closein classAtmosphereInterceptorWriter- Throws:
IOException
-
flush
Description copied from interface:AsyncIOWriterFlush the buffered content.- Specified by:
flushin interfaceAsyncIOWriter- Overrides:
flushin classAtmosphereInterceptorWriter- Throws:
IOException
-
isOpen
public abstract boolean isOpen()Is the underlying WebSocket open.- Returns:
- true is opened
-
write
Use the underlying container's websocket to write the String.- Parameters:
s- a websocket String message- Returns:
- this
- Throws:
IOException
-
write
Use the underlying container's websocket to write the byte.- Parameters:
b- a websocket byte messageoffset- startlength- end- Returns:
- this
- Throws:
IOException
-
write
Use the underlying container's websocket to write the byte.- Parameters:
b- a websocket byte message- Returns:
- WebSocket
- Throws:
IOException
-
close
public abstract void close()Close the underlying WebSocket -
close
Allow the underlying WebSocket to close with a code and a reason. -
uuid
-
notSupported
public static void notSupported(AtmosphereRequest request, AtmosphereResponse response) throws IOException - Throws:
IOException
-
sendPing
Send a WebSocket Ping- Parameters:
payload- the bytes to send- Returns:
- this
-
sendPong
Send a WebSocket Pong- Parameters:
payload- the bytes to send- Returns:
- this
-
attachment
Attach an object. Be careful when attaching an object as it can cause memory leak -
attachment
Return the attachment
-