public.javadoc.org.spincast.plugins.undertow.SpincastWebsocketEndpoint.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spincast-website Show documentation
Show all versions of spincast-website Show documentation
Source code for the https://www.spincast.org website.
SpincastWebsocketEndpoint (org.spincast:spincast-framework 1.13.0 API)
org.spincast.plugins.undertow
Class SpincastWebsocketEndpoint
- java.lang.Object
-
- org.spincast.plugins.undertow.SpincastWebsocketEndpoint
-
- All Implemented Interfaces:
- WebsocketEndpointManager, WebsocketEndpointWriter, WebsocketEndpoint
public class SpincastWebsocketEndpoint
extends Object
implements WebsocketEndpoint
-
-
Field Summary
Fields
Modifier and Type
Field and Description
static String
EXCHANGE_VARIABLE_PEER_ID
protected static org.slf4j.Logger
logger
-
Constructor Summary
Constructors
Constructor and Description
SpincastWebsocketEndpoint(String endpointId,
WebsocketEndpointHandler eventsHandler,
UndertowWebsocketEndpointWriterFactory undertowWebsocketEndpointWriterFactory,
SpincastUndertowConfig spincastUndertowConfig,
SpincastUndertowUtils spincastUndertowUtils)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type
Method and Description
void
closeEndpoint()
Closes the entire WebSocket endpoint.
void
closeEndpoint(boolean sendClosingMessageToPeers)
Closes the entire WebSocket endpoint.
void
closeEndpoint(int closingCode,
String closingReason)
Closes the entire WebSocket endpoint.
protected void
closeEndpoint(int closingCode,
String closingReason,
boolean sendClosingMessageToPeers)
void
closePeer(String peerId)
Closes a specific peer connection on the endpoint.
void
closePeer(String peerId,
int closingCode,
String closingReason)
Closes a specific peer connection on the endpoint.
String
getEndpointId()
The endpoint id
protected WebsocketEndpointHandler
getEventsHandler()
protected Object
getNewPeerIdLock(String peerId)
Gets the creation lock for a peer id.
Set<String>
getPeersIds()
The connected peers' ids.
protected SpincastUndertowConfig
getSpincastUndertowConfig()
protected SpincastUndertowUtils
getSpincastUndertowUtils()
protected ExecutorService
getThreadExecutorForAppEvents()
The ExecutorService to use to
send events to the application.
protected int
getThreadExecutorForAppEventsThreadNumber()
The maximum number of concurrent threads used when
sending events to the application.
protected ThreadFactory
getThreadExecutorForAppEventsThreadThreadFactory()
The ThreadFactory to use for the Executor that
sends events to the application.
protected int
getThreadExecutorForAppEventsTimeoutAmount()
The timeout amount before cancelling a task when
sending events to the application.
protected TimeUnit
getThreadExecutorForAppEventsTimeoutTimeUnit()
The timeout unit before cancelling a task when
sending events to the application.
protected UndertowWebsocketEndpointWriterFactory
getUndertowWebsocketEndpointWriterFactory()
protected UndertowWebsocketEndpointWriter
getUndertowWebsocketWriter()
protected Map<String,io.undertow.websockets.core.WebSocketChannel>
getWebSocketChannelByPeerId()
protected io.undertow.websockets.WebSocketProtocolHandshakeHandler
getWebSocketProtocolHandshakeHandler()
The handler to use for the Websocket connection.
void
handleConnectionRequest(io.undertow.server.HttpServerExchange exchange,
String peerId)
protected void
init()
boolean
isClosed()
Is this endpoint closed?
boolean
isClosing()
Is this endpoint closing?
protected void
managePeersWriteConnectionClosed(Set<String> peerIds)
Called when a write operation detected a closed connection
on some peers.
protected void
removePeerChannel(String peerId)
protected void
removePeerChannelAndSendPeerClosedAppEvent(String peerId)
protected void
sendAppEventInNewThread(Runnable runnable)
Sends an event to the application in a separated thread.
void
sendMessage(byte[] message)
Sends a byte array message to all
peers of the endpoint.
void
sendMessage(Set<String> peerIds,
byte[] message)
Sends a byte array message to specific
peers.
void
sendMessage(Set<String> peerIds,
String message)
Sends a String message to specific
peers.
void
sendMessage(String message)
Sends a String message to all
peers of the endpoint.
void
sendMessage(String peerId,
byte[] message)
Sends a byte array message to a specific
peer.
void
sendMessage(String peerId,
String message)
Sends a String message to a specific
peer.
void
sendMessageExcept(Set<String> peerIdsToRemove,
byte[] message)
Sends a byte array message to all
peers except the specified ones.
void
sendMessageExcept(Set<String> peerIdsToRemove,
String message)
Sends a String message to all
peers except the specified ones.
void
sendMessageExcept(String peerId,
byte[] message)
Sends a byte array message to all
peers except the specified one.
void
sendMessageExcept(String peerId,
String message)
Sends a String message to all
peers except the specified one.
protected void
sendOnBytesMessageAppEvent(String peerId,
byte[] message)
Sends a "byte[] message" event to the app.
protected void
sendOnPeerConnectedAppEvent(String peerId)
Sends a "Peer connected " event to the app.
protected void
sendOnStringMessageAppEvent(String peerId,
String message)
Sends a "String message" event to the app.
protected void
sendPeerClosedAppEvent(String peerId)
Sends a "peer closed" event to the app.
protected void
startSendingPings()
Starts sending automatic pings to the peers.
protected void
stopSendingPings()
protected void
validateWebsocketClosingCode(int closingCode)
Is the Websocket closing code valid?
-
-
Field Detail
-
logger
protected static final org.slf4j.Logger logger
-
EXCHANGE_VARIABLE_PEER_ID
public static final String EXCHANGE_VARIABLE_PEER_ID
-
Constructor Detail
-
SpincastWebsocketEndpoint
public SpincastWebsocketEndpoint(String endpointId,
WebsocketEndpointHandler eventsHandler,
UndertowWebsocketEndpointWriterFactory undertowWebsocketEndpointWriterFactory,
SpincastUndertowConfig spincastUndertowConfig,
SpincastUndertowUtils spincastUndertowUtils)
Constructor
-
Method Detail
-
init
@Inject
protected void init()
-
getWebSocketChannelByPeerId
protected Map<String,io.undertow.websockets.core.WebSocketChannel> getWebSocketChannelByPeerId()
-
getEventsHandler
protected WebsocketEndpointHandler getEventsHandler()
-
getUndertowWebsocketEndpointWriterFactory
protected UndertowWebsocketEndpointWriterFactory getUndertowWebsocketEndpointWriterFactory()
-
getSpincastUndertowConfig
protected SpincastUndertowConfig getSpincastUndertowConfig()
-
getSpincastUndertowUtils
protected SpincastUndertowUtils getSpincastUndertowUtils()
-
getUndertowWebsocketWriter
protected UndertowWebsocketEndpointWriter getUndertowWebsocketWriter()
-
getNewPeerIdLock
protected Object getNewPeerIdLock(String peerId)
Gets the creation lock for a peer id.
-
getEndpointId
public String getEndpointId()
Description copied from interface: WebsocketEndpointManager
The endpoint id
- Specified by:
getEndpointId
in interface WebsocketEndpointManager
-
getPeersIds
public Set<String> getPeersIds()
Description copied from interface: WebsocketEndpointManager
The connected peers' ids.
- Specified by:
getPeersIds
in interface WebsocketEndpointManager
-
closePeer
public void closePeer(String peerId)
Description copied from interface: WebsocketEndpointManager
Closes a specific peer connection on the endpoint.
- Specified by:
closePeer
in interface WebsocketEndpointManager
-
closePeer
public void closePeer(String peerId,
int closingCode,
String closingReason)
Description copied from interface: WebsocketEndpointManager
Closes a specific peer connection on the endpoint.
- Specified by:
closePeer
in interface WebsocketEndpointManager
-
removePeerChannelAndSendPeerClosedAppEvent
protected void removePeerChannelAndSendPeerClosedAppEvent(String peerId)
-
removePeerChannel
protected void removePeerChannel(String peerId)
-
managePeersWriteConnectionClosed
protected void managePeersWriteConnectionClosed(Set<String> peerIds)
Called when a write operation detected a closed connection
on some peers.
-
isClosing
public boolean isClosing()
Description copied from interface: WebsocketEndpointManager
Is this endpoint closing?
- Specified by:
isClosing
in interface WebsocketEndpointManager
-
isClosed
public boolean isClosed()
Description copied from interface: WebsocketEndpointManager
Is this endpoint closed?
- Specified by:
isClosed
in interface WebsocketEndpointManager
-
closeEndpoint
public void closeEndpoint()
Description copied from interface: WebsocketEndpointManager
Closes 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:
closeEndpoint
in interface WebsocketEndpointManager
-
closeEndpoint
public void closeEndpoint(boolean sendClosingMessageToPeers)
Description copied from interface: WebsocketEndpointManager
Closes the entire WebSocket endpoint.
All peer connections of this endpoint will be
closed and the endpoint will be removed.
- Specified by:
closeEndpoint
in interface WebsocketEndpointManager
- Parameters:
sendClosingMessageToPeers
- if true
,
Spincast will try to send a "closing" message to the peers
before closing their connections.
-
closeEndpoint
public void closeEndpoint(int closingCode,
String closingReason)
Description copied from interface: WebsocketEndpointManager
Closes 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:
closeEndpoint
in interface WebsocketEndpointManager
-
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
public void sendMessage(String message)
Description copied from interface: WebsocketEndpointWriter
Sends a String message to all
peers of the endpoint.
- Specified by:
sendMessage
in interface WebsocketEndpointWriter
-
sendMessage
public void sendMessage(String peerId,
String message)
Description copied from interface: WebsocketEndpointWriter
Sends a String message to a specific
peer.
- Specified by:
sendMessage
in interface WebsocketEndpointWriter
-
sendMessageExcept
public void sendMessageExcept(String peerId,
String message)
Description copied from interface: WebsocketEndpointWriter
Sends a String message to all
peers except the specified one.
- Specified by:
sendMessageExcept
in interface WebsocketEndpointWriter
-
sendMessageExcept
public void sendMessageExcept(Set<String> peerIdsToRemove,
String message)
Description copied from interface: WebsocketEndpointWriter
Sends a String message to all
peers except the specified ones.
- Specified by:
sendMessageExcept
in interface WebsocketEndpointWriter
-
sendMessage
public void sendMessage(Set<String> peerIds,
String message)
Description copied from interface: WebsocketEndpointWriter
Sends a String message to specific
peers.
- Specified by:
sendMessage
in interface WebsocketEndpointWriter
-
sendMessage
public void sendMessage(byte[] message)
Description copied from interface: WebsocketEndpointWriter
Sends a byte array message to all
peers of the endpoint.
- Specified by:
sendMessage
in interface WebsocketEndpointWriter
-
sendMessage
public void sendMessage(String peerId,
byte[] message)
Description copied from interface: WebsocketEndpointWriter
Sends a byte array message to a specific
peer.
- Specified by:
sendMessage
in interface WebsocketEndpointWriter
-
sendMessageExcept
public void sendMessageExcept(String peerId,
byte[] message)
Description copied from interface: WebsocketEndpointWriter
Sends a byte array message to all
peers except the specified one.
- Specified by:
sendMessageExcept
in interface WebsocketEndpointWriter
-
sendMessageExcept
public void sendMessageExcept(Set<String> peerIdsToRemove,
byte[] message)
Description copied from interface: WebsocketEndpointWriter
Sends a byte array message to all
peers except the specified ones.
- Specified by:
sendMessageExcept
in interface WebsocketEndpointWriter
-
sendMessage
public void sendMessage(Set<String> peerIds,
byte[] message)
Description copied from interface: WebsocketEndpointWriter
Sends a byte array message to specific
peers.
- Specified by:
sendMessage
in interface WebsocketEndpointWriter
-
handleConnectionRequest
public void handleConnectionRequest(io.undertow.server.HttpServerExchange exchange,
String peerId)
- Specified by:
handleConnectionRequest
in interface WebsocketEndpoint
-
getWebSocketProtocolHandshakeHandler
protected io.undertow.websockets.WebSocketProtocolHandshakeHandler getWebSocketProtocolHandshakeHandler()
The handler to use for the Websocket connection.
-
sendOnPeerConnectedAppEvent
protected void sendOnPeerConnectedAppEvent(String peerId)
Sends a "Peer connected " event to the app.
-
sendOnStringMessageAppEvent
protected void sendOnStringMessageAppEvent(String peerId,
String message)
Sends a "String message" event to the app.
-
sendOnBytesMessageAppEvent
protected void sendOnBytesMessageAppEvent(String peerId,
byte[] message)
Sends a "byte[] message" event to the app.
-
sendPeerClosedAppEvent
protected void sendPeerClosedAppEvent(String peerId)
Sends a "peer closed" event to the app.
-
sendAppEventInNewThread
protected void sendAppEventInNewThread(Runnable runnable)
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
protected TimeUnit getThreadExecutorForAppEventsTimeoutTimeUnit()
The timeout unit before cancelling a task when
sending events to the application.
-
getThreadExecutorForAppEvents
protected ExecutorService 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
protected ThreadFactory getThreadExecutorForAppEventsThreadThreadFactory()
The ThreadFactory to use for the Executor that
sends events to the application.
- Returns:
- the ThreadFactory to use or
null
to use the default one.
Copyright © 2019. All rights reserved.