src.server
Class Alerter

java.lang.Object
  extended bysrc.server.Alerter

public class Alerter
extends java.lang.Object

Adds support for sending alerts to users. An alert is a kind of notification of when an event occurs. An alert could for instance be a message generated from within the server which is then sent out to all users that have registered that they want that kind of alert/notification. E.g. a message telling the user that the latest math exam has been graded. Implements singelton pattern.

Version:
2005-apr-20

Method Summary
 void deregisterTranslator(java.lang.String translatorId)
          Removes all alert registrations with the specified translator id.
 boolean deregisterUser(java.lang.String userId, java.lang.String translatorId, java.lang.String alertName)
          Removes a user from the alert list for a specific alert and translator.
 java.util.Vector getAlertList(java.lang.String userId, java.lang.String translatorId)
          Lists all alerts that a user has registered for.
static Alerter getInstance()
          Used to get the object in singelton patterns.
 java.util.HashSet getRegisteredAlerts()
          Gets a set with all alerts that are valid.
 void registerAlert(java.lang.String alertName)
          Registers an alert so that the alerter will accept it when notified with said alert.
 boolean registerUser(java.lang.String userId, java.lang.String translatorId, java.lang.String alertName)
          Registers an user for a specific module generated alert through a specific translator.
 void triggerAlert(java.lang.String alertName, OutputPackage output)
          Triggers an alert and sends the specified output package to all the users that have registered for the specific alert.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Alerter getInstance()
Used to get the object in singelton patterns.

Returns:
The one instance of the class.

registerUser

public boolean registerUser(java.lang.String userId,
                            java.lang.String translatorId,
                            java.lang.String alertName)
Registers an user for a specific module generated alert through a specific translator. Alerts are sent out on a user and translator basis. Meaning that a user can register to only get alerts through e.g. email even though the user uses the same userId with his cell phone, all because they use different translators.

Parameters:
userId - The user identifier, a single user id can be connected to multiple translators and user specific details (e.g. email adresses, cell phon number).
translatorId - The translator identifier for the translator that the alert should be sent through.
alertName - The name of the alert that the user wants.

deregisterUser

public boolean deregisterUser(java.lang.String userId,
                              java.lang.String translatorId,
                              java.lang.String alertName)
Removes a user from the alert list for a specific alert and translator.

Parameters:
userId - The user identifier, a single user id can be connected to multiple translators and user specific details (e.g. email adresses, cell phone number).
translatorId - The translator identifier for the translator that the alert should be sent through.
alertName - The name of the alert that the user wants.

triggerAlert

public void triggerAlert(java.lang.String alertName,
                         OutputPackage output)
Triggers an alert and sends the specified output package to all the users that have registered for the specific alert.

Parameters:
alertName - The name of the alert that should be triggered.
output - The package containing the message that should be sent out. The translatorId and userId contained in the package are irrelevant, the alerter substitutes them with the real recipients' identification.

deregisterTranslator

public void deregisterTranslator(java.lang.String translatorId)
Removes all alert registrations with the specified translator id. Used when for instance a translator is dropped from the server and is no longer contactable.

Parameters:
translatorId - The id of the translator to remove.

getAlertList

public java.util.Vector getAlertList(java.lang.String userId,
                                     java.lang.String translatorId)
Lists all alerts that a user has registered for.

Parameters:
userId - The user identifier, a single user id can be connected to multiple translators and user specific details (e.g. email adresses, cell phone number).
translatorId - The translator identifier for the translator that the alert should be sent through.
Returns:
An Vector with all registered alerts (empty if none).

registerAlert

public void registerAlert(java.lang.String alertName)
Registers an alert so that the alerter will accept it when notified with said alert.

Parameters:
alertName - The name of the alert to register.

getRegisteredAlerts

public java.util.HashSet getRegisteredAlerts()
Gets a set with all alerts that are valid.

Returns:
A set containing alert names.