Skip to content

Commit

Permalink
Allow JSONClient reconfiguration when connected
Browse files Browse the repository at this point in the history
The WebSocket library allows changing the ping interval immediately
during an ongoing connection. Expose this capability by adding a new
reconfigure() method to the JSONClient class.

To make use of this, set the updated PING_INTERVAL_PARAMETER on the
JSONConfiguration object passed to the JSONClient constructor, then
invoke JSONClient#reconfigure().
  • Loading branch information
robert-s-ubi committed Oct 21, 2022
1 parent b163057 commit 365b42a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ byte[] joinByteArrays(byte[] a, byte[] b) {
}

void configure() {
if (client == null) {
return;
}
client.setReuseAddr(configuration.getParameter(JSONConfiguration.REUSE_ADDR_PARAMETER, false));
client.setTcpNoDelay(
configuration.getParameter(JSONConfiguration.TCP_NO_DELAY_PARAMETER, false));
Expand Down
8 changes: 8 additions & 0 deletions ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ public JSONClient enableWSS(WssSocketBuilder wssSocketBuilder) {
return this;
}

/**
* Applies JSONConfiguration changes when already connected. Specifically, the WebSocket ping
* interval can be changed without reconnecting by calling this method.
*/
public void reconfigure() {
transmitter.configure();
}

@Override
public void addFeatureProfile(Profile profile) {
featureRepository.addFeatureProfile(profile);
Expand Down

0 comments on commit 365b42a

Please sign in to comment.