Class NettyStreamingService<T>
java.lang.Object
info.bitrich.xchangestream.service.ConnectableService
info.bitrich.xchangestream.service.netty.NettyStreamingService<T>
- Direct Known Subclasses:
JsonNettyStreamingService
public abstract class NettyStreamingService<T> extends ConnectableService
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
NettyStreamingService.NettyWebSocketClientHandler
protected class
NettyStreamingService.Subscription
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,NettyStreamingService.Subscription>
channels
protected static Duration
DEFAULT_CONNECTION_TIMEOUT
protected static int
DEFAULT_IDLE_TIMEOUT
protected static Duration
DEFAULT_RETRY_DURATION
protected URI
uri
Fields inherited from class info.bitrich.xchangestream.service.ConnectableService
BEFORE_CONNECTION_HANDLER
-
Constructor Summary
Constructors Constructor Description NettyStreamingService(String apiUrl)
NettyStreamingService(String apiUrl, int maxFramePayloadLength)
NettyStreamingService(String apiUrl, int maxFramePayloadLength, Duration connectionTimeout, Duration retryDuration)
NettyStreamingService(String apiUrl, int maxFramePayloadLength, Duration connectionTimeout, Duration retryDuration, int idleTimeoutSeconds)
-
Method Summary
Modifier and Type Method Description io.reactivex.Completable
disconnect()
protected String
getChannel(T message)
protected abstract String
getChannelNameFromMessage(T message)
protected io.netty.handler.codec.http.DefaultHttpHeaders
getCustomHeaders()
abstract String
getSubscribeMessage(String channelName, Object... args)
String
getSubscriptionUniqueId(String channelName, Object... args)
abstract String
getUnsubscribeMessage(String channelName, Object... args)
protected io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler
getWebSocketClientExtensionHandler()
protected WebSocketClientHandler
getWebSocketClientHandler(io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker handshaker, WebSocketClientHandler.WebSocketMessageHandler handler)
protected void
handleChannelError(String channel, Throwable t)
protected void
handleChannelMessage(String channel, T message)
protected void
handleError(T message, Throwable t)
protected void
handleIdle(io.netty.channel.ChannelHandlerContext ctx)
protected void
handleMessage(T message)
boolean
isSocketOpen()
abstract void
messageHandler(String message)
Handler that receives incoming messages.protected io.reactivex.Completable
openConnection()
void
resubscribeChannels()
void
sendMessage(String message)
void
setAcceptAllCertificates(boolean acceptAllCertificates)
void
setAutoReconnect(boolean autoReconnect)
void
setEnableLoggingHandler(boolean enableLoggingHandler)
void
setLoggingHandlerLevel(io.netty.handler.logging.LogLevel loggingHandlerLevel)
void
setSocksProxyHost(String socksProxyHost)
void
setSocksProxyPort(Integer socksProxyPort)
io.reactivex.Observable<T>
subscribeChannel(String channelName, Object... args)
io.reactivex.Observable<ConnectionStateModel.State>
subscribeConnectionState()
io.reactivex.Observable<Object>
subscribeConnectionSuccess()
io.reactivex.Observable<Object>
subscribeDisconnect()
io.reactivex.Observable<Object>
subscribeIdle()
Observable which fires if the websocket is deemed idle, only fired ifidleTimeoutSeconds != 0
.io.reactivex.Observable<Throwable>
subscribeReconnectFailure()
void
useCompressedMessages(boolean compressedMessages)
Methods inherited from class info.bitrich.xchangestream.service.ConnectableService
connect, setBeforeConnectionHandler
-
Field Details
-
DEFAULT_CONNECTION_TIMEOUT
-
DEFAULT_RETRY_DURATION
-
DEFAULT_IDLE_TIMEOUT
protected static final int DEFAULT_IDLE_TIMEOUT- See Also:
- Constant Field Values
-
uri
-
channels
-
-
Constructor Details
-
NettyStreamingService
-
NettyStreamingService
-
NettyStreamingService
-
NettyStreamingService
-
-
Method Details
-
openConnection
protected io.reactivex.Completable openConnection()- Specified by:
openConnection
in classConnectableService
-
getCustomHeaders
protected io.netty.handler.codec.http.DefaultHttpHeaders getCustomHeaders() -
disconnect
public io.reactivex.Completable disconnect() -
getChannelNameFromMessage
- Throws:
IOException
-
getSubscribeMessage
- Throws:
IOException
-
getUnsubscribeMessage
public abstract String getUnsubscribeMessage(String channelName, Object... args) throws IOException- Throws:
IOException
-
getSubscriptionUniqueId
-
messageHandler
Handler that receives incoming messages.- Parameters:
message
- Content of the message from the server.
-
sendMessage
-
subscribeReconnectFailure
-
subscribeConnectionSuccess
-
subscribeDisconnect
-
subscribeConnectionState
-
subscribeChannel
-
resubscribeChannels
public void resubscribeChannels() -
getChannel
-
handleMessage
-
handleError
-
handleIdle
protected void handleIdle(io.netty.channel.ChannelHandlerContext ctx) -
subscribeIdle
Observable which fires if the websocket is deemed idle, only fired ifidleTimeoutSeconds != 0
. -
handleChannelMessage
-
handleChannelError
-
getWebSocketClientExtensionHandler
protected io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler getWebSocketClientExtensionHandler() -
getWebSocketClientHandler
protected WebSocketClientHandler getWebSocketClientHandler(io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker handshaker, WebSocketClientHandler.WebSocketMessageHandler handler) -
isSocketOpen
public boolean isSocketOpen() -
useCompressedMessages
public void useCompressedMessages(boolean compressedMessages) -
setAcceptAllCertificates
public void setAcceptAllCertificates(boolean acceptAllCertificates) -
setEnableLoggingHandler
public void setEnableLoggingHandler(boolean enableLoggingHandler) -
setLoggingHandlerLevel
public void setLoggingHandlerLevel(io.netty.handler.logging.LogLevel loggingHandlerLevel) -
setSocksProxyHost
-
setSocksProxyPort
-
setAutoReconnect
public void setAutoReconnect(boolean autoReconnect)
-