Skip to content

Commit

Permalink
review write request load
Browse files Browse the repository at this point in the history
  • Loading branch information
lo92fr committed Apr 16, 2023
1 parent c91f721 commit 81d5e7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class SiemensHvacHandlerImpl extends BaseThingHandler implements SiemensH
private final @Nullable SiemensHvacConnector hvacConnector;
private final @Nullable SiemensHvacMetadataRegistry metaDataRegistry;
private final ChannelTypeRegistry channelTypeRegistry;
private long LastWrite = 0;

public SiemensHvacHandlerImpl(Thing thing, @Nullable SiemensHvacConnector hvacConnector,
@Nullable SiemensHvacMetadataRegistry metaDataRegistry, ChannelTypeRegistry channelTypeRegistry) {
Expand Down Expand Up @@ -97,7 +98,7 @@ public void initialize() {
}
});

pollingJob = scheduler.scheduleWithFixedDelay(this::pollingCode, 0, 10, TimeUnit.SECONDS);
pollingJob = scheduler.scheduleWithFixedDelay(this::pollingCode, 0, 60, TimeUnit.SECONDS);
}

@Override
Expand Down Expand Up @@ -217,17 +218,24 @@ private void ReadDp(String dp, String uid, String type, boolean async) {

try {
lockObj.lock();
logger.debug("Start read : {}", dp);

logger.info("Start read : {}", dp);
String request = "api/menutree/read_datapoint.json?Id=" + dp;

logger.debug("siemensHvac:ReadDp:DoRequest(): {}", request);
logger.info("siemensHvac:ReadDp:DoRequest(): {}", request);

if (async) {
if (lcHvacConnector != null) {
lcHvacConnector.DoRequest(request, new SiemensHvacCallback() {

@Override
public void execute(java.net.URI uri, int status, @Nullable Object response) {
// prevent async read if we just write so we have no overlaps
long now = System.currentTimeMillis();
if (now - LastWrite < 5000) {
return;
}

if (response instanceof JsonObject) {
DecodeReadDp((JsonObject) response, uid, dp, type);
}
Expand All @@ -246,7 +254,6 @@ public void execute(java.net.URI uri, int status, @Nullable Object response) {
} finally {
logger.debug("End read : {}", dp);
lockObj.unlock();

}
}

Expand All @@ -258,6 +265,9 @@ private void WriteDp(String dp, Type dpVal, String type) {

try {
lockObj.lock();
logger.info("Start write : {}", dp);
LastWrite = System.currentTimeMillis();

String valUpdate = "0";
String valUpdateEnum = "";

Expand All @@ -284,10 +294,10 @@ private void WriteDp(String dp, Type dpVal, String type) {
type);

if (lcHvacConnector != null) {
logger.debug("Write request for : {} ", valUpdate);
logger.info("Write request for : {} ", valUpdate);
JsonObject response = lcHvacConnector.DoRequest(request, null);

logger.debug("Write request response : {} ", response);
logger.info("Write request response : {} ", response);
}

} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void onError(@Nullable Request request, @Nullable SiemensHvacCallback cb)
lockObj.lock();
try {
startedRequest++;
logger.debug("StartedRequest : {}", startedRequest);
logger.info("StartedRequest : {}", startedRequest - completedRequest);

} finally {
lockObj.unlock();
Expand Down

0 comments on commit 81d5e7d

Please sign in to comment.