Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.websockets

public Class SimpleWebSocket

extends Object
implements WebSocket
Class Inheritance
All Implemented Interfaces
org.glassfish.grizzly.websockets.WebSocket
Known Direct Subclasses
org.glassfish.grizzly.websockets.DefaultWebSocket
Imports
java.util.Collection, .EnumSet, .Queue, java.util.concurrent.ConcurrentLinkedQueue, java.util.concurrent.atomic.AtomicReference, java.util.logging.Logger, org.glassfish.grizzly.Buffer, .Connection, .Grizzly, .GrizzlyFuture, org.glassfish.grizzly.memory.Buffers, .MemoryManager, org.glassfish.grizzly.websockets.frametypes.PingFrameType, .PongFrameType

Generic WebSocket implementation. Typically used by client implementations.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static enum

Field Summary

Modifier and TypeField and Description
protected Broadcaster
protected final EnumSet<SimpleWebSocket.State>
protected final Queue<WebSocketListener>
private static final Logger
protected final ProtocolHandler
protected final AtomicReference<SimpleWebSocket.State>

Constructor Summary

AccessConstructor and Description
public
SimpleWebSocket(final ProtocolHandler protocolHandler, final WebSocketListener... listeners)

Method Summary

Modifier and TypeMethod and Description
public final boolean
add(WebSocketListener listener)

Implements org.glassfish.grizzly.websockets.WebSocket.add.

Adds a WebSocketListener to be notified of events of interest.

public void
broadcast(Iterable<? extends WebSocket> recipients, String data)

Implements org.glassfish.grizzly.websockets.WebSocket.broadcast.

Broadcasts the data to the remote end-point set.

public void
broadcast(Iterable<? extends WebSocket> recipients, byte[] data)

Implements org.glassfish.grizzly.websockets.WebSocket.broadcast.

Broadcasts the data to the remote end-point set.

public void
broadcastFragment(Iterable<? extends WebSocket> recipients, String data, boolean last)

Implements org.glassfish.grizzly.websockets.WebSocket.broadcastFragment.

Broadcasts the data fragment to the remote end-point set.

public void
broadcastFragment(Iterable<? extends WebSocket> recipients, byte[] data, boolean last)

Implements org.glassfish.grizzly.websockets.WebSocket.broadcastFragment.

Broadcasts the data fragment to the remote end-point set.

public void
public void
close(int code)

Implements org.glassfish.grizzly.websockets.WebSocket.close.

Closes this WebSocket using the specified status code.

public void
close(int code, String reason)

Implements org.glassfish.grizzly.websockets.WebSocket.close.

Closes this WebSocket using the specified status code and reason.

protected Broadcaster
public Collection<WebSocketListener>
public boolean
isConnected()

Implements org.glassfish.grizzly.websockets.WebSocket.isConnected.

Convenience method to determine if this WebSocket is connected.

public void
onClose(final DataFrame frame)

Implements org.glassfish.grizzly.websockets.WebSocket.onClose.

This callback will be invoked when the remote end-point sent a closing frame.

public void
onConnect()

Implements org.glassfish.grizzly.websockets.WebSocket.onConnect.

This callback will be invoked when the opening handshake between both endpoints has been completed.

public void
onFragment(boolean last, byte[] fragment)

Implements org.glassfish.grizzly.websockets.WebSocket.onFragment.

This callback will be invoked when a fragmented binary message has been received.

public void
onFragment(boolean last, String fragment)

Implements org.glassfish.grizzly.websockets.WebSocket.onFragment.

This callback will be invoked when a fragmented textual message has been received.

public void
onMessage(byte[] data)

Implements org.glassfish.grizzly.websockets.WebSocket.onMessage.

This callback will be invoked when a binary message has been received.

public void
onMessage(String text)

Implements org.glassfish.grizzly.websockets.WebSocket.onMessage.

This callback will be invoked when a text message has been received.

public void
onPing(DataFrame frame)

Implements org.glassfish.grizzly.websockets.WebSocket.onPing.

This callback will be invoked when the remote end-point has sent a ping frame.

public void
onPong(DataFrame frame)

Implements org.glassfish.grizzly.websockets.WebSocket.onPong.

This callback will be invoked when the remote end-point has sent a pong frame.

public final boolean
remove(WebSocketListener listener)

Implements org.glassfish.grizzly.websockets.WebSocket.remove.

Removes the specified WebSocketListener as a target of event notification.

public GrizzlyFuture<DataFrame>
send(byte[] data)

Implements org.glassfish.grizzly.websockets.WebSocket.send.

Send a binary frame to the remote end-point.

public GrizzlyFuture<DataFrame>
send(String data)

Implements org.glassfish.grizzly.websockets.WebSocket.send.

Send a text frame to the remote end-point.

private GrizzlyFuture<DataFrame>
send(DataFrame frame)

public GrizzlyFuture<DataFrame>
sendPing(byte[] data)

Implements org.glassfish.grizzly.websockets.WebSocket.sendPing.

Sends a ping frame with the specified payload (if any).

public GrizzlyFuture<DataFrame>
sendPong(byte[] data)

Implements org.glassfish.grizzly.websockets.WebSocket.sendPong.

Sends a ping frame with the specified payload (if any).

protected void
sendRaw(byte[] rawData)

protected void
public void
public GrizzlyFuture<DataFrame>
stream(boolean last, String fragment)

Implements org.glassfish.grizzly.websockets.WebSocket.stream.

Sends a fragment of a complete message.

public GrizzlyFuture<DataFrame>
stream(boolean last, byte[] bytes, int off, int len)

Implements org.glassfish.grizzly.websockets.WebSocket.stream.

Sends a fragment of a complete message.

protected byte[]
protected byte[]
toRawData(byte[] binary)

protected byte[]
toRawData(String fragment, boolean last)

protected byte[]
toRawData(byte[] binary, boolean last)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

broadcasterback to summary
protected Broadcaster broadcaster
connectedback to summary
protected final EnumSet<SimpleWebSocket.State> connected
listenersback to summary
protected final Queue<WebSocketListener> listeners
LOGGERback to summary
private static final Logger LOGGER
protocolHandlerback to summary
protected final ProtocolHandler protocolHandler
stateback to summary
protected final AtomicReference<SimpleWebSocket.State> state

Constructor Detail

SimpleWebSocketback to summary
public SimpleWebSocket(final ProtocolHandler protocolHandler, final WebSocketListener... listeners)

Method Detail

addback to summary
public final boolean add(WebSocketListener listener)

Implements org.glassfish.grizzly.websockets.WebSocket.add.

Doc from org.glassfish.grizzly.websockets.WebSocket.add.

Adds a WebSocketListener to be notified of events of interest.

Annotations
@Override
broadcastback to summary
public void broadcast(Iterable<? extends WebSocket> recipients, String data)

Implements org.glassfish.grizzly.websockets.WebSocket.broadcast.

Doc from org.glassfish.grizzly.websockets.WebSocket.broadcast.

Broadcasts the data to the remote end-point set.

Annotations
@Override
broadcastback to summary
public void broadcast(Iterable<? extends WebSocket> recipients, byte[] data)

Implements org.glassfish.grizzly.websockets.WebSocket.broadcast.

Doc from org.glassfish.grizzly.websockets.WebSocket.broadcast.

Broadcasts the data to the remote end-point set.

Annotations
@Override
broadcastFragmentback to summary
public void broadcastFragment(Iterable<? extends WebSocket> recipients, String data, boolean last)

Implements org.glassfish.grizzly.websockets.WebSocket.broadcastFragment.

Doc from org.glassfish.grizzly.websockets.WebSocket.broadcastFragment.

Broadcasts the data fragment to the remote end-point set.

Annotations
@Override
broadcastFragmentback to summary
public void broadcastFragment(Iterable<? extends WebSocket> recipients, byte[] data, boolean last)

Implements org.glassfish.grizzly.websockets.WebSocket.broadcastFragment.

Doc from org.glassfish.grizzly.websockets.WebSocket.broadcastFragment.

Broadcasts the data fragment to the remote end-point set.

Annotations
@Override
closeback to summary
public void close()

Implements org.glassfish.grizzly.websockets.WebSocket.close.

Doc from org.glassfish.grizzly.websockets.WebSocket.close.

Closes this WebSocket.

Annotations
@Override
closeback to summary
public void close(int code)

Implements org.glassfish.grizzly.websockets.WebSocket.close.

Doc from org.glassfish.grizzly.websockets.WebSocket.close.

Closes this WebSocket using the specified status code.

Annotations
@Override
closeback to summary
public void close(int code, String reason)

Implements org.glassfish.grizzly.websockets.WebSocket.close.

Doc from org.glassfish.grizzly.websockets.WebSocket.close.

Closes this WebSocket using the specified status code and reason.

Annotations
@Override
getBroadcasterback to summary
protected Broadcaster getBroadcaster()
getListenersback to summary
public Collection<WebSocketListener> getListeners()
isConnectedback to summary
public boolean isConnected()

Implements org.glassfish.grizzly.websockets.WebSocket.isConnected.

Doc from org.glassfish.grizzly.websockets.WebSocket.isConnected.

Convenience method to determine if this WebSocket is connected.

Annotations
@Override
onCloseback to summary
public void onClose(final DataFrame frame)

Implements org.glassfish.grizzly.websockets.WebSocket.onClose.

Doc from org.glassfish.grizzly.websockets.WebSocket.onClose.

This callback will be invoked when the remote end-point sent a closing frame.

Annotations
@Override
onConnectback to summary
public void onConnect()

Implements org.glassfish.grizzly.websockets.WebSocket.onConnect.

Doc from org.glassfish.grizzly.websockets.WebSocket.onConnect.

This callback will be invoked when the opening handshake between both endpoints has been completed.

Annotations
@Override
onFragmentback to summary
public void onFragment(boolean last, byte[] fragment)

Implements org.glassfish.grizzly.websockets.WebSocket.onFragment.

Doc from org.glassfish.grizzly.websockets.WebSocket.onFragment.

This callback will be invoked when a fragmented binary message has been received.

Annotations
@Override
onFragmentback to summary
public void onFragment(boolean last, String fragment)

Implements org.glassfish.grizzly.websockets.WebSocket.onFragment.

Doc from org.glassfish.grizzly.websockets.WebSocket.onFragment.

This callback will be invoked when a fragmented textual message has been received.

Annotations
@Override
onMessageback to summary
public void onMessage(byte[] data)

Implements org.glassfish.grizzly.websockets.WebSocket.onMessage.

Doc from org.glassfish.grizzly.websockets.WebSocket.onMessage.

This callback will be invoked when a binary message has been received.

Annotations
@Override
onMessageback to summary
public void onMessage(String text)

Implements org.glassfish.grizzly.websockets.WebSocket.onMessage.

Doc from org.glassfish.grizzly.websockets.WebSocket.onMessage.

This callback will be invoked when a text message has been received.

Annotations
@Override
onPingback to summary
public void onPing(DataFrame frame)

Implements org.glassfish.grizzly.websockets.WebSocket.onPing.

Doc from org.glassfish.grizzly.websockets.WebSocket.onPing.

This callback will be invoked when the remote end-point has sent a ping frame.

Annotations
@Override
onPongback to summary
public void onPong(DataFrame frame)

Implements org.glassfish.grizzly.websockets.WebSocket.onPong.

Doc from org.glassfish.grizzly.websockets.WebSocket.onPong.

This callback will be invoked when the remote end-point has sent a pong frame.

Annotations
@Override
removeback to summary
public final boolean remove(WebSocketListener listener)

Implements org.glassfish.grizzly.websockets.WebSocket.remove.

Doc from org.glassfish.grizzly.websockets.WebSocket.remove.

Removes the specified WebSocketListener as a target of event notification.

Annotations
@Override
sendback to summary
public GrizzlyFuture<DataFrame> send(byte[] data)

Implements org.glassfish.grizzly.websockets.WebSocket.send.

Doc from org.glassfish.grizzly.websockets.WebSocket.send.

Send a binary frame to the remote end-point.

Annotations
@Override
sendback to summary
public GrizzlyFuture<DataFrame> send(String data)

Implements org.glassfish.grizzly.websockets.WebSocket.send.

Doc from org.glassfish.grizzly.websockets.WebSocket.send.

Send a text frame to the remote end-point.

Annotations
@Override
sendback to summary
private GrizzlyFuture<DataFrame> send(DataFrame frame)
sendPingback to summary
public GrizzlyFuture<DataFrame> sendPing(byte[] data)

Implements org.glassfish.grizzly.websockets.WebSocket.sendPing.

Doc from org.glassfish.grizzly.websockets.WebSocket.sendPing.

Sends a ping frame with the specified payload (if any).

Annotations
@Override
sendPongback to summary
public GrizzlyFuture<DataFrame> sendPong(byte[] data)

Implements org.glassfish.grizzly.websockets.WebSocket.sendPong.

Doc from org.glassfish.grizzly.websockets.WebSocket.sendPong.

Sends a ping frame with the specified payload (if any).

It may seem odd to send a pong frame, however, RFC-6455 states:

"A Pong frame MAY be sent unsolicited. This serves as a unidirectional heartbeat. A response to an unsolicited Pong frame is not expected."

Annotations
@Override
sendRawback to summary
protected void sendRaw(byte[] rawData)
Annotations
@SuppressWarnings:unchecked
setBroadcasterback to summary
protected void setBroadcaster(Broadcaster broadcaster)
setClosedback to summary
public void setClosed()
streamback to summary
public GrizzlyFuture<DataFrame> stream(boolean last, String fragment)

Implements org.glassfish.grizzly.websockets.WebSocket.stream.

Doc from org.glassfish.grizzly.websockets.WebSocket.stream.

Sends a fragment of a complete message.

Annotations
@Override
streamback to summary
public GrizzlyFuture<DataFrame> stream(boolean last, byte[] bytes, int off, int len)

Implements org.glassfish.grizzly.websockets.WebSocket.stream.

Doc from org.glassfish.grizzly.websockets.WebSocket.stream.

Sends a fragment of a complete message.

Annotations
@Override
toRawDataback to summary
protected byte[] toRawData(String text)
toRawDataback to summary
protected byte[] toRawData(byte[] binary)
toRawDataback to summary
protected byte[] toRawData(String fragment, boolean last)
toRawDataback to summary
protected byte[] toRawData(byte[] binary, boolean last)
org.glassfish.grizzly.websockets back to summary

protected final Enum SimpleWebSocket.State

extends Enum<SimpleWebSocket.State>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final SimpleWebSocket.State
public static final SimpleWebSocket.State
public static final SimpleWebSocket.State
public static final SimpleWebSocket.State

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static SimpleWebSocket.State
public static SimpleWebSocket.State[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CLOSEDback to summary
public static final SimpleWebSocket.State CLOSED
CLOSINGback to summary
public static final SimpleWebSocket.State CLOSING
CONNECTEDback to summary
public static final SimpleWebSocket.State CONNECTED
NEWback to summary
public static final SimpleWebSocket.State NEW

Constructor Detail

Stateback to summary
private State()

Method Detail

valueOfback to summary
public static SimpleWebSocket.State valueOf(String name)
valuesback to summary
public static SimpleWebSocket.State[] values()