Package com.inesm.KeyManager.services
Class MessageManager
java.lang.Object
com.inesm.KeyManager.services.OperationService
com.inesm.KeyManager.services.MessageManager
Service that handles message and receipts logic.
-
Method Summary
Modifier and TypeMethodDescriptionlongcreateMessage(User user, int operationID, com.inesm.KeyManager.services.KeyManager.MissionInfo info, SharedResource data, long groupID) Creates a single message in the database.exportMessage(Message message, User user) Exports a message for manual distribution.voidgenerateMessages(User user, int operationID, SharedResource data, long groupID) Generates message(s) from an operation.getMessageByIDSource(long id, String source) Gets a message from the database.Gets all messages from the database.getWaitingResources(boolean blocking) Gets all resources waiting to be sent from the database.voidimportMessage(Message message) Imports a message from manual distribution.voidprocess(NetworkResource resource) Processes a network resource.
-
Method Details
-
getMessageByIDSource
Gets a message from the database. Uses the messageID and source in order to uniquely identify a given message.- Parameters:
id- the messageID of the messagesource- source of the message- Returns:
- the retrieved message
- Throws:
ObjectNotFoundException- if a message with the given messageID source pair could not be found
-
getWaitingResources
Gets all resources waiting to be sent from the database. These resources are message tagged with status 2 and receipts with the field waiting set to true.- Parameters:
blocking- the flag used to block and wait for resources in case no waiting resources are available- Returns:
- a list containing the network resources retrieved or null if no waiting resources are available (if blocking=false)
- Throws:
InterruptedException- if any thread interrupted the current thread before or while the current thread was waiting (if blocking=true)
-
getMessages
Gets all messages from the database.- Returns:
- a list containing all messages
-
process
public void process(NetworkResource resource) throws ObjectNotFoundException, ObjectNotMappedException, InvalidParametersException, InvalidSignatureException Processes a network resource. Calls the dedicated processing method of each network resource.- Parameters:
resource- the network resource to be processed- Throws:
ObjectNotFoundException- if the network resource is a receipt and the corresponding message cannot be foundObjectNotMappedException- if the network resource is not recognizedInvalidParametersException- if the network resource contained invalid parametersInvalidSignatureException- if the network resource contained an invalid signature
-
exportMessage
public Message exportMessage(Message message, User user) throws ObjectNotFoundException, InvalidMessageException Exports a message for manual distribution.- Parameters:
message- the message to be exported, not null, must have messageID and source setuser- the user issuing the manual distribution, not null, must have username set- Returns:
- the updated message with the export status
- Throws:
ObjectNotFoundException- if the specified message could not be foundInvalidMessageException- if the message status is not waiting, making it not possible to export the message
-
importMessage
public void importMessage(Message message) throws InvalidParametersException, InvalidSignatureException Imports a message from manual distribution.- Parameters:
message- the message being imported- Throws:
InvalidParametersException- if the message contained invalid parametersInvalidSignatureException- if the message's signature was invalid
-