Package io.openems.common.websocket
Class AbstractWebsocketClient<T extends WsData>
java.lang.Object
io.openems.common.websocket.AbstractWebsocket<T>
io.openems.common.websocket.AbstractWebsocketClient<T>
- Type Parameters:
T
- the type of websocket attachments inheritingWsData
- Direct Known Subclasses:
WebsocketClient
A Websocket Client implementation that automatically tries to reconnect a
closed connection.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final org.java_websocket.drafts.Draft
static final Proxy
protected final org.java_websocket.client.WebSocketClient
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractWebsocketClient
(String name, URI serverUri) protected
protected
protected
AbstractWebsocketClient
(String name, URI serverUri, org.java_websocket.drafts.Draft draft, Map<String, String> httpHeaders, Proxy proxy) -
Method Summary
Modifier and TypeMethodDescriptionprotected OnInternalError
Callback for internal error.boolean
sendMessage
(JsonrpcMessage message) Sends a JSON-RPC message.void
sendMessageOrError
(JsonrpcMessage message) Sends aJsonrpcMessage
.sendRequest
(JsonrpcRequest request) Sends a JSON-RPC Request and returns a future Response.void
start()
Starts the websocket client.void
Starts the websocket client; waiting till it started.void
stop()
Stops the websocket client.Methods inherited from class io.openems.common.websocket.AbstractWebsocket
createWsData, execute, getName, getOnClose, getOnError, getOnNotification, getOnOpen, getOnRequest, handleInternalErrorAsync, handleInternalErrorSync, logError, logInfo, logWarn
-
Field Details
-
NO_HTTP_HEADERS
-
NO_PROXY
-
DEFAULT_DRAFT
public static final org.java_websocket.drafts.Draft DEFAULT_DRAFT -
ws
protected final org.java_websocket.client.WebSocketClient ws
-
-
Constructor Details
-
AbstractWebsocketClient
-
AbstractWebsocketClient
-
AbstractWebsocketClient
-
AbstractWebsocketClient
-
-
Method Details
-
start
public void start()Starts the websocket client.- Overrides:
start
in classAbstractWebsocket<T extends WsData>
-
startBlocking
Starts the websocket client; waiting till it started.- Throws:
InterruptedException
- on waiting error
-
stop
public void stop()Stops the websocket client.- Overrides:
stop
in classAbstractWebsocket<T extends WsData>
-
getOnInternalError
Description copied from class:AbstractWebsocket
Callback for internal error.- Specified by:
getOnInternalError
in classAbstractWebsocket<T extends WsData>
- Returns:
- the
OnInternalError
callback
-
sendMessageOrError
Sends aJsonrpcMessage
.- Parameters:
message
- theJsonrpcMessage
- Throws:
OpenemsException
- on error, e.g. if the websocket is not connected
-
sendMessage
Sends a JSON-RPC message. Returns true if sending was successful, otherwise false. Also logs a warning in that case.- Parameters:
message
- theJsonrpcMessage
.- Returns:
- true if sending was successful
-
sendRequest
public CompletableFuture<JsonrpcResponseSuccess> sendRequest(JsonrpcRequest request) throws OpenemsError.OpenemsNamedException Sends a JSON-RPC Request and returns a future Response.- Parameters:
request
- the JSON-RPC Request- Returns:
- the future JSON-RPC Response
- Throws:
OpenemsError.OpenemsNamedException
- on error
-