Package org.spincast.plugins.undertow
Class SpincastWebsocketEndpoint
java.lang.Object
org.spincast.plugins.undertow.SpincastWebsocketEndpoint
- All Implemented Interfaces:
WebsocketEndpointManager,WebsocketEndpointWriter,WebsocketEndpoint
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSpincastWebsocketEndpoint(String endpointId, WebsocketEndpointHandler eventsHandler, UndertowWebsocketEndpointWriterFactory undertowWebsocketEndpointWriterFactory, SpincastUndertowConfig spincastUndertowConfig, SpincastUndertowUtils spincastUndertowUtils) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidCloses the entire WebSocket endpoint.voidcloseEndpoint(boolean sendClosingMessageToPeers) Closes the entire WebSocket endpoint.voidcloseEndpoint(int closingCode, String closingReason) Closes the entire WebSocket endpoint.protected voidcloseEndpoint(int closingCode, String closingReason, boolean sendClosingMessageToPeers) voidCloses a specific peer connection on the endpoint.voidCloses a specific peer connection on the endpoint.The endpoint idprotected WebsocketEndpointHandlerprotected ObjectgetNewPeerIdLock(String peerId) Gets the creation lock for a peer id.The connected peers' ids.protected SpincastUndertowConfigprotected SpincastUndertowUtilsprotected ExecutorServiceThe ExecutorService to use to send events to the application.protected intThe maximum number of concurrent threads used when sending events to the application.protected ThreadFactoryThe ThreadFactory to use for the Executor that sends events to the application.protected intThe timeout amount before cancelling a task when sending events to the application.protected TimeUnitThe timeout unit before cancelling a task when sending events to the application.protected UndertowWebsocketEndpointWriterFactoryprotected UndertowWebsocketEndpointWriterprotected io.undertow.websockets.WebSocketProtocolHandshakeHandlerThe handler to use for the Websocket connection.voidhandleConnectionRequest(io.undertow.server.HttpServerExchange exchange, String peerId) protected voidinit()booleanisClosed()Is this endpoint closed?booleanIs this endpoint closing?protected voidmanagePeersWriteConnectionClosed(Set<String> peerIds) Called when a write operation detected a closed connection on some peers.protected voidremovePeerChannel(String peerId) protected voidprotected voidsendAppEventInNewThread(Runnable runnable) Sends an event to the application in a separated thread.voidsendMessage(byte[] message) Sends a byte array message to all peers of the endpoint.voidsendMessage(String message) Sends a String message to all peers of the endpoint.voidsendMessage(String peerId, byte[] message) Sends a byte array message to a specific peer.voidsendMessage(String peerId, String message) Sends a String message to a specific peer.voidsendMessage(Set<String> peerIds, byte[] message) Sends a byte array message to specific peers.voidsendMessage(Set<String> peerIds, String message) Sends a String message to specific peers.voidsendMessageExcept(String peerId, byte[] message) Sends a byte array message to all peers except the specified one.voidsendMessageExcept(String peerId, String message) Sends a String message to all peers except the specified one.voidsendMessageExcept(Set<String> peerIdsToRemove, byte[] message) Sends a byte array message to all peers except the specified ones.voidsendMessageExcept(Set<String> peerIdsToRemove, String message) Sends a String message to all peers except the specified ones.protected voidsendOnBytesMessageAppEvent(String peerId, byte[] message) Sends a "byte[] message" event to the app.protected voidsendOnPeerConnectedAppEvent(String peerId) Sends a "Peer connected " event to the app.protected voidsendOnStringMessageAppEvent(String peerId, String message) Sends a "String message" event to the app.protected voidsendPeerClosedAppEvent(String peerId) Sends a "peer closed" event to the app.protected voidStarts sending automatic pings to the peers.protected voidprotected voidvalidateWebsocketClosingCode(int closingCode) Is the Websocket closing code valid?
-
Field Details
-
logger
protected static final org.slf4j.Logger logger -
EXCHANGE_VARIABLE_PEER_ID
-
-
Constructor Details
-
SpincastWebsocketEndpoint
public SpincastWebsocketEndpoint(String endpointId, WebsocketEndpointHandler eventsHandler, UndertowWebsocketEndpointWriterFactory undertowWebsocketEndpointWriterFactory, SpincastUndertowConfig spincastUndertowConfig, SpincastUndertowUtils spincastUndertowUtils) Constructor
-
-
Method Details
-
init
@Inject protected void init() -
getWebSocketChannelByPeerId
-
getEventsHandler
-
getUndertowWebsocketEndpointWriterFactory
-
getSpincastUndertowConfig
-
getSpincastUndertowUtils
-
getUndertowWebsocketWriter
-
getNewPeerIdLock
Gets the creation lock for a peer id. -
getEndpointId
Description copied from interface:WebsocketEndpointManagerThe endpoint id- Specified by:
getEndpointIdin interfaceWebsocketEndpointManager
-
getPeersIds
Description copied from interface:WebsocketEndpointManagerThe connected peers' ids.- Specified by:
getPeersIdsin interfaceWebsocketEndpointManager
-
closePeer
Description copied from interface:WebsocketEndpointManagerCloses a specific peer connection on the endpoint.- Specified by:
closePeerin interfaceWebsocketEndpointManager
-
closePeer
Description copied from interface:WebsocketEndpointManagerCloses a specific peer connection on the endpoint.- Specified by:
closePeerin interfaceWebsocketEndpointManager
-
removePeerChannelAndSendPeerClosedAppEvent
-
removePeerChannel
-
managePeersWriteConnectionClosed
Called when a write operation detected a closed connection on some peers. -
isClosing
public boolean isClosing()Description copied from interface:WebsocketEndpointManagerIs this endpoint closing?- Specified by:
isClosingin interfaceWebsocketEndpointManager
-
isClosed
public boolean isClosed()Description copied from interface:WebsocketEndpointManagerIs this endpoint closed?- Specified by:
isClosedin interfaceWebsocketEndpointManager
-
closeEndpoint
public void closeEndpoint()Description copied from interface:WebsocketEndpointManagerCloses the entire WebSocket endpoint. All peer connections of this endpoint will be closed and the endpoint will be removed.Will try to send a "closing" message to the peers before closing their connection.
- Specified by:
closeEndpointin interfaceWebsocketEndpointManager
-
closeEndpoint
public void closeEndpoint(boolean sendClosingMessageToPeers) Description copied from interface:WebsocketEndpointManagerCloses the entire WebSocket endpoint. All peer connections of this endpoint will be closed and the endpoint will be removed.- Specified by:
closeEndpointin interfaceWebsocketEndpointManager- Parameters:
sendClosingMessageToPeers- iftrue, Spincast will try to send a "closing" message to the peers before closing their connections.
-
closeEndpoint
Description copied from interface:WebsocketEndpointManagerCloses the entire WebSocket endpoint. All peer connections of this endpoint will be closed and the endpoint will be removed.Will try to send a "closing" message to the peers before closing their connection.
- Specified by:
closeEndpointin interfaceWebsocketEndpointManager
-
closeEndpoint
protected void closeEndpoint(int closingCode, String closingReason, boolean sendClosingMessageToPeers) -
validateWebsocketClosingCode
protected void validateWebsocketClosingCode(int closingCode) Is the Websocket closing code valid?- Throws:
an- expcetion is the code is not valid.
-
startSendingPings
protected void startSendingPings()Starts sending automatic pings to the peers. -
stopSendingPings
protected void stopSendingPings() -
sendMessage
Description copied from interface:WebsocketEndpointWriterSends a String message to all peers of the endpoint.- Specified by:
sendMessagein interfaceWebsocketEndpointWriter
-
sendMessage
Description copied from interface:WebsocketEndpointWriterSends a String message to a specific peer.- Specified by:
sendMessagein interfaceWebsocketEndpointWriter
-
sendMessageExcept
Description copied from interface:WebsocketEndpointWriterSends a String message to all peers except the specified one.- Specified by:
sendMessageExceptin interfaceWebsocketEndpointWriter
-
sendMessageExcept
Description copied from interface:WebsocketEndpointWriterSends a String message to all peers except the specified ones.- Specified by:
sendMessageExceptin interfaceWebsocketEndpointWriter
-
sendMessage
Description copied from interface:WebsocketEndpointWriterSends a String message to specific peers.- Specified by:
sendMessagein interfaceWebsocketEndpointWriter
-
sendMessage
public void sendMessage(byte[] message) Description copied from interface:WebsocketEndpointWriterSends a byte array message to all peers of the endpoint.- Specified by:
sendMessagein interfaceWebsocketEndpointWriter
-
sendMessage
Description copied from interface:WebsocketEndpointWriterSends a byte array message to a specific peer.- Specified by:
sendMessagein interfaceWebsocketEndpointWriter
-
sendMessageExcept
Description copied from interface:WebsocketEndpointWriterSends a byte array message to all peers except the specified one.- Specified by:
sendMessageExceptin interfaceWebsocketEndpointWriter
-
sendMessageExcept
Description copied from interface:WebsocketEndpointWriterSends a byte array message to all peers except the specified ones.- Specified by:
sendMessageExceptin interfaceWebsocketEndpointWriter
-
sendMessage
Description copied from interface:WebsocketEndpointWriterSends a byte array message to specific peers.- Specified by:
sendMessagein interfaceWebsocketEndpointWriter
-
handleConnectionRequest
- Specified by:
handleConnectionRequestin interfaceWebsocketEndpoint
-
getWebSocketProtocolHandshakeHandler
protected io.undertow.websockets.WebSocketProtocolHandshakeHandler getWebSocketProtocolHandshakeHandler()The handler to use for the Websocket connection. -
sendOnPeerConnectedAppEvent
Sends a "Peer connected " event to the app. -
sendOnStringMessageAppEvent
Sends a "String message" event to the app. -
sendOnBytesMessageAppEvent
Sends a "byte[] message" event to the app. -
sendPeerClosedAppEvent
Sends a "peer closed" event to the app. -
sendAppEventInNewThread
Sends an event to the application in a separated thread. -
getThreadExecutorForAppEventsTimeoutAmount
protected int getThreadExecutorForAppEventsTimeoutAmount()The timeout amount before cancelling a task when sending events to the application. -
getThreadExecutorForAppEventsTimeoutTimeUnit
The timeout unit before cancelling a task when sending events to the application. -
getThreadExecutorForAppEvents
The ExecutorService to use to send events to the application. -
getThreadExecutorForAppEventsThreadNumber
protected int getThreadExecutorForAppEventsThreadNumber()The maximum number of concurrent threads used when sending events to the application. -
getThreadExecutorForAppEventsThreadThreadFactory
The ThreadFactory to use for the Executor that sends events to the application.- Returns:
- the ThreadFactory to use or
nullto use the default one.
-