Class ReservationRecord
java.lang.Object
com.iizix.server.upload.ReservationRecord
The on-disk record of one upload reservation,
reservation.json in the reservation's staging directory. Everything a cold-start sweep needs to tell an orphan from an in-flight reservation is here, so no in-memory state is required to make that decision.Format version 1. The v field exists so that a later version can add fields (for instance per-chunk digests for re-pick resume) without a format break; a reader of version 1 never sees them.
- Author:
- Christopher Mindus
Field Summary
FieldsModifier and TypeFieldDescriptionfinal StringThe application session UUID that owns the reservation; also the quota key.final intThe chunk size in force, bytes.final longCreation time in milliseconds.final intThe number of files.final intThe idle timeout in force when created, seconds.longThe last activity time in milliseconds; rewritten on every accepted chunk.final intThe maximum pause time in force when created, seconds.longThe time the reservation became paused as a whole (no file receiving, at least one paused), in milliseconds; 0 while not paused.final StringThe reservation ID.final longThe server process start time in milliseconds: a different value means a previous boot.final intThe start timeout in force when created, seconds.static final StringReservation state: cancelled as a whole; its files are gone unless consumed.static final StringReservation state: every file is final.static final StringReservation state: open, accepting chunks.final StringThe authenticated user UUID, metadata only, empty for an undefined user.final intThe format version this record was read with or will be written with.static final intThe current format version.Constructor Summary
ConstructorsConstructorDescriptionReservationRecord(String rid, long serverBoot, String appSession, String user, long created, int idleSeconds, int startSeconds, int chunk, int files) Constructor for a new reservation with the default maximum pause time (ServerSettings.DEFAULT_UPLOAD_MAX_PAUSE).ReservationRecord(String rid, long serverBoot, String appSession, String user, long created, int idleSeconds, int startSeconds, int maxPauseSeconds, int chunk, int files) Constructor for a new reservation.Method Summary
Modifier and TypeMethodDescriptionstatic ReservationRecordfromJSON(JSONObject jo) Deserializes from JSON.booleanisInFlight(long thisBoot, long now) Checks if the reservation is in flight at a point in time: open, of this server process, and either paused within its maximum pause time or active within its idle timeout.toJSON()Serializes to JSON.toString()Outputs to string.
Field Details
VERSION
public static final int VERSIONThe current format version.- See Also:
STATE_OPEN
STATE_CANCELLED
Reservation state: cancelled as a whole; its files are gone unless consumed.- See Also:
STATE_CLOSED
version
public final int versionThe format version this record was read with or will be written with.rid
The reservation ID.serverBoot
public final long serverBootThe server process start time in milliseconds: a different value means a previous boot.appSession
The application session UUID that owns the reservation; also the quota key.user
The authenticated user UUID, metadata only, empty for an undefined user.created
public final long createdCreation time in milliseconds.idleSeconds
public final int idleSecondsThe idle timeout in force when created, seconds.startSeconds
public final int startSecondsThe start timeout in force when created, seconds.maxPauseSeconds
public final int maxPauseSecondsThe maximum pause time in force when created, seconds.chunk
public final int chunkThe chunk size in force, bytes.files
public final int filesThe number of files.lastActivity
public long lastActivityThe last activity time in milliseconds; rewritten on every accepted chunk.state
pausedSince
public long pausedSinceThe time the reservation became paused as a whole (no file receiving, at least one paused), in milliseconds; 0 while not paused. While set, the maximum pause time applies instead of the idle timeout.
Constructor Details
ReservationRecord
public ReservationRecord(String rid, long serverBoot, String appSession, String user, long created, int idleSeconds, int startSeconds, int chunk, int files) Constructor for a new reservation with the default maximum pause time (ServerSettings.DEFAULT_UPLOAD_MAX_PAUSE).- Parameters:
rid- The reservation ID.serverBoot- The server process start time.appSession- The owning application session UUID.user- The user UUID, empty for none.created- The creation time.idleSeconds- The idle timeout in seconds.startSeconds- The start timeout in seconds.chunk- The chunk size in bytes.files- The file count.
ReservationRecord
public ReservationRecord(String rid, long serverBoot, String appSession, String user, long created, int idleSeconds, int startSeconds, int maxPauseSeconds, int chunk, int files) Constructor for a new reservation.- Parameters:
rid- The reservation ID.serverBoot- The server process start time.appSession- The owning application session UUID.user- The user UUID, empty for none.created- The creation time.idleSeconds- The idle timeout in seconds.startSeconds- The start timeout in seconds.maxPauseSeconds- The maximum pause time in seconds.chunk- The chunk size in bytes.files- The file count.
Method Details
toJSON
fromJSON
Deserializes from JSON.- Parameters:
jo- The JSON object.- Returns:
- The record.
- Throws:
JSONException- If a required field is missing or of the wrong type.
isInFlight
public boolean isInFlight(long thisBoot, long now) Checks if the reservation is in flight at a point in time: open, of this server process, and either paused within its maximum pause time or active within its idle timeout. Whether its application session is still alive is the caller's knowledge, not the record's.- Parameters:
thisBoot- The current server process start time.now- The current time in milliseconds.- Returns:
- true if in flight by the record alone.
toString