Class FileUploadModule

java.lang.Object
com.iizix.server.upload.FileUploadModule
All Implemented Interfaces:
IServerModule<Object>

public final class FileUploadModule extends Object implements IServerModule<Object>
The server module of the upload service: owns the staging store, the server-global registry, the chunk servlet and the sweeps, and routes the registry's events to the application session that owns each reservation.

Lifecycle, in the PushNotificationModule shape: initialize(IServer) builds the store and the registry; onServerReady(IServer) runs the cold-start sweep (every directory is a previous boot's: app sessions never outlive the process), registers the servlet when $upload.allow is on (mount-time gate; the reservation-time gate is the service's and requires this mount too, isRouteAvailable()), registers a server dispose listener that cancels every live reservation, and starts the periodic sweep; dispose() unregisters the servlet and stops the sweep.

Author:
Christopher Mindus
  • Constructor Details

    • FileUploadModule

      public FileUploadModule()
      Constructor for the server: everything is built in initialize(IServer).
  • Method Details

    • getInstance

      public static FileUploadModule getInstance()
      Gets the live module.
      Returns:
      The module, or null if the server has not initialized it or has disposed of it.
    • getModuleName

      public String getModuleName()
      --- IServerModule ---
      Specified by:
      getModuleName in interface IServerModule<Object>
      Returns:
      A name such as "Load Balancer" or "License Manager".
    • getModuleDescripion

      public String getModuleDescripion()
      Description copied from interface: IServerModule
      Gets the description.
      Specified by:
      getModuleDescripion in interface IServerModule<Object>
      Returns:
      A descriptive text of the module such a "Load Balancer for servers in the co.iizi.* domain" or "Backup License Manager for com.domain.LicMan".
    • initialize

      public IEndPointConstructor<Object> initialize(IServer server) throws Exception
      Description copied from interface: IServerModule
      Initializes the module end point constructor.
      Specified by:
      initialize in interface IServerModule<Object>
      Parameters:
      server - The server instance.
      Returns:
      The end point constructor.
      Throws:
      Exception - For failures: the module will not be used...
    • onServerReady

      public void onServerReady(IServer server)
      Description copied from interface: IServerModule
      Called when the server is ready. A server module that wishes to listen to when the server is going to be disposed can do so using IServer.addDisposeListener(com.iizix.server.IServerDisposeListener) at this stage.
      Specified by:
      onServerReady in interface IServerModule<Object>
      Parameters:
      server - The server instance.
    • dispose

      public void dispose()
      Description copied from interface: IServerModule
      Disposes of this server module. After dispose is called and IServerModule.dispose() has been called, the end point constructor is automatically removed and disposed of.
      Specified by:
      dispose in interface IServerModule<Object>
    • sweep

      public int sweep(long now)
      One in-process sweep: idle reservations by the clock (belt and braces beside the timers), then orphaned directories - anything on disk whose application session has no service here.
      Parameters:
      now - The current time.
      Returns:
      The number of directories swept from disk.
    • createService

      public AppGyroFileUploaderService createService(IUploadSessionContext context)
      Creates the service of an application session and routes its events.
      Parameters:
      context - The session context.
      Returns:
      The service.
    • disposeService

      public void disposeService(AppGyroFileUploaderService service)
      Disposes of a session's service: every transfer of the session is cancelled and removed.
      Parameters:
      service - The service.
    • serviceOf

      Finds the service owning a reservation.
      Parameters:
      r - The reservation.
      Returns:
      The service, or null if the session has none (disposed).
    • getRegistry

      public FileUploadRegistry getRegistry()
      Gets the registry.
      Returns:
      The registry.
    • getStore

      public UploadStagingStore getStore()
      Gets the store.
      Returns:
      The store.
    • isServletRegistered

      public boolean isServletRegistered()
      Checks if the chunk servlet is registered.
      Returns:
      true if registered.