Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URL;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -46,7 +48,6 @@
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.Jetty;
import org.eclipse.jetty.util.NanoTime;
import org.eclipse.jetty.util.Uptime;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.annotation.Name;
Expand Down Expand Up @@ -77,6 +78,7 @@ public class Server extends Handler.Wrapper implements Attributes
private static final Logger LOG = LoggerFactory.getLogger(Server.class);
private static final String __serverInfo = "jetty/" + Server.getVersion();

private final Instant startupInstant = Instant.now();
private final AttributeContainerMap _attributes = new AttributeContainerMap();
private final ThreadPool _threadPool;
private final Scheduler _scheduler;
Expand Down Expand Up @@ -252,10 +254,10 @@ public File getTempDirectory()
* {@link ContextHandler}. A {@code Server}'s {@link Context}:
* <ul>
* <li>has a {@code null} {@link Context#getContextPath() context path}</li>
* <li>returns the {@link ClassLoader} that loaded the {@link Server} from {@link Context#getClassLoader()}.</li>
* <li>returns the {@link ClassLoader} that loaded the Server from {@link Context#getClassLoader()}.</li>
* <li>is an {@link java.util.concurrent.Executor} that delegates to the {@link Server#getThreadPool() Server ThreadPool}</li>
* <li>is a {@link org.eclipse.jetty.util.Decorator} using the {@link DecoratedObjectFactory} found
* as a {@link #getBean(Class) bean} of the {@link Server}</li>
* as a {@link #getBean(Class) bean} of the Server</li>
* <li>has the same {@link #getTempDirectory() temporary director} of the {@link Server#getTempDirectory() server}</li>
* </ul>
*/
Expand Down Expand Up @@ -529,20 +531,36 @@ public HttpField getDateField()
long seconds = now / 1000;
DateField df = _dateField;

if (df == null || df._seconds != seconds)
if (df == null || df.seconds != seconds)
{
try (AutoLock ignore = _dateLock.lock())
{
df = _dateField;
if (df == null || df._seconds != seconds)
if (df == null || df.seconds != seconds)
{
HttpField field = new ResponseHttpFields.PersistentPreEncodedHttpField(HttpHeader.DATE, DateGenerator.formatDate(now));
_dateField = new DateField(seconds, field);
return field;
}
}
}
return df._dateField;
return df.dateField;
}

/**
* @return the UTC startup instant
*/
public Instant getStartupInstant()
{
return startupInstant;
}

/**
* @return the time, in milliseconds, since this Server was created.
*/
public long getUptimeMillis()
{
return Duration.between(startupInstant, Instant.now()).toMillis();
}

@Override
Expand Down Expand Up @@ -614,7 +632,7 @@ protected void doStart() throws Exception

if (_dryRun)
{
LOG.info(String.format("Started(dry run) %s @%dms", this, Uptime.getUptime()));
LOG.info("Started(dry run) {} @{}ms", this, getUptimeMillis());
throw new StopException();
}

Expand All @@ -634,7 +652,7 @@ protected void doStart() throws Exception
}

multiException.ifExceptionThrow();
LOG.info(String.format("Started %s @%dms", this, Uptime.getUptime()));
LOG.info("Started {} @{}ms", this, getUptimeMillis());
}
catch (Throwable th)
{
Expand Down Expand Up @@ -674,7 +692,7 @@ protected void doStop() throws Exception
if (isDumpBeforeStop())
dumpStdErr();

LOG.info(String.format("Stopped %s", this));
LOG.info("Stopped {}", this);
if (LOG.isDebugEnabled())
LOG.debug("doStop {}", this);

Expand Down Expand Up @@ -886,18 +904,7 @@ public static void main(String... args)
System.err.println(getVersion());
}

private static class DateField
{
final long _seconds;
final HttpField _dateField;

public DateField(long seconds, HttpField dateField)
{
super();
_seconds = seconds;
_dateField = dateField;
}
}
private record DateField(long seconds, HttpField dateField) {}

private static class DynamicErrorHandler extends ErrorHandler {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.jetty.server.jmx;

import java.time.Duration;
import java.time.Instant;
import java.util.List;

import org.eclipse.jetty.server.Server;
Expand All @@ -26,12 +25,9 @@
@ManagedObject
public class ServerMBean extends Handler.AbstractMBean
{
private final Instant startup;

public ServerMBean(Object managedObject)
{
super(managedObject);
startup = Instant.now();
}

@Override
Expand Down Expand Up @@ -69,13 +65,13 @@ public List<ContextHandler> getContexts()
@ManagedAttribute("The UTC startup instant")
public String getStartupTime()
{
return startup.toString();
return getManagedObject().getStartupInstant().toString();
}

@ManagedAttribute("The uptime duration in d:HH:mm:ss.SSS")
public String getUpTime()
{
Duration upTime = Duration.between(startup, Instant.now());
Duration upTime = Duration.ofMillis(getManagedObject().getUptimeMillis());
return "%d:%02d:%02d:%02d.%03d".formatted(
upTime.toDaysPart(),
upTime.toHoursPart(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

/**
* Provide for a Uptime class that is compatible with Android, GAE, and the new Java 8 compact profiles
*
* @deprecated no replacement, will be removed
*/
@Deprecated(forRemoval = true, since = "12.1.3")
public class Uptime
{
public static final int NOIMPL = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.concurrent.CopyOnWriteArrayList;

import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.Uptime;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.thread.AutoLock;
Expand Down Expand Up @@ -244,7 +243,7 @@ private void setStarted()
{
_state = State.STARTED;
if (LOG.isDebugEnabled())
LOG.debug("STARTED @{}ms {}", Uptime.getUptime(), this);
LOG.debug("STARTED {}", this);
for (EventListener listener : _eventListeners)
{
if (listener instanceof Listener)
Expand Down

This file was deleted.