Class OperatorFileWriter.Staged
java.lang.Object
com.ultikits.ultitools.config.document.OperatorFileWriter.Staged
- Enclosing class:
OperatorFileWriter
A verified write whose content is staged and not yet published - or, when nothing needed staging, the write's
settled result. Publishing re-reads the target under the lock every load and write holds, immediately before the
replacement, and replaces it only while it still holds exactly the bytes the write was verified against (an edit
saved while the content was being staged or while other files were being prepared is seen and kept: review round
1 IN-01, plan 17-65); a file the gate read absent is created exclusively, never replacing one that appeared.
A commit ends in one of three states, and restore() acts only on bytes the write still owns in that state
(#673: a failed commit grants no permission to bypass the file-ownership check):
- published - the target was replaced or created; the file holds this write's bytes until someone else writes it.
- unpublished - nothing was replaced: the file changed or appeared before the commit, or the commit failed
with any failure other than
AtomicConfigWriter.RestoreFailedException.AtomicConfigWriterthen leaves the target holding exactly what it held (a failed move, a failure before the target was opened, a failed in-place write that was put back from its backup) and a failed creation creates nothing, so no byte of this write is on disk and the file belongs to whoever writes it next - an operator's save included. - not put back - the in-place write failed after the target was opened and putting it back failed too
(
AtomicConfigWriter.RestoreFailedException): the target may hold part of this write, its backup is kept and one SEVERE names both. Only the operator decides what the file should hold; nothing here writes or deletes it again.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Pathprivate final ConfigDocumentprivate final Pathprivate booleanprivate booleanWhether the commit failed withAtomicConfigWriter.RestoreFailedException: the target may hold part of this write and its backup is kept (the not-put-back state).private final OwnedPathsprivate booleanWhether this write replaced or created the target (the published state).private final Stringprivate final Stringprivate final Stringprivate final OperatorFileWriter.Resultprivate final AtomicConfigWriter.StagedWrite -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateStaged(OperatorFileWriter.Result settled) privateStaged(Path file, Path absolute, OwnedPaths owned, List<String> keys, String rendered, ConfigDocument candidate, String read, String readText, AtomicConfigWriter.StagedWrite temporary) -
Method Summary
Modifier and TypeMethodDescriptioncommit()Publishes the staged content when the target still holds exactly the bytes the write was verified against (or, for a file the gate read absent, while no file exists there); otherwise the staged file is released and the result isOperatorFileWriter.Outcome.FILE_CHANGED, logged once.booleandiscard()Releases staged content that will not be committed; nothing on disk other than the staged temporary file is touched.booleanWhether verified content is staged and waits forcommit().readText()The text the staged content was verified against - exactly what the file held when the gate read it - so a caller undoing a published write can put back precisely those bytes.booleanrestore()Undoes this write after its batch failed, acting only on bytes the write still owns (class description, #673): unpublished - nothing is read, written or deleted: no byte of this write is on disk, so whatever the file holds now, an operator's save made while the batch was failing included, is kept; not put back - the file is read under the lock and never written or deleted: the SEVERE the failed put-back logged, the kept backup and the entity's "changed since it was read" protection until a reload stand, and the operator decides what the file holds; published - the text the write was verified against is put back (or the file it created removed) through the same last-moment check as the commit, only while the file still holds exactly what this write put there.(package private) static OperatorFileWriter.Stagedsettled(OperatorFileWriter.Result result) The settled result of a write that needed no staging, ornullwhile content is staged.
-
Field Details
-
settled
-
file
-
absolute
-
owned
-
keys
-
rendered
-
candidate
-
read
-
readText
-
temporary
-
finished
private boolean finished -
published
private boolean publishedWhether this write replaced or created the target (the published state). -
notPutBack
private boolean notPutBackWhether the commit failed withAtomicConfigWriter.RestoreFailedException: the target may hold part of this write and its backup is kept (the not-put-back state). Set only from that exception; every other failure leaves the write unpublished with no byte of it on disk.
-
-
Constructor Details
-
Staged
private Staged(Path file, Path absolute, OwnedPaths owned, List<String> keys, String rendered, ConfigDocument candidate, String read, String readText, AtomicConfigWriter.StagedWrite temporary) -
Staged
-
-
Method Details
-
settled
-
isPending
public boolean isPending()Whether verified content is staged and waits forcommit().- Returns:
falsewhen the write was settled without staging (refused, file changed, or unchanged)
-
readText
The text the staged content was verified against - exactly what the file held when the gate read it - so a caller undoing a published write can put back precisely those bytes.- Returns:
- the text read, or
nullwhen the file was absent or nothing is staged
-
settledResult
The settled result of a write that needed no staging, ornullwhile content is staged.- Returns:
- the result or
null
-
commit
Publishes the staged content when the target still holds exactly the bytes the write was verified against (or, for a file the gate read absent, while no file exists there); otherwise the staged file is released and the result isOperatorFileWriter.Outcome.FILE_CHANGED, logged once. A write that needed no staging returns its settled result. A staged write is committed at most once.The exception
AtomicConfigWriterthrows decides the state a failed commit leaves (class description): aAtomicConfigWriter.RestoreFailedExceptionrecords that the target was not put back; any other failure leaves the write unpublished. The failure is rethrown unchanged either way.- Returns:
- the outcome:
OperatorFileWriter.Outcome.WRITTENwhen published - Throws:
IOException- if the replacement or the creation fails (the target is then asAtomicConfigWriterleaves it)
-
restore
Undoes this write after its batch failed, acting only on bytes the write still owns (class description, #673):- unpublished - nothing is read, written or deleted: no byte of this write is on disk, so whatever the file holds now, an operator's save made while the batch was failing included, is kept;
- not put back - the file is read under the lock and never written or deleted: the SEVERE the failed put-back logged, the kept backup and the entity's "changed since it was read" protection until a reload stand, and the operator decides what the file holds;
- published - the text the write was verified against is put back (or the file it created removed) through the same last-moment check as the commit, only while the file still holds exactly what this write put there. A file that changed after this write replaced it - an operator's save - is kept as it is, and one WARNING names it (17-65 review round 1 R65-I3).
- Returns:
- whether the file now holds what it held before this write (also when nothing needed undoing); after a
failed put-back,
trueonly when the file holds exactly those bytes again - Throws:
IOException- if reading the file or putting the text back fails
-
discard
public boolean discard()Releases staged content that will not be committed; nothing on disk other than the staged temporary file is touched. Does nothing aftercommit()or for a settled write.- Returns:
- whether no staged temporary file is left behind
-