You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tv...@apache.org on 2026/03/19 17:44:02 UTC
(commons-jcs) 07/11: Change type of UDPDiscoveryAttributes.maxIdleTime to Duration
This is an automated email from the ASF dual-hosted git repository.
tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git
commit c151837c1e8f27c8374326694322518002e5d1af
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Thu Mar 19 17:11:51 2026 +0100
Change type of UDPDiscoveryAttributes.maxIdleTime to Duration
---
.../jcs4/utils/discovery/UDPDiscoveryAttributes.java | 16 +++++++++-------
.../jcs4/utils/discovery/UDPDiscoveryService.java | 6 +++---
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryAttributes.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryAttributes.java
index b9f1a199..452b1b78 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryAttributes.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryAttributes.java
@@ -1,5 +1,7 @@
package org.apache.commons.jcs4.utils.discovery;
+import java.time.Duration;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -47,7 +49,7 @@ public record UDPDiscoveryAttributes(
int udpTTL,
/** Amount of time before we remove services that we haven't heard from */
- int maxIdleTimeSec
+ Duration maxIdleTime
)
{
/** Default udp discovery address */
@@ -57,7 +59,7 @@ public record UDPDiscoveryAttributes(
private static final int DEFAULT_UDP_DISCOVERY_PORT = 5678;
/** Default amount of time before we remove services that we haven't heard from */
- private static final int DEFAULT_MAX_IDLE_TIME_SEC = 180;
+ private static final Duration DEFAULT_MAX_IDLE_TIME = Duration.ofSeconds(180);
/** Record with all defaults set */
private static final UDPDiscoveryAttributes DEFAULT = new UDPDiscoveryAttributes(
@@ -67,7 +69,7 @@ public record UDPDiscoveryAttributes(
null,
DEFAULT_UDP_DISCOVERY_PORT,
0,
- DEFAULT_MAX_IDLE_TIME_SEC
+ DEFAULT_MAX_IDLE_TIME
);
/**
@@ -87,7 +89,7 @@ public record UDPDiscoveryAttributes(
{
this(lac.getTcpListenerHost(), lac.getTcpListenerPort(), lac.getUdpDiscoveryAddr(),
lac.getUdpDiscoveryInterface(), lac.getUdpDiscoveryPort(), lac.getUdpTTL(),
- defaults().maxIdleTimeSec());
+ defaults().maxIdleTime());
}
/**
@@ -107,7 +109,7 @@ public record UDPDiscoveryAttributes(
defaults().udpDiscoveryInterface(),
udpDiscoveryPort,
udpTTL,
- defaults().maxIdleTimeSec()
+ defaults().maxIdleTime()
);
}
@@ -126,7 +128,7 @@ public record UDPDiscoveryAttributes(
udpDiscoveryInterface(),
udpDiscoveryPort(),
udpTTL(),
- maxIdleTimeSec()
+ maxIdleTime()
);
}
@@ -142,7 +144,7 @@ public record UDPDiscoveryAttributes(
buf.append("\n ServicePort = [").append(servicePort()).append("]");
buf.append("\n UdpDiscovery = [").append(udpDiscoveryAddr()).append("]");
buf.append("\n UdpDiscoveryPort = [").append(udpDiscoveryPort()).append("]");
- buf.append("\n MaxIdleTimeSec = [").append(maxIdleTimeSec()).append("]");
+ buf.append("\n MaxIdleTimeSec = [").append(maxIdleTime()).append("]");
return buf.toString();
}
}
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryService.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryService.java
index 65ae7f0e..838d0541 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryService.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryService.java
@@ -260,11 +260,11 @@ public class UDPDiscoveryService
// the listeners need to be notified.
getDiscoveredServices().stream()
.filter(service -> {
- if (now.isAfter(service.getLastHearFromTime().plusSeconds(getUdpDiscoveryAttributes().maxIdleTimeSec())))
+ if (now.isAfter(service.getLastHearFromTime().plus(getUdpDiscoveryAttributes().maxIdleTime())))
{
log.info( "Removing service, since we haven't heard from it in "
+ "{0} seconds. service = {1}",
- getUdpDiscoveryAttributes().maxIdleTimeSec(), service );
+ getUdpDiscoveryAttributes().maxIdleTime().toSeconds(), service );
return true;
}
@@ -452,7 +452,7 @@ public class UDPDiscoveryService
// delay and the idle time.
this.cleanupTaskFuture = scheduledExecutor.scheduleAtFixedRate(
this::cleanup, 0,
- getUdpDiscoveryAttributes().maxIdleTimeSec(), TimeUnit.SECONDS);
+ getUdpDiscoveryAttributes().maxIdleTime().toSeconds(), TimeUnit.SECONDS);
}
/**