Package ai.preferred.venom.storage
Class MysqlFileManager
- java.lang.Object
-
- ai.preferred.venom.storage.MysqlFileManager
-
- All Implemented Interfaces:
FileManager<Integer>
,AutoCloseable
public class MysqlFileManager extends Object implements FileManager<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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MysqlFileManager.CompletedThreadedCallback
A callback wrapper for to run complete multithreaded.
-
Constructor Summary
Constructors Constructor Description MysqlFileManager(String url, String table, String username, String password, File storagePath)
Constructs an instance of MysqlFileManager.MysqlFileManager(String url, String table, String username, String password, String storageDir)
Constructs an instance of MysqlFileManager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Record<Integer>
get(Request request)
Returns latest record matching request.Record<Integer>
get(Integer id)
Returns record by the internal record id.Callback
getCallback()
Get callback upon completion of request.String
put(Request request, Response response)
Puts record into database.
-
-
-
Constructor Detail
-
MysqlFileManager
public MysqlFileManager(String url, String table, String username, String password, String storageDir)
Constructs an instance of MysqlFileManager.- Parameters:
url
- a JDBC URL to the databasetable
- table in the database to use for record storageusername
- username for the databasepassword
- password for the databasestorageDir
- storage directory to use for content storage
-
MysqlFileManager
public MysqlFileManager(String url, String table, String username, String password, File storagePath)
Constructs an instance of MysqlFileManager.- Parameters:
url
- a JDBC URL to the databasetable
- name of table in the database to use for record storageusername
- username for the databasepassword
- password for the databasestoragePath
- 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 interfaceFileManager<Integer>
- Returns:
- Callback for FileManager
-
put
public final String put(Request request, Response response) throws StorageException
Description copied from interface:FileManager
Puts record into database.- Specified by:
put
in interfaceFileManager<Integer>
- Parameters:
request
- requestresponse
- Response- Returns:
- id of record
- Throws:
StorageException
- throws StorageException
-
get
public final Record<Integer> get(Integer id) throws StorageException
Description copied from interface:FileManager
Returns record by the internal record id.- Specified by:
get
in interfaceFileManager<Integer>
- Parameters:
id
- record id- Returns:
- stored record
- Throws:
StorageException
- throws StorageException
-
get
public final Record<Integer> get(Request request) throws StorageException
Description copied from interface:FileManager
Returns latest record matching request.- Specified by:
get
in interfaceFileManager<Integer>
- Parameters:
request
- request- Returns:
- stored record
- Throws:
StorageException
- throws StorageException
-
close
public final void close() throws SQLException
- Specified by:
close
in interfaceAutoCloseable
- Throws:
SQLException
-
-