Skip to content

Commit 90d1c04

Browse files
committed
Updates from review.
Now the startupTime is a ZonedDateTime, which takes into account daylight savings. Signed-off-by: Simone Bordet <[email protected]>
1 parent 9bedc35 commit 90d1c04

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.net.URI;
2121
import java.net.URL;
2222
import java.time.Duration;
23-
import java.time.Instant;
23+
import java.time.ZonedDateTime;
2424
import java.util.ArrayList;
2525
import java.util.Arrays;
2626
import java.util.Collections;
@@ -79,7 +79,6 @@ public class Server extends Handler.Wrapper implements Attributes
7979
private static final Logger LOG = LoggerFactory.getLogger(Server.class);
8080
private static final String __serverInfo = "jetty/" + Server.getVersion();
8181

82-
private final Instant startupInstant = Instant.now();
8382
private final AttributeContainerMap _attributes = new AttributeContainerMap();
8483
private final ThreadPool _threadPool;
8584
private final Scheduler _scheduler;
@@ -89,6 +88,7 @@ public class Server extends Handler.Wrapper implements Attributes
8988
private final AutoLock _dateLock = new AutoLock();
9089
private final MimeTypes.Mutable _mimeTypes = new MimeTypes.Mutable();
9190
private String _serverInfo = __serverInfo;
91+
private ZonedDateTime startupTime;
9292
private boolean _openEarly = true;
9393
private boolean _stopAtShutdown;
9494
private boolean _dumpAfterStart;
@@ -549,28 +549,30 @@ public HttpField getDateField()
549549
}
550550

551551
/**
552-
* @return the UTC startup instant
552+
* @return the startup date and time in the system timezone, or {@code null} if not started
553553
*/
554-
public Instant getStartupInstant()
554+
public ZonedDateTime getStartupTime()
555555
{
556-
return startupInstant;
556+
return startupTime;
557557
}
558558

559559
/**
560-
* @return the time, in milliseconds, since this Server was created.
560+
* @return the time, in milliseconds, since this Server was started
561561
*/
562562
public long getUptimeMillis()
563563
{
564-
return Duration.between(startupInstant, Instant.now()).toMillis();
564+
return startupTime == null ? 0 : Duration.between(startupTime, ZonedDateTime.now()).toMillis();
565565
}
566566

567567
@Override
568568
protected void doStart() throws Exception
569569
{
570570
try
571571
{
572-
//If the Server should be stopped when the jvm exits, register
573-
//with the shutdown handler thread.
572+
startupTime = ZonedDateTime.now();
573+
574+
// If the Server should be stopped when the jvm exits,
575+
// register with the shutdown handler thread.
574576
if (getStopAtShutdown())
575577
ShutdownThread.register(this);
576578

@@ -697,6 +699,8 @@ protected void doStop() throws Exception
697699
if (LOG.isDebugEnabled())
698700
LOG.debug("doStop {}", this);
699701

702+
startupTime = null;
703+
700704
Throwable multiException = null;
701705

702706
if (getStopTimeout() > 0)

jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/jmx/ServerMBean.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public List<ContextHandler> getContexts()
6262
return getManagedObject().getDescendants(ContextHandler.class);
6363
}
6464

65-
@ManagedAttribute("The UTC startup instant")
65+
@ManagedAttribute("The startup date time in the system timezone")
6666
public String getStartupTime()
6767
{
68-
return getManagedObject().getStartupInstant().toString();
68+
return String.valueOf(getManagedObject().getStartupTime());
6969
}
7070

7171
@ManagedAttribute("The uptime duration in d:HH:mm:ss.SSS")

jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Uptime.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* Provide for a Uptime class that is compatible with Android, GAE, and the new Java 8 compact profiles
2121
*
22-
* @deprecated no replacement, will be removed
22+
* @deprecated no replacement, will be removed, functionality moved to the {@code Server} class.
2323
*/
2424
@Deprecated(forRemoval = true, since = "12.1.4")
2525
public class Uptime

0 commit comments

Comments
 (0)