Class ReservationRecord

java.lang.Object
com.iizix.server.upload.ReservationRecord

public final class ReservationRecord extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    final String
    The application session UUID that owns the reservation; also the quota key.
    final int
    The chunk size in force, bytes.
    final long
    Creation time in milliseconds.
    final int
    The number of files.
    final int
    The idle timeout in force when created, seconds.
    long
    The last activity time in milliseconds; rewritten on every accepted chunk.
    final int
    The maximum pause time in force when created, seconds.
    long
    The time the reservation became paused as a whole (no file receiving, at least one paused), in milliseconds; 0 while not paused.
    final String
    The reservation ID.
    final long
    The server process start time in milliseconds: a different value means a previous boot.
    final int
    The start timeout in force when created, seconds.
    static final String
    Reservation state: cancelled as a whole; its files are gone unless consumed.
    static final String
    Reservation state: every file is final.
    static final String
    Reservation state: open, accepting chunks.
    final String
    The authenticated user UUID, metadata only, empty for an undefined user.
    final int
    The format version this record was read with or will be written with.
    static final int
    The current format version.
  • Constructor Summary

    Constructors
    Constructor
    Description
    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).
    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 Type
    Method
    Description
    Deserializes from JSON.
    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.
    Serializes to JSON.
    Outputs to string.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • VERSION

      public static final int VERSION
      The current format version.
      See Also:
    • STATE_OPEN

      public static final String STATE_OPEN
      Reservation state: open, accepting chunks.
      See Also:
    • STATE_CANCELLED

      public static final String STATE_CANCELLED
      Reservation state: cancelled as a whole; its files are gone unless consumed.
      See Also:
    • STATE_CLOSED

      public static final String STATE_CLOSED
      Reservation state: every file is final.
      See Also:
    • version

      public final int version
      The format version this record was read with or will be written with.
    • rid

      public final String rid
      The reservation ID.
    • serverBoot

      public final long serverBoot
      The server process start time in milliseconds: a different value means a previous boot.
    • appSession

      public final String appSession
      The application session UUID that owns the reservation; also the quota key.
    • user

      public final String user
      The authenticated user UUID, metadata only, empty for an undefined user.
    • created

      public final long created
      Creation time in milliseconds.
    • idleSeconds

      public final int idleSeconds
      The idle timeout in force when created, seconds.
    • startSeconds

      public final int startSeconds
      The start timeout in force when created, seconds.
    • maxPauseSeconds

      public final int maxPauseSeconds
      The maximum pause time in force when created, seconds.
    • chunk

      public final int chunk
      The chunk size in force, bytes.
    • files

      public final int files
      The number of files.
    • lastActivity

      public long lastActivity
      The last activity time in milliseconds; rewritten on every accepted chunk.
    • state

      public String state
    • pausedSince

      public long pausedSince
      The 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

      public JSONObject toJSON()
      Serializes to JSON.
      Returns:
      The JSON object.
    • fromJSON

      public static ReservationRecord fromJSON(JSONObject jo)
      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

      public String toString()
      Outputs to string.
      Overrides:
      toString in class Object