org.atmosphere.websocket
Class WebSocket

java.lang.Object
  extended by org.atmosphere.cpr.AsyncIOWriterAdapter
      extended by org.atmosphere.cpr.AtmosphereInterceptorWriter
          extended by org.atmosphere.websocket.WebSocket
All Implemented Interfaces:
AsyncIOWriter
Direct Known Subclasses:
Grizzly2WebSocket, GrizzlyWebSocket, Jetty8WebSocket, Jetty9WebSocket, TomcatWebSocket

public abstract class WebSocket
extends AtmosphereInterceptorWriter

Represent a portable WebSocket implementation which can be used to write message.

Author:
Jeanfrancois Arcand

Field Summary
protected  boolean binaryWrite
           
protected  long lastWrite
           
protected static org.slf4j.Logger logger
           
static String WEBSOCKET_ACCEPT_DONE
           
static String WEBSOCKET_INITIATED
           
static String WEBSOCKET_RESUME
           
static String WEBSOCKET_SUSPEND
           
 
Fields inherited from class org.atmosphere.cpr.AtmosphereInterceptorWriter
filters
 
Constructor Summary
WebSocket(AtmosphereConfig config)
           
 
Method Summary
abstract  void close()
           
 void close(AtmosphereResponse r)
          No OPS
 AtmosphereConfig config()
           
 WebSocket flush(AtmosphereResponse r)
          No OPS
abstract  boolean isOpen()
          Is the underlying WebSocket open.
 long lastWriteTimeStampInMilliseconds()
          The last time, in milliseconds, a write operation occurred.
 WebSocket redirect(AtmosphereResponse r, String location)
          No OPS
 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
protected  byte[] transform(byte[] b, int offset, int length)
           
protected  WebSocketHandler webSocketHandler()
           
protected  WebSocket webSocketHandler(WebSocketHandler webSocketHandler)
           
 WebSocket write(AtmosphereResponse r, byte[] data)
          No OPS
 WebSocket write(AtmosphereResponse r, byte[] b, int offset, int length)
          No OPS
 WebSocket write(AtmosphereResponse r, String data)
          No OPS
abstract  WebSocket write(byte[] b, int offset, int length)
           
abstract  WebSocket write(String s)
           
 WebSocket writeError(AtmosphereResponse r, int errorCode, String message)
          No OPS
 
Methods inherited from class org.atmosphere.cpr.AtmosphereInterceptorWriter
interceptor, invokeInterceptor, writeReady
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.slf4j.Logger logger

WEBSOCKET_INITIATED

public static final String WEBSOCKET_INITIATED

WEBSOCKET_SUSPEND

public static final String WEBSOCKET_SUSPEND

WEBSOCKET_RESUME

public static final String WEBSOCKET_RESUME

WEBSOCKET_ACCEPT_DONE

public static final String WEBSOCKET_ACCEPT_DONE

lastWrite

protected long lastWrite

binaryWrite

protected final boolean binaryWrite
Constructor Detail

WebSocket

public WebSocket(AtmosphereConfig config)
Method Detail

config

public AtmosphereConfig config()

webSocketHandler

protected WebSocket webSocketHandler(WebSocketHandler webSocketHandler)

webSocketHandler

protected WebSocketHandler webSocketHandler()

resource

public WebSocket resource(AtmosphereResource r)
Associate an AtmosphereResource to this WebSocket

Parameters:
r - an AtmosphereResource to this WebSocket
Returns:
this

resource

public 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.

Returns:
AtmosphereResource

lastWriteTimeStampInMilliseconds

public long lastWriteTimeStampInMilliseconds()
The last time, in milliseconds, a write operation occurred.

Returns:
this

transform

protected byte[] transform(byte[] b,
                           int offset,
                           int length)
                    throws IOException
Throws:
IOException

write

public WebSocket write(AtmosphereResponse r,
                       String data)
                throws IOException
No OPS

Specified by:
write in interface AsyncIOWriter
Overrides:
write in class AtmosphereInterceptorWriter
data - the WebSocket message
Throws:
IOException

write

public WebSocket write(AtmosphereResponse r,
                       byte[] data)
                throws IOException
No OPS

Specified by:
write in interface AsyncIOWriter
Overrides:
write in class AtmosphereInterceptorWriter
data - the WebSocket message
Throws:
IOException

write

public WebSocket write(AtmosphereResponse r,
                       byte[] b,
                       int offset,
                       int length)
                throws IOException
No OPS

Specified by:
write in interface AsyncIOWriter
Overrides:
write in class AtmosphereInterceptorWriter
b - the WebSocket message
offset - offset of the message
length - length if the message
Throws:
IOException

writeError

public WebSocket writeError(AtmosphereResponse r,
                            int errorCode,
                            String message)
                     throws IOException
No OPS

Specified by:
writeError in interface AsyncIOWriter
Overrides:
writeError in class AtmosphereInterceptorWriter
errorCode - the error code
Throws:
IOException

redirect

public WebSocket redirect(AtmosphereResponse r,
                          String location)
                   throws IOException
No OPS

Specified by:
redirect in interface AsyncIOWriter
Overrides:
redirect in class AtmosphereInterceptorWriter
Throws:
IOException

close

public void close(AtmosphereResponse r)
           throws IOException
No OPS

Specified by:
close in interface AsyncIOWriter
Overrides:
close in class AtmosphereInterceptorWriter
Throws:
IOException

flush

public WebSocket flush(AtmosphereResponse r)
                throws IOException
No OPS

Specified by:
flush in interface AsyncIOWriter
Overrides:
flush in class AtmosphereInterceptorWriter
Throws:
IOException

isOpen

public abstract boolean isOpen()
Is the underlying WebSocket open.

Returns:

write

public abstract WebSocket write(String s)
                         throws IOException
Throws:
IOException

write

public abstract WebSocket write(byte[] b,
                                int offset,
                                int length)
                         throws IOException
Throws:
IOException

close

public abstract void close()


Copyright © 2012. All Rights Reserved.