Skip to content

Commit

Permalink
Added net.throttleBoardType in server.properties to control throttling.
Browse files Browse the repository at this point in the history
  • Loading branch information
teejaydub committed Apr 19, 2024
1 parent aad7c57 commit d062ffa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public HardwareHandler(Holder holder, HardwareStateHolder stateHolder) {
holder.twitterWrapper, holder.limits.notificationPeriodLimitSec);
this.smsLogic = new SmsLogic(holder.smsWrapper, holder.limits.notificationPeriodLimitSec);
this.propertyLogic = new SetWidgetPropertyLogic(holder.sessionDao);
this.info = new BlynkInternalLogic(holder.otaManager, holder.limits.hardwareIdleTimeout);
this.info = new BlynkInternalLogic(holder.otaManager, holder.limits.hardwareIdleTimeout,
holder.props.getProperty("net.throttleBoardType", ""));

this.state = stateHolder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.handler.traffic.ChannelTrafficShapingHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -37,10 +38,12 @@ public class BlynkInternalLogic {

private final OTAManager otaManager;
private final int hardwareIdleTimeout;
private final String throttleBoardType;

public BlynkInternalLogic(OTAManager otaManager, int hardwareIdleTimeout) {
public BlynkInternalLogic(OTAManager otaManager, int hardwareIdleTimeout, String throttleBoardType) {
this.otaManager = otaManager;
this.hardwareIdleTimeout = hardwareIdleTimeout;
this.throttleBoardType = throttleBoardType;
}

public void messageReceived(ChannelHandlerContext ctx, HardwareStateHolder state, StringMessage message) {
Expand Down Expand Up @@ -98,6 +101,17 @@ private void parseHardwareInfo(ChannelHandlerContext ctx, String[] messageParts,
otaManager.initiateHardwareUpdate(ctx, state.userKey, hardwareInfo, dashBoard, device);
device.hardwareInfo = hardwareInfo;
dashBoard.updatedAt = System.currentTimeMillis();

if (this.throttleBoardType.isEmpty()
|| !hardwareInfo.boardType.equals(this.throttleBoardType)) {
try {
log.trace("Removing throttle for boardType '{}'.",
hardwareInfo.boardType, this.throttleBoardType);
ctx.pipeline().remove(ChannelTrafficShapingHandler.class);
} catch (Exception e) {
log.debug("Couldn't remove channel throttle.");
}
}
}

ctx.writeAndFlush(ok(msgId), ctx.voidPromise());
Expand Down

0 comments on commit d062ffa

Please sign in to comment.