package org.glassfish.grizzly.websockets;
import org.glassfish.grizzly.Buffer;
import org.glassfish.grizzly.Connection;
import org.glassfish.grizzly.Grizzly;
import org.glassfish.grizzly.attributes.Attribute;
public final class WebSocketHolder {
public volatile WebSocket webSocket;
public volatile HandShake handshake;
public volatile WebSocketApplication application;
public volatile Buffer buffer;
public volatile ProtocolHandler handler;
private static final Attribute<WebSocketHolder> webSocketAttribute =
Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute("web-socket");
private WebSocketHolder(final ProtocolHandler handler, final WebSocket socket) {
this.handler = handler;
webSocket = socket;
}
public static boolean isWebSocketInProgress(final Connection connection) {
return (get(connection) != null);
}
public static WebSocket getWebSocket(Connection connection) {
final WebSocketHolder holder = get(connection);
return holder == null ? null : holder.webSocket;
}
public static WebSocketHolder get(final Connection connection) {
return webSocketAttribute.get(connection);
}
public static WebSocketHolder set(final Connection connection,
final ProtocolHandler handler,
final WebSocket socket) {
final WebSocketHolder holder = new WebSocketHolder(handler, socket);
webSocketAttribute.set(connection, holder);
return holder;
}
}