Class AbstractWebSocket
java.lang.Object
org.java_websocket.WebSocketAdapter
org.java_websocket.AbstractWebSocket
- All Implemented Interfaces:
WebSocketListener
- Direct Known Subclasses:
WebSocketClient, WebSocketServer
Base class for additional implementations for the server as well as the client
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ScheduledFuture<?> Attribute for a task that checks for lost connectionsprivate ScheduledExecutorServiceAttribute for a service that triggers lost connection checkingprivate longAttribute for the lost connection check interval in nanosecondsprivate booleanAttribute to start internal threads as daemonprotected static intUsed for internal buffer allocations when the socket buffer size is not specified.private final org.slf4j.LoggerLogger instanceprivate intTCP receive buffer size that will be used for sockets (zero means use system default)private booleanAttribute which allows you to enable/disable the SO_REUSEADDR socket option.private final ObjectAttribute to sync onprivate booleanAttribute which allows you to deactivate the Nagle's algorithmprivate booleanAttribute to keep track if the WebSocket Server/Client is running/connected -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidCancel any running timer for the connection lost detectionprivate voidexecuteConnectionLostDetection(WebSocket webSocket, long minimumPongTime) Send a ping to the endpoint or close the connection since the other endpoint did not respond with a pingintGet the interval checking for lost connections Default is 60 secondsprotected abstract Collection<WebSocket> Getter to get all the currently available connectionsintReturns the TCP receive buffer size that will be used for sockets (or zero, if not explicitly set).booleanisDaemon()Getter for daemonbooleanTests Tests if SO_REUSEADDR is enabled.booleanTests if TCP_NODELAY is enabled.private voidThis methods allows the reset of the connection lost timer in case of a changed parametervoidsetConnectionLostTimeout(int connectionLostTimeout) Setter for the interval checking for lost connections A value lower or equal 0 results in the check to be deactivatedvoidsetDaemon(boolean daemon) Setter for daemonvoidsetReceiveBufferSize(int receiveBufferSize) Sets the TCP receive buffer size that will be used for sockets.voidsetReuseAddr(boolean reuseAddr) Setter for soReuseAddrvoidsetTcpNoDelay(boolean tcpNoDelay) Setter for tcpNoDelayprotected voidStart the connection lost timerprotected voidStop the connection lost timerMethods inherited from class WebSocketAdapter
onPreparePing, onWebsocketHandshakeReceivedAsClient, onWebsocketHandshakeReceivedAsServer, onWebsocketHandshakeSentAsClient, onWebsocketPing, onWebsocketPongMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface WebSocketListener
getLocalSocketAddress, getRemoteSocketAddress, onWebsocketClose, onWebsocketCloseInitiated, onWebsocketClosing, onWebsocketError, onWebsocketMessage, onWebsocketMessage, onWebsocketOpen, onWriteDemand
-
Field Details
-
log
private final org.slf4j.Logger logLogger instance- Since:
- 1.4.0
-
tcpNoDelay
private boolean tcpNoDelayAttribute which allows you to deactivate the Nagle's algorithm- Since:
- 1.3.3
-
reuseAddr
private boolean reuseAddrAttribute which allows you to enable/disable the SO_REUSEADDR socket option.- Since:
- 1.3.5
-
connectionLostCheckerService
Attribute for a service that triggers lost connection checking- Since:
- 1.4.1
-
connectionLostCheckerFuture
Attribute for a task that checks for lost connections- Since:
- 1.4.1
-
connectionLostTimeout
private long connectionLostTimeoutAttribute for the lost connection check interval in nanoseconds- Since:
- 1.3.4
-
websocketRunning
private boolean websocketRunningAttribute to keep track if the WebSocket Server/Client is running/connected- Since:
- 1.3.9
-
daemon
private boolean daemonAttribute to start internal threads as daemon- Since:
- 1.5.6
-
syncConnectionLost
Attribute to sync on -
receiveBufferSize
private int receiveBufferSizeTCP receive buffer size that will be used for sockets (zero means use system default)- Since:
- 1.5.7
-
DEFAULT_READ_BUFFER_SIZE
protected static int DEFAULT_READ_BUFFER_SIZEUsed for internal buffer allocations when the socket buffer size is not specified.
-
-
Constructor Details
-
AbstractWebSocket
public AbstractWebSocket()
-
-
Method Details
-
getConnectionLostTimeout
public int getConnectionLostTimeout()Get the interval checking for lost connections Default is 60 seconds- Returns:
- the interval in seconds
- Since:
- 1.3.4
-
setConnectionLostTimeout
public void setConnectionLostTimeout(int connectionLostTimeout) Setter for the interval checking for lost connections A value lower or equal 0 results in the check to be deactivated- Parameters:
connectionLostTimeout- the interval in seconds- Since:
- 1.3.4
-
stopConnectionLostTimer
protected void stopConnectionLostTimer()Stop the connection lost timer- Since:
- 1.3.4
-
startConnectionLostTimer
protected void startConnectionLostTimer()Start the connection lost timer- Since:
- 1.3.4
-
restartConnectionLostTimer
private void restartConnectionLostTimer()This methods allows the reset of the connection lost timer in case of a changed parameter- Since:
- 1.3.4
-
executeConnectionLostDetection
Send a ping to the endpoint or close the connection since the other endpoint did not respond with a ping- Parameters:
webSocket- the websocket instanceminimumPongTime- the lowest/oldest allowable last pong time (in nanoTime) before we consider the connection to be lost
-
getConnections
Getter to get all the currently available connections- Returns:
- the currently available connections
- Since:
- 1.3.4
-
cancelConnectionLostTimer
private void cancelConnectionLostTimer()Cancel any running timer for the connection lost detection- Since:
- 1.3.4
-
isTcpNoDelay
public boolean isTcpNoDelay()Tests if TCP_NODELAY is enabled.- Returns:
- a boolean indicating whether or not TCP_NODELAY is enabled for new connections.
- Since:
- 1.3.3
-
setTcpNoDelay
public void setTcpNoDelay(boolean tcpNoDelay) Setter for tcpNoDelayEnable/disable TCP_NODELAY (disable/enable Nagle's algorithm) for new connections
- Parameters:
tcpNoDelay- true to enable TCP_NODELAY, false to disable.- Since:
- 1.3.3
-
isReuseAddr
public boolean isReuseAddr()Tests Tests if SO_REUSEADDR is enabled.- Returns:
- a boolean indicating whether or not SO_REUSEADDR is enabled.
- Since:
- 1.3.5
-
setReuseAddr
public void setReuseAddr(boolean reuseAddr) Setter for soReuseAddrEnable/disable SO_REUSEADDR for the socket
- Parameters:
reuseAddr- whether to enable or disable SO_REUSEADDR- Since:
- 1.3.5
-
isDaemon
public boolean isDaemon()Getter for daemon- Returns:
- whether internal threads are spawned in daemon mode
- Since:
- 1.5.6
-
setDaemon
public void setDaemon(boolean daemon) Setter for daemonControls whether or not internal threads are spawned in daemon mode
- Since:
- 1.5.6
-
getReceiveBufferSize
public int getReceiveBufferSize()Returns the TCP receive buffer size that will be used for sockets (or zero, if not explicitly set).- Since:
- 1.5.7
- See Also:
-
setReceiveBufferSize
public void setReceiveBufferSize(int receiveBufferSize) Sets the TCP receive buffer size that will be used for sockets. If this is not explicitly set (or set to zero), the system default is used.- Since:
- 1.5.7
- See Also:
-