Class MemoryAgent
- Namespace
- McServerLauncher.Services
- Assembly
- McServerLauncher.dll
The agent that holds a server's heap tighter while the machine is short of memory: getting it into the server's folder, onto the command line, and out again when it must not run.
public static class MemoryAgent
- Inheritance
-
MemoryAgent
- Inherited Members
Remarks
The agent is a 10 KB jar built from agent/ and embedded in the app, so nothing is downloaded
and no JDK is needed to publish. It only reads a small control file and writes a status file in the
server's own hidden folder; it opens no socket and calls no System.gc().
It can stop a server from starting (a JVM refuses to start over an agent it cannot load), so there are three ways to turn it off, and a way for it to turn itself off:
- a Manual server never gets it, and neither does one on a Java that is not HotSpot or is older than 12 (where the profile it adjusts does not apply);
- the setting "adjust memory live" in Settings, and the environment variable
MCSL_NO_AGENT=1; - a start that dies within a minute of an agent error is noted against the pair of that Java and this agent, and the server is restarted without it, here and in every start after.
Fields
ControlFileName
The file the app writes and the agent reads.
public const string ControlFileName = "control"
Field Value
DisableVariable
The environment variable that turns the agent off for everything started from here.
public const string DisableVariable = "MCSL_NO_AGENT"
Field Value
JarFileName
The jar's file name inside the server's hidden memory folder.
public const string JarFileName = "mcsl-agent.jar"
Field Value
StartupWindow
How long after starting an agent error still counts as the agent's doing.
public static readonly TimeSpan StartupWindow
Field Value
StatusFileName
The file the agent writes and the app reads.
public const string StatusFileName = "status.json"
Field Value
Properties
EmbeddedHash
SHA-256 of the embedded jar, in lower case hex.
public static string EmbeddedHash { get; }
Property Value
FailuresPath
Where the failures are remembered. Settable so tests can point it at a temp folder.
public static string FailuresPath { get; set; }
Property Value
Flag
The flag that loads the agent, with the path relative to the server's folder.
public static string Flag { get; }
Property Value
Methods
HasFailed(int, string)
True when this Java has refused this agent before.
public static bool HasFailed(int javaMajor, string hash)
Parameters
Returns
Install(string)
Puts the jar in the server's memory folder, replacing one that is missing or is not this build's, and writes the control file for the margins the server starts with. Returns false when it cannot, which means the flag must not be given: an agent that cannot be loaded stops the JVM.
public static bool Install(string serverFolder)
Parameters
serverFolderstring
Returns
IsLoadError(string)
True for a console line that says the JVM could not load an agent.
public static bool IsLoadError(string line)
Parameters
linestring
Returns
Remarks
The three ways a JVM says so: it cannot open the jar, the agent library failed to start, and the
native method that runs premain failed. The lines carry no log prefix, so they are matched
by their own words at the very start of the line, which a player's chat (always prefixed) never is.
ReadStatus(string, DateTime, TimeSpan)
The agent's latest report, or null when there is none or it is older than maxAge.
public static AgentStatus? ReadStatus(string serverFolder, DateTime nowUtc, TimeSpan maxAge)
Parameters
Returns
RecordFailure(int, string)
Notes that this Java could not load this agent, so no start uses it again.
public static void RecordFailure(int javaMajor, string hash)
Parameters
ShouldUse(ServerConfig, JavaRuntime, bool, Func<string, string?>?)
True when this server should start with the agent: it is Automatic, on a HotSpot from Java 12, the setting is on, the variable is not set, and this Java has not refused this agent before.
public static bool ShouldUse(ServerConfig config, JavaService.JavaRuntime java, bool settingEnabled, Func<string, string?>? environment = null)
Parameters
configServerConfigjavaJavaService.JavaRuntimesettingEnabledboolenvironmentFunc<string, string>
Returns
WriteControl(string, HeapMargins)
Writes the control file for these margins, by writing a temporary file and renaming it.
public static void WriteControl(string serverFolder, HeapMargins margins)
Parameters
serverFolderstringmarginsHeapMargins