Class IiziGoInstances
java.lang.Object
com.iizix.jetty.IiziGoInstances
The registry of the iiziGo instances of the user that run now, and the port offsets their workspaces claim (CC-FIX-PORT-RANGE-A, R-D-5 and R-D-6 of CC-SURVEY-PORT-RANGE). Two iiziGo side by side - two workspaces, or a UI harness beside the owner's iiziGo - share four fixed things of the user: the web server ports, the QUIC work directory, the Derby server on 1527 and the WebView2 cache folder. This registry is what each of them asks.
~/.iizi/com.iizigo/instances/<pid>.properties: one file per live iiziGo, written once its web server has bound (workspace, workspace ID, ports, build, start time), deleted at its exit; a file whose process is gone is pruned by the next reader. The process start time is recorded too, so that a PID the operating system reused is not taken for the iiziGo that wrote the file.~/.iizi/com.iizigo/ports.properties: the offset of the port range each workspace bound last (its claim), so that a workspace falling back from the first ports avoids the offsets other workspaces use. A workspace is one claim: a claim that names the same workspace directory under another ID (an ID an earlier iiziGo generated and lost before it was saved) is replaced, never left to count as another workspace (CC-FIX-PWA-PAGE-PORTS, ruling PW-5). The first ports of the ranges, the ones of Preferences > IIZI > Web Server, are tried first whatever the claims say: they are taken whenever they are free.
No socket and no new dependency: plain files, written to a temporary name and renamed onto the real one; the claims file is changed under a file lock. The class lives in com.iizix.jetty, beside the port range it serves, so that its decisions are tested headless in com.iizix.jetty.tests; the iiziGo plug-ins call it.
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumWhat a starting iiziGo does with the WebView2 cache folder (R-D-17).static enumWhat an exiting iiziGo does with the Derby network server (R-D-16).static final recordOne live iiziGo.Constructor Summary
ConstructorsConstructorDescriptionConstructor for the default directory.IiziGoInstances(File dir, long ownPid) Constructor.Method Summary
Modifier and TypeMethodDescriptioncacheRotation(boolean buildChanged, boolean othersLive) Decides what a starting iiziGo does with the WebView2 cache folder (R-D-17).static int[]candidateOffsets(int count, int sticky, Collection<Integer> claimedByOthers) Orders the offsets of a port range for a start: first offset 0, the ports of Preferences > IIZI > Web Server, whatever the claims and the sticky offset say - they are taken whenever they are free (ruling PW-5 of CC-FIX-PWA-PAGE-PORTS, which supersedes the sticky-first order of R-D-4/R-D-5); then the workspace's own sticky offset when it is inside the range; then every offset no other workspace claims; then the offsets other workspaces claim - a port is taken from another workspace only when nothing else is free.voidRecords the offset a workspace bound.claimedByOthers(String workspaceId) Gets the offsets other workspaces claim.claimedWorkspace(String workspaceId) Gets the workspace directory recorded with a claim.claims()Gets the claims: the offset each workspace bound last.static FileGets the default iiziGo user directory,~/.iizi/com.iizigo.static IiziGoInstances.DerbyExitderbyExit(boolean autostop, boolean startedHere, boolean leftRunningByIiziGo, boolean othersLive) Decides what an exiting iiziGo does with the Derby network server (R-D-16): the last iiziGo out stops it, and no iiziGo stops a Derby another live iiziGo uses.voidRemoves the claim of a workspace ("Forget" on the Preferences page).holderOf(int port) Gets the live iiziGo, other than this one, that holds a port.Gets the other iiziGo instances that run now, pruning the files of those that are gone.voidregister(IiziGoInstances.Instance instance) Registers this iiziGo, replacing an earlier registration of it (a restart of its web server).self()Gets the registration of this iiziGo.voidRemoves the registration of this iiziGo.
Constructor Details
IiziGoInstances
public IiziGoInstances()Constructor for the default directory.IiziGoInstances
Constructor.- Parameters:
dir- The iiziGo user directory: the registry lives ininstancesandports.propertiesunder it.ownPid- The process ID that counts as "this iiziGo".
Method Details
defaultDirectory
Gets the default iiziGo user directory,~/.iizi/com.iizigo.- Returns:
- The directory (it may not exist yet).
register
Registers this iiziGo, replacing an earlier registration of it (a restart of its web server).- Parameters:
instance- The instance; its PID must be this process's.
unregister
public void unregister()Removes the registration of this iiziGo.self
Gets the registration of this iiziGo.- Returns:
- The instance, null when not registered.
liveOthers
Gets the other iiziGo instances that run now, pruning the files of those that are gone.- Returns:
- The live instances other than this one, ordered by PID.
holderOf
Gets the live iiziGo, other than this one, that holds a port.- Parameters:
port- The TCP or UDP port.- Returns:
- The instance, null when no other live iiziGo holds it.
claims
claimedWorkspace
claimedByOthers
claim
Records the offset a workspace bound. A claim of the same workspace directory under another ID is removed: it is this workspace's, left by an iiziGo that generated its ID and never saved it (killed, or ended before its preferences were written), and it must not count as another workspace's claim (ruling PW-5: three such claims moved the owner's iiziGo to 2801 and then 2802 after two kills).- Parameters:
workspaceId- The workspace ID.workspace- The workspace directory, for messages and for the match above.offset- The offset.
forget
Removes the claim of a workspace ("Forget" on the Preferences page).- Parameters:
workspaceId- The workspace ID.
candidateOffsets
Orders the offsets of a port range for a start: first offset 0, the ports of Preferences > IIZI > Web Server, whatever the claims and the sticky offset say - they are taken whenever they are free (ruling PW-5 of CC-FIX-PWA-PAGE-PORTS, which supersedes the sticky-first order of R-D-4/R-D-5); then the workspace's own sticky offset when it is inside the range; then every offset no other workspace claims; then the offsets other workspaces claim - a port is taken from another workspace only when nothing else is free.- Parameters:
count- The number of offsets in the range, at least 1.sticky- The workspace's sticky offset, -1 for none.claimedByOthers- The offsets other workspaces claim.- Returns:
- The offsets in the order to try, each once.
derbyExit
public static IiziGoInstances.DerbyExit derbyExit(boolean autostop, boolean startedHere, boolean leftRunningByIiziGo, boolean othersLive) Decides what an exiting iiziGo does with the Derby network server (R-D-16): the last iiziGo out stops it, and no iiziGo stops a Derby another live iiziGo uses. A Derby this process did not start is stopped only when an iiziGo started it (itsderbyserver.pidnames a live process) - never one the user started by hand.- Parameters:
autostop- The preference "auto-stop" of the database server.startedHere-truewhen this process started the Derby that runs.leftRunningByIiziGo-truewhen a Derby started by an earlier iiziGo still runs.othersLive-truewhen another iiziGo runs now.- Returns:
- The action.
cacheRotation
Decides what a starting iiziGo does with the WebView2 cache folder (R-D-17).- Parameters:
buildChanged-truewhen the folder was last set up by another build.othersLive-truewhen another iiziGo runs now.- Returns:
- The action.