Skip to content

Commit

Permalink
Fixing linty
Browse files Browse the repository at this point in the history
  • Loading branch information
grafnu committed Nov 6, 2024
1 parent 0a40282 commit 5dac5c4
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ public class MqttPublisher implements MessagePublisher {
private static final int INITIALIZE_TIME_MS = 20000;
private static final String BROKER_URL_FORMAT = "%s://%s:%s";
private static final int PUBLISH_THREAD_COUNT = 10;
private static final int TOKEN_EXPIRATION_SEC = 60;
private static final int TOKEN_EXPIRATION_MS = TOKEN_EXPIRATION_SEC * 1000;
private static final Duration TOKEN_EXPIRATION = Duration.ofHours(1);
private static final String TICKLE_TOPIC = "events/udmi";
private static final long TICKLE_PERIOD_SEC = 10;
private static final String REFLECTOR_PUBLIC_KEY = "reflector/rsa_public.pem";
Expand Down Expand Up @@ -150,7 +149,7 @@ public class MqttPublisher implements MessagePublisher {
providerHostname = getProviderHostname(config);
topicBase = getTopicBase();
clientId = catchToNull(() -> config.reflector_endpoint.client_id);
LOG.info(deviceId + " token expiration sec " + TOKEN_EXPIRATION_SEC);
LOG.info(deviceId + " token expiration sec " + TOKEN_EXPIRATION.getSeconds());
certManager = getCertManager();
mqttClient = newMqttClient(deviceId);
mqttClientId = mqttClient.getClientId();
Expand Down Expand Up @@ -309,7 +308,8 @@ private synchronized void publishCore(String deviceId, String topic, String payl
publishRaw(deviceId, topic, payload, start);
}

private synchronized void publishRaw(String deviceId, String topic, String payload, Instant start) {
private synchronized void publishRaw(String deviceId, String topic, String payload,
Instant start) {
try {
publisherQueueSize.decrementAndGet();
if (!connectWait.tryAcquire(INITIALIZE_TIME_MS, TimeUnit.MILLISECONDS)) {
Expand Down Expand Up @@ -499,7 +499,7 @@ private char[] getHashPassword(String audience) {
}

private synchronized void maybeRefreshJwt() {
long refreshTime = mqttTokenSetTimeMs + TOKEN_EXPIRATION_MS / 2;
long refreshTime = mqttTokenSetTimeMs + TOKEN_EXPIRATION.toMillis() / 2;
long currentTimeMillis = System.currentTimeMillis();
long remaining = refreshTime - currentTimeMillis;
LOG.debug(deviceId + " remaining until refresh " + remaining);
Expand Down Expand Up @@ -606,7 +606,7 @@ private String createJwt(String projectId, byte[] privateKeyBytes, String algori
JwtBuilder jwtBuilder =
Jwts.builder()
.setIssuedAt(now.toDate())
.setExpiration(now.plusMillis(TOKEN_EXPIRATION_MS).toDate())
.setExpiration(now.plusMillis((int) TOKEN_EXPIRATION.toMillis()).toDate())
.setAudience(projectId);

LOG.info(format("Creating jwt %s key with audience %s", algorithm, projectId));
Expand Down

0 comments on commit 5dac5c4

Please sign in to comment.