Class MysqlFileManager

  • All Implemented Interfaces:
    FileManager<java.lang.Integer>, java.lang.AutoCloseable

    public class MysqlFileManager
    extends java.lang.Object
    implements FileManager<java.lang.Integer>
    This class implements a FileManager that writes response content to a file on the file system and a record in MySQL database pointing to the record and allows retrieving the file using an id or request.
    Author:
    Maksim Tkachenko, Truong Quoc Tuan, Ween Jiann Lee
    • Constructor Summary

      Constructors 
      Constructor Description
      MysqlFileManager​(java.lang.String url, java.lang.String table, java.lang.String username, java.lang.String password, java.io.File storagePath)
      Constructs an instance of MysqlFileManager.
      MysqlFileManager​(java.lang.String url, java.lang.String table, java.lang.String username, java.lang.String password, java.lang.String storageDir)
      Constructs an instance of MysqlFileManager.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      Record<java.lang.Integer> get​(Request request)
      Returns latest record matching request.
      Record<java.lang.Integer> get​(java.lang.Integer id)
      Returns record by the internal record id.
      Callback getCallback()
      Get callback upon completion of request.
      java.lang.String put​(Request request, Response response)
      Puts record into database.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MysqlFileManager

        public MysqlFileManager​(java.lang.String url,
                                java.lang.String table,
                                java.lang.String username,
                                java.lang.String password,
                                java.lang.String storageDir)
        Constructs an instance of MysqlFileManager.
        Parameters:
        url - a JDBC URL to the database
        table - table in the database to use for record storage
        username - username for the database
        password - password for the database
        storageDir - storage directory to use for content storage
      • MysqlFileManager

        public MysqlFileManager​(java.lang.String url,
                                java.lang.String table,
                                java.lang.String username,
                                java.lang.String password,
                                java.io.File storagePath)
        Constructs an instance of MysqlFileManager.
        Parameters:
        url - a JDBC URL to the database
        table - name of table in the database to use for record storage
        username - username for the database
        password - password for the database
        storagePath - storage path to use for content storage
    • Method Detail

      • getCallback

        public final Callback getCallback()
        Description copied from interface: FileManager
        Get callback upon completion of request.

        Please note that blocking callbacks will significantly reduce the rate at which request are processed. Please implement your own executors on I/O blocking callbacks.

        Specified by:
        getCallback in interface FileManager<java.lang.Integer>
        Returns:
        Callback for FileManager
      • put

        public final java.lang.String put​(Request request,
                                          Response response)
                                   throws StorageException
        Description copied from interface: FileManager
        Puts record into database.
        Specified by:
        put in interface FileManager<java.lang.Integer>
        Parameters:
        request - request
        response - Response
        Returns:
        id of record
        Throws:
        StorageException - throws StorageException
      • get

        public final Record<java.lang.Integer> get​(java.lang.Integer id)
                                            throws StorageException
        Description copied from interface: FileManager
        Returns record by the internal record id.
        Specified by:
        get in interface FileManager<java.lang.Integer>
        Parameters:
        id - record id
        Returns:
        stored record
        Throws:
        StorageException - throws StorageException
      • get

        public final Record<java.lang.Integer> get​(Request request)
                                            throws StorageException
        Description copied from interface: FileManager
        Returns latest record matching request.
        Specified by:
        get in interface FileManager<java.lang.Integer>
        Parameters:
        request - request
        Returns:
        stored record
        Throws:
        StorageException - throws StorageException
      • close

        public final void close()
                         throws java.sql.SQLException
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.sql.SQLException