[jitsi-dev] Re: [jitsi~svn:9192] Separate notification service from its handlers


#1

Hey Ingo,

just one thing, when renaming bundles there comes a problem that
people that have already installed the previous version and install
the new one will end up running the same bundle twice, one with old
name and one with the new.
Its the same with renaming the notification service. When you install
the latest version as old notification.jar was already cached will be
started and the new bundle notification-service.jar will be started
too. This may lead to problems.
We can leave the notification service as it was before. WDYT?

Regards
damencho

···

On Mon, Dec 5, 2011 at 9:40 PM, <ibauersachs@java.net> wrote:

Project: jitsi
Repository: svn
Revision: 9192
Author: ibauersachs
Date: 2011-12-05 19:40:11 UTC
Link:

Log Message:
------------
Separate notification service from its handlers

Revisions:
----------
9192

Modified Paths:
---------------
trunk/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java
trunk/src/net/java/sip/communicator/plugin/notificationconfiguration/NotificationsTable.java
trunk/lib/felix.client.run.properties
trunk/src/net/java/sip/communicator/impl/notification/NotificationActivator.java
trunk/src/net/java/sip/communicator/impl/notification/notification.manifest.mf
trunk/src/net/java/sip/communicator/impl/notification/NotificationManager.java
trunk/src/net/java/sip/communicator/impl/notification/PopupMessageNotificationHandlerImpl.java
trunk/src/net/java/sip/communicator/service/notification/LogMessageNotificationHandler.java
trunk/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java
trunk/src/net/java/sip/communicator/plugin/loggingutils/LoggingConfigForm.java
trunk/src/net/java/sip/communicator/service/notification/NotificationService.java
trunk/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java
trunk/src/net/java/sip/communicator/impl/notification/LogMessageNotificationHandlerImpl.java
trunk/src/net/java/sip/communicator/service/notification/SoundNotificationHandler.java
trunk/src/net/java/sip/communicator/plugin/notificationconfiguration/NotificationConfigurationPanel.java
trunk/test/net/java/sip/communicator/slick/popupmessagehandler/TestPopupMessageHandler.java
trunk/src/net/java/sip/communicator/impl/notification/CommandNotificationHandlerImpl.java
trunk/src/net/java/sip/communicator/service/notification/PopupMessageNotificationHandler.java
trunk/src/net/java/sip/communicator/service/notification/event/NotificationActionTypeEvent.java
trunk/build.xml

Added Paths:
------------
trunk/src/net/java/sip/communicator/service/notification/NotificationHandler.java
trunk/src/net/java/sip/communicator/service/notification/SoundNotificationAction.java
trunk/src/net/java/sip/communicator/service/notification/notification.manifest.mf
trunk/src/net/java/sip/communicator/service/notification/PopupMessageNotificationAction.java
trunk/src/net/java/sip/communicator/service/notification/NotificationAction.java
trunk/src/net/java/sip/communicator/service/notification/NotificationServiceImpl.java
trunk/src/net/java/sip/communicator/service/notification/LogMessageNotificationAction.java
trunk/src/net/java/sip/communicator/service/notification/NotificationServiceActivator.java
trunk/src/net/java/sip/communicator/service/notification/CommandNotificationAction.java
trunk/src/net/java/sip/communicator/service/notification/Notification.java

Diffs:
------
Index: trunk/test/net/java/sip/communicator/slick/popupmessagehandler/TestPopupMessageHandler.java

--- trunk/test/net/java/sip/communicator/slick/popupmessagehandler/TestPopupMessageHandler.java (revision 9191)
+++ trunk/test/net/java/sip/communicator/slick/popupmessagehandler/TestPopupMessageHandler.java (revision 9192)
@@ -127,7 +127,7 @@
= (NotificationService) bc.getService(serviceReference);

    notificationService\.fireNotification\(

- NotificationService.ACTION_POPUP_MESSAGE,
+ NotificationAction.ACTION_POPUP_MESSAGE,
messageStart,
messageStart,
null,
Index: trunk/src/net/java/sip/communicator/service/notification/NotificationActionHandler.java

--- trunk/src/net/java/sip/communicator/service/notification/NotificationActionHandler.java (revision 9191)
+++ trunk/src/net/java/sip/communicator/service/notification/NotificationActionHandler.java (revision 9192)
@@ -1,38 +0,0 @@
-/*
- * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package net.java.sip.communicator.service.notification;
-
-/**
- * The <tt>NotificationActionHandler</tt> is the parent interface of all specific
- * notification handlers used for handling different action types. This
- * interface is used in the NotificationService in all methods dealing with
- * action handlers.
- *
- * @author Yana Stamcheva
- */
-public interface NotificationActionHandler
-{
- /**
- * Returns TRUE if this notification action handler is enabled and FALSE
- * otherwise. While the notification handler for an action type is disabled
- * no notifications will be fired for this action type.
- *
- * @return TRUE if this notification action handler is enabled and FALSE
- * otherwise
- */
- public boolean isEnabled();
-
- /**
- * Enables or disables this notification handler. While the notification
- * handler for an action type is disabled no notifications will be fired
- * for this action type.
- *
- * @param isEnabled TRUE to enable this notification handler, FALSE to
- * disable it.
- */
- public void setEnabled(boolean isEnabled);
-}
Index: trunk/src/net/java/sip/communicator/service/notification/event/NotificationActionTypeEvent.java

--- trunk/src/net/java/sip/communicator/service/notification/event/NotificationActionTypeEvent.java (revision 9191)
+++ trunk/src/net/java/sip/communicator/service/notification/event/NotificationActionTypeEvent.java (revision 9192)
@@ -40,11 +40,6 @@
public static final String ACTION_CHANGED = "ActionChanged";

/\*\*

- * The type of the notification action that is being added.
- */
- private String sourceActionType = null;
-
- /**
* The type of the event that a new action is being added for.
*/
private String sourceEventType = null;
@@ -54,7 +49,7 @@
* string) that will be performed when notifications are being fired for
* the corresponding event type.
*/
- private NotificationActionHandler actionHandler = null;
+ private NotificationAction actionHandler = null;

/\*\*
 \* The type of this event\. One of the static field constants declared in

@@ -69,35 +64,22 @@
* @param eventType the type of this event. One of the static fields
* declared in this class
* @param sourceEventType the event type for which this event occured
- * @param sourceActionType the action type corresponding to this event
* @param actionHandler the <tt>NotificationActionHandler</tt> that handles
* the given action
*/
public NotificationActionTypeEvent( NotificationService source,
String eventType,
String sourceEventType,
- String sourceActionType,
- NotificationActionHandler actionHandler)
+ NotificationAction actionHandler)
{
super(source);

    this\.eventType = eventType;
    this\.sourceEventType = sourceEventType;

- this.sourceActionType = sourceActionType;
this.actionHandler = actionHandler;
}

/\*\*

- * Returns the action type, for which this event is about.
- *
- * @return the action type, for which this event is about.
- */
- public String getSourceActionType()
- {
- return sourceActionType;
- }
-
- /**
* Returns the event type, to which the given action belongs.
*
* @return the event type, to which the given action belongs
@@ -114,7 +96,7 @@
* @return the <tt>NotificationActionHandler</tt> that handles the action,
* for which this event is about.
*/
- public NotificationActionHandler getActionHandler()
+ public NotificationAction getActionHandler()
{
return actionHandler;
}
Index: trunk/src/net/java/sip/communicator/service/notification/NotificationService.java

--- trunk/src/net/java/sip/communicator/service/notification/NotificationService.java (revision 9191)
+++ trunk/src/net/java/sip/communicator/service/notification/NotificationService.java (revision 9192)
@@ -6,8 +6,6 @@
*/
package net.java.sip.communicator.service.notification;

-import java.util.*;
-
/**
* This service is previewed for use by bundles that implement some kind of
* user notification (e.g. playing sounds, poping systray tooltips, or
@@ -23,237 +21,78 @@
public interface NotificationService
{
/**
- * The log message action type indicates that a message would be logged,
- * when a notification is fired.
- */
- public static final String ACTION_LOG_MESSAGE = "LogMessageAction";
-
- /**
- * The popup message action type indicates that a window (or a systray
- * popup), containing the corresponding notification message would be poped
- * up, when a notification is fired.
- */
- public static final String ACTION_POPUP_MESSAGE = "PopupMessageAction";
-
- /**
- * The sound action type indicates that a sound would be played, when a
- * notification is fired.
- */
- public static final String ACTION_SOUND = "SoundAction";
-
- /**
- * The command action type indicates that a command would be executed,
- * when a notification is fired.
- */
- public static final String ACTION_COMMAND = "CommandAction";
-
- /**
- * Default event type for receiving messages.
- */
- public static final String INCOMING_MESSAGE = "IncomingMessage";
-
- /**
- * Default event type for receiving calls (incoming calls).
- */
- public static final String INCOMING_CALL = "IncomingCall";
-
- /**
- * Default event type for outgoing calls.
- */
- public static final String OUTGOING_CALL = "OutgoingCall";
-
- /**
- * Default event type for a busy call.
- */
- public static final String BUSY_CALL = "BusyCall";
-
- /**
- * Default event type for dialing.
- */
- public static final String DIALING = "Dialing";
-
- /**
- * Default event type for hanging up calls.
- */
- public static final String HANG_UP = "HangUp";
-
- /**
- * Default event type for
- * proactive notifications (typing notifications when chatting).
- */
- public static final String PROACTIVE_NOTIFICATION = "ProactiveNotification";
-
- /**
- * Default event type when a secure message received.
- */
- public static final String SECURITY_MESSAGE = "SecurityMessage";
-
- /**
- * Default event type for activated security on a call.
- */
- public static final String CALL_SECURITY_ON = "CallSecurityOn";
-
- /**
- * Default event type for security error on a call.
- */
- public static final String CALL_SECURITY_ERROR = "CallSecurityError";
-
- /**
- * Default event type for incoming file transfers.
- */
- public static final String INCOMING_FILE = "IncomingFile";
-
- /**
- * Default event type for call been saved using a recorder.
- */
- public static final String CALL_SAVED = "CallSaved";
-
- /**
- * Creates a <tt>SoundNotificationHandler</tt>, by specifying the
- * path pointing to the sound file and the loop interval if the sound should
- * be played in loop. If the sound should be played just once the loop
- * interval should be set to -1. The <tt>SoundNotificationHandler</tt> is
- * the one that would take care of playing the sound, when a notification
- * is fired.
- *
- * @param soundFileDescriptor the path pointing to the sound file
- * @param loopInterval the interval of milliseconds to repeat the sound in
- * loop
- * @return the <tt>SoundNotificationHandler</tt> is the one, that would take
- * care of playing the given sound, when a notification is fired
- */
- public SoundNotificationHandler createSoundNotificationHandler(
- String soundFileDescriptor,
- int loopInterval);
-
- /**
- * Creates a <tt>PopupMessageNotificationHandler</tt>, by specifying the
- * default message to show, when no message is provided to the
- * <tt>fireNotification</tt> method. The
- * <tt>PopupMessageNotificationHandler</tt> is the one that would take care
- * of showing a popup message (through the systray service for example),
- * when a notification is fired.
- *
- * @param defaultMessage the message to show if not message is provided to
- * the <tt>fireNotification</tt> method
- * @return the <tt>PopupMessageNotificationHandler</tt> is the one, that
- * would take care of showing a popup message (through the systray service
- * for example), when a notification is fired.
- */
- public PopupMessageNotificationHandler createPopupMessageNotificationHandler(
- String defaultMessage);
-
- /**
- * Creates a <tt>LogMessageNotificationHandler</tt>, by specifying the
- * type of the log (error, trace, info, etc.). The
- * <tt>LogMessageNotificationHandler</tt> is the one that would take care
- * of logging a message (through the application log system), when a
- * notification is fired.
- *
- * @param logType the type of the log (error, trace, etc.). One of the types
- * defined in the <tt>LogMessageNotificationHandler</tt> interface
- * @return the <tt>LogMessageNotificationHandler</tt> is the one, that would
- * take care of logging a message (through the application log system), when
- * a notification is fired.
- */
- public LogMessageNotificationHandler createLogMessageNotificationHandler(
- String logType);
-
- /**
- * Creates a <tt>CommandNotificationHandler</tt>, by specifying the path to
- * the command file to execute, when a notification is fired. The
- * <tt>CommandNotificationHandler</tt> is the one that would take care
- * of executing the given program, when a notification is fired.
- *
- * @param commandFileDescriptor the path to the file containing the program
- * to execute
- * @return the <tt>CommandNotificationHandler</tt> is the one, that would
- * take care of executing a program, when a notification is fired.
- */
- public CommandNotificationHandler createCommandNotificationHandler(
- String commandFileDescriptor);
-
- /**
* Registers a notification for the given <tt>eventType</tt> by specifying
- * the type of the action to be performed when a notification is fired for
- * this event and the corresponding <tt>handler</tt> that should be used to
- * handle the action. Unlike the other <tt>registerNotificationForEvent</tt>
+ * the action to be performed when a notification is fired for this event.
+ *
+ * Unlike the other <tt>registerNotificationForEvent</tt>
* method, this one allows the user to specify its own
- * <tt>NotificationHandler</tt>, which would be used to handle notifications
+ * <tt>NotificationAction</tt>, which would be used to handle notifications
* for the specified <tt>actionType</tt>.
*
* @param eventType the name of the event (as defined by the plug-in that's
* registering it) that we are setting an action for.
- * @param actionType the type of the action that is to be executed when the
- * specified event occurs (could be one of the ACTION_XXX fields).
- * @param handler the <tt>NotificationActionHandler</tt>, which would be
+ * @param action the <tt>NotificationAction</tt>, which would be
* used to perform the notification action.
- * @throws IllegalArgumentException if the specified <tt>handler</tt> do not
- * correspond to the given <tt>actionType</tt>.
*/
- public void registerNotificationForEvent( String eventType,
- String actionType,
- NotificationActionHandler handler)
- throws IllegalArgumentException;
-
+ public void registerNotificationForEvent(String eventType,
+ NotificationAction action);
+
/**
- * Registers a Default notification for the given <tt>eventType</tt> by specifying
- * the type of the action to be performed when a notification is fired for
- * this event and the corresponding <tt>handler</tt> that should be used to
- * handle the action. Unlike the other
- * <tt>registerDefaultNotificationForEvent</tt>
- * method, this one allows the user to specify its own
- * <tt>NotificationHandler</tt>, which would be used to handle notifications
- * for the specified <tt>actionType</tt>.
- * Default events are stored or executed at first run or when they are
- * missing in the configuration. Also the registered default events
- * are used when restoreDefaults is called.
+ * Registers a default notification for the given <tt>eventType</tt> by
+ * specifying the action to be performed when a notification is fired for
+ * this event.
*
+ * Unlike the other <tt>registerDefaultNotificationForEvent</tt> method,
+ * this one allows the user to specify its own <tt>NotificationAction</tt>,
+ * which would be used to handle notifications.
+ *
+ * Default events are stored or executed at first run or when they are
+ * missing in the configuration. Also the registered default events are used
+ * when restoreDefaults is called.
+ *
* @param eventType the name of the event (as defined by the plug-in that's
- * registering it) that we are setting an action for.
- * @param actionType the type of the action that is to be executed when the
- * specified event occurs (could be one of the ACTION_XXX fields).
+ * registering it) that we are setting an action for.
* @param handler the <tt>NotificationActionHandler</tt>, which would be
- * used to perform the notification action.
- * @throws IllegalArgumentException if the specified <tt>handler</tt> do not
- * correspond to the given <tt>actionType</tt>.
+ * used to perform the notification action.
*/
- public void registerDefaultNotificationForEvent( String eventType,
- String actionType,
- NotificationActionHandler handler)
- throws IllegalArgumentException;
-
+ public void registerDefaultNotificationForEvent(String eventType,
+ NotificationAction handler);
+
/**
- * Registers a default notification for the given <tt>eventType</tt> by specifying
- * the type of the action to be performed when a notification is fired for
- * this event, the <tt>actionDescriptor</tt> for sound and command actions
- * and the <tt>defaultMessage</tt> for popup and log actions. Actions
- * registered by this method would be handled by some default
+ * Registers a default notification for the given <tt>eventType</tt> by
+ * specifying the type of the action to be performed when a notification is
+ * fired for this event, the <tt>actionDescriptor</tt> for sound and command
+ * actions and the <tt>defaultMessage</tt> for popup and log actions.
+ *
+ * Actions registered by this method would be handled by some default
* <tt>NotificationHandler</tt>s, declared by the implementation.
* <p>
* The method allows registering more than one actionType for a specific
- * event. Setting twice the same <tt>actionType</tt> for the same
- * <tt>eventType</tt> however would cause the first setting to be
+ * event. Setting the same <tt>actionType</tt> for the same
+ * <tt>eventType</tt> twice however would cause the first setting to be
* overridden.
- * Default events are stored or executed at first run or when they are
- * missing in the configuration. Also the registered default events
+ *
+ * Default events are stored or executed at first run or when
+ * they are missing in the configuration. Also the registered default events
* are used when restoreDefaults is called.
- *
+ *
* @param eventType the name of the event (as defined by the plug-in that's
- * registering it) that we are setting an action for.
+ * registering it) that we are setting an action for.
* @param actionType the type of the action that is to be executed when the
- * specified event occurs (could be one of the ACTION_XXX fields).
+ * specified event occurs (could be one of the ACTION_XXX
+ * fields).
* @param actionDescriptor a String containing a description of the action
- * (a URI to the sound file for audio notifications or a command line for
- * exec action types) that should be executed when the action occurs.
+ * (a URI to the sound file for audio notifications or a command
+ * line for exec action types) that should be executed when the
+ * action occurs.
* @param defaultMessage the default message to use if no specific message
- * has been provided when firing the notification.
+ * has been provided when firing the notification.
*/
- public void registerDefaultNotificationForEvent( String eventType,
- String actionType,
- String actionDescriptor,
- String defaultMessage);
-
+ public void registerDefaultNotificationForEvent(String eventType,
+ String actionType,
+ String actionDescriptor,
+ String defaultMessage);
+
/**
* Registers a notification for the given <tt>eventType</tt> by specifying
* the type of the action to be performed when a notification is fired for
@@ -263,44 +102,46 @@
* <tt>NotificationHandler</tt>s, declared by the implementation.
* <p>
* The method allows registering more than one actionType for a specific
- * event. Setting twice the same <tt>actionType</tt> for the same
- * <tt>eventType</tt> however would cause the first setting to be
+ * event. Setting the same <tt>actionType</tt> for the same
+ * <tt>eventType</tt> twice however would cause the first setting to be
* overridden.
- *
+ *
* @param eventType the name of the event (as defined by the plug-in that's
- * registering it) that we are setting an action for.
+ * registering it) that we are setting an action for.
* @param actionType the type of the action that is to be executed when the
- * specified event occurs (could be one of the ACTION_XXX fields).
+ * specified event occurs (could be one of the ACTION_XXX
+ * fields).
* @param actionDescriptor a String containing a description of the action
- * (a URI to the sound file for audio notifications or a command line for
- * exec action types) that should be executed when the action occurs.
+ * (a URI to the sound file for audio notifications or a command
+ * line for exec action types) that should be executed when the
+ * action occurs.
* @param defaultMessage the default message to use if no specific message
- * has been provided when firing the notification.
+ * has been provided when firing the notification.
*/
public void registerNotificationForEvent( String eventType,
String actionType,
String actionDescriptor,
String defaultMessage);
-
+
/**
* Deletes all registered events and actions
* and registers and saves the default events as current.
*/
public void restoreDefaults();
-
+
/**
- * Removes the given <tt>eventType</tt> from the list of event notifications.
- * This means that we delete here all registered notifications for the given
- * <tt>eventType</tt>.
+ * Removes the given <tt>eventType</tt> from the list of event
+ * notifications. This means that we delete here all registered
+ * notifications for the given <tt>eventType</tt>.
* <p>
* This method does nothing if the given <tt>eventType</tt> is not contained
* in the list of registered event types.
- *
+ *
* @param eventType the name of the event (as defined by the plugin that's
- * registering it) to be removed.
+ * registering it) to be removed.
*/
public void removeEventNotification(String eventType);
-
+
/**
* Removes the event notification corresponding to the specified
* <tt>actionType</tt> and <tt>eventType</tt>.
@@ -309,57 +150,40 @@
* <tt>actionType</tt> are not contained in the list of registered types.
*
* @param eventType the name of the event (as defined by the plugin that's
- * registering it) for which we'll remove the notification.
+ * registering it) for which we'll remove the notification.
* @param actionType the type of the action that is to be executed when the
- * specified event occurs (could be one of the ACTION_XXX fields).
+ * specified event occurs (could be one of the ACTION_XXX
+ * fields).
*/
public void removeEventNotificationAction( String eventType,
String actionType);

/\*\*
 \* Returns an iterator over a list of all events registered in this

- * notification service. Each line in the returned list consists of
- * a String, representing the name of the event (as defined by the plugin
- * that registered it).
- *
+ * notification service. Each line in the returned list consists of a
+ * String, representing the name of the event (as defined by the plugin that
+ * registered it).
+ *
* @return an iterator over a list of all events registered in this
- * notifications service
+ * notifications service
*/
- public Iterator<String> getRegisteredEvents();
-
- /**
- * Returns a Map containing all action types (as keys) and actionDescriptors
- * (as values) that have been registered for <tt>eventType</tt>.
- * <p>
- * This method returns <b>null</b> if the given <tt>eventType</tt> is not
- * contained in the list of registered event types.
- *
- * @param eventType the name of the event that we'd like to retrieve actions
- * for.
- * @return a <tt>Map</tt> containing the <tt>actionType</tt>s (as keys) and
- * <tt>actionHandler</tt>s (as values) that should be executed when
- * an event with the specified name has occurred, or null if no actions
- * have been defined for <tt>eventType</tt>.
- */
- public Map<String, NotificationActionHandler> getEventNotifications(
- String eventType);
+ public Iterable<String> getRegisteredEvents();

/\*\*

- * Returns the <tt>NotificationActionHandler</tt> corresponding to the given
- * event and action types.
+ * Returns the <tt>NotificationAction</tt> corresponding to the given event
+ * and action type.
* <p>
* This method returns <b>null</b> if the given <tt>eventType</tt> or
* <tt>actionType</tt> are not contained in the list of registered types.
- *
+ *
* @param eventType the type of the event that we'd like to retrieve.
* @param actionType the type of the action that we'd like to retrieve a
- * descriptor for.
- * @return the <tt>NotificationActionHandler</tt> corresponding to the given
- * event and action types
+ * descriptor for.
+ * @return the <tt>NotificationAction</tt> corresponding to the given event
+ * and action type
*/
- public NotificationActionHandler getEventNotificationActionHandler(
- String eventType,
- String actionType);
+ public NotificationAction getEventNotificationAction(String eventType,
+ String actionType);

/\*\*
 \* Registers a listener that would be notified of changes that have occurred

@@ -382,6 +206,26 @@
NotificationChangeListener listener);

/\*\*

+ * Adds an object that executes the actual action of a notification action.
+ * @param handler The handler that executes the action.
+ */
+ public void addActionHandler(NotificationHandler handler);
+
+ /**
+ * Removes an object that executes the actual action of notification action.
+ * @param actionType The handler type to remove.
+ */
+ public void removeActionHandler(String actionType);
+
+ /**
+ * Gets at list of handler for the specified action type.
+ *
+ * @param actionType the type for which the list of handlers should be
+ * retrieved or <tt>null</tt> if all handlers shall be returned.
+ */
+ public Iterable<NotificationHandler> getActionHandlers(String actionType);
+
+ /**
* Fires all notifications registered for the specified <tt>eventType</tt>
* using <tt>message</tt> as a notification message wherever appropriate
* (e.g. systray notifications, logs, etc.)
Index: trunk/src/net/java/sip/communicator/service/notification/notification.manifest.mf

--- trunk/src/net/java/sip/communicator/service/notification/notification.manifest.mf (revision 0)
+++ trunk/src/net/java/sip/communicator/service/notification/notification.manifest.mf (revision 9192)
@@ -0,0 +1,11 @@
+Bundle-Activator: net.java.sip.communicator.service.notification.NotificationServiceActivator
+Bundle-Name: Notifications
+Bundle-Description: An implementation of the Notification service.
+Bundle-Vendor: sip-communicator.org
+Bundle-Version: 0.0.1
+System-Bundle: yes
+Export-Package: net.java.sip.communicator.service.notification,
+ net.java.sip.communicator.service.notification.event
+Import-Package: org.osgi.framework,
+ net.java.sip.communicator.util,
+ net.java.sip.communicator.service.configuration
Index: trunk/src/net/java/sip/communicator/service/notification/PopupMessageNotificationAction.java

--- trunk/src/net/java/sip/communicator/service/notification/PopupMessageNotificationAction.java (revision 0)
+++ trunk/src/net/java/sip/communicator/service/notification/PopupMessageNotificationAction.java (revision 9192)
@@ -0,0 +1,41 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.service.notification;
+
+/**
+ * An implementation of the <tt>PopupMessageNotificationHandler</tt> interface.
+ *
+ * @author Yana Stamcheva
+ */
+public class PopupMessageNotificationAction
+ extends NotificationAction
+{
+ private String defaultMessage;
+
+ /**
+ * Creates an instance of <tt>PopupMessageNotificationHandlerImpl</tt> by
+ * specifying the default message to use if no message is specified.
+ *
+ * @param defaultMessage the default message to use if no message is
+ * specified
+ */
+ public PopupMessageNotificationAction(String defaultMessage)
+ {
+ super(NotificationAction.ACTION_POPUP_MESSAGE);
+ this.defaultMessage = defaultMessage;
+ }
+
+ /**
+ * Return the default message to use if no message is specified.
+ *
+ * @return the default message to use if no message is specified.
+ */
+ public String getDefaultMessage()
+ {
+ return defaultMessage;
+ }
+}
Index: trunk/src/net/java/sip/communicator/service/notification/PopupMessageNotificationHandler.java

--- trunk/src/net/java/sip/communicator/service/notification/PopupMessageNotificationHandler.java (revision 9191)
+++ trunk/src/net/java/sip/communicator/service/notification/PopupMessageNotificationHandler.java (revision 9192)
@@ -6,8 +6,6 @@
*/
package net.java.sip.communicator.service.notification;

-import net.java.sip.communicator.service.systray.*;
-
/**
* The <tt>PopupMessageNotificationHandler</tt> interface is meant to be
* implemented by the notification bundle in order to provide handling of
@@ -16,21 +14,22 @@
* @author Yana Stamcheva
*/
public interface PopupMessageNotificationHandler
- extends NotificationActionHandler
+ extends NotificationHandler
{
/**
- * Returns the default message to be used when no message is provided to the
- * <tt>popupMessage</tt> method.
- *
- * @return the default message to be used when no message is provided to the
- * <tt>popupMessage</tt> method.
- */
- public String getDefaultMessage();
-
- /**
* Shows the given <tt>PopupMessage</tt>
*
- * @param message the message to show in the popup
+ * @param action the action to act upon
+ * @param title the title of the given message
+ * @param message the message to use if and where appropriate (e.g. with
+ * systray or log notification.)
+ * @param icon the icon to show in the notification if and where
+ * appropriate
+ * @param tag additional info to be used by the notification handler
*/
- public void popupMessage(PopupMessage message);
+ public void popupMessage(PopupMessageNotificationAction action,
+ String title,
+ String message,
+ byte[] icon,
+ Object tag);
}
Index: trunk/src/net/java/sip/communicator/service/notification/CommandNotificationAction.java

--- trunk/src/net/java/sip/communicator/service/notification/CommandNotificationAction.java (revision 0)
+++ trunk/src/net/java/sip/communicator/service/notification/CommandNotificationAction.java (revision 9192)
@@ -0,0 +1,42 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.service.notification;
+
+/**
+ * An implementation of the <tt>CommandNotificationHandler</tt> interface.
+ *
+ * @author Yana Stamcheva
+ */
+public class CommandNotificationAction
+ extends NotificationAction
+{
+ private String commandDescriptor;
+
+ /**
+ * Creates an instance of <tt>CommandNotification</tt> by
+ * specifying the <tt>commandDescriptor</tt>, which will point us to the
+ * command to execute.
+ *
+ * @param commandDescriptor a String that should point us to the command to
+ * execute
+ */
+ public CommandNotificationAction(String commandDescriptor)
+ {
+ super(NotificationAction.ACTION_COMMAND);
+ this.commandDescriptor = commandDescriptor;
+ }
+
+ /**
+ * Returns the command descriptor.
+ *
+ * @return the command descriptor
+ */
+ public String getDescriptor()
+ {
+ return commandDescriptor;
+ }
+}
Index: trunk/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java

--- trunk/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java (revision 9191)
+++ trunk/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java (revision 9192)
@@ -13,17 +13,11 @@
* @author Yana Stamcheva
*/
public interface CommandNotificationHandler
- extends NotificationActionHandler
+ extends NotificationHandler
{
/**
- * Executes the program pointed by the descriptor.
+ * Executes the program pointed by the descriptor.
+ * @param action the action to act upon
*/
- public void execute();
-
- /**
- * Returns the descriptor pointing to the command to be executed.
- *
- * @return the descriptor pointing to the command to be executed.
- */
- public String getDescriptor();
+ public void execute(CommandNotificationAction action);
}
Index: trunk/src/net/java/sip/communicator/service/notification/NotificationAction.java

--- trunk/src/net/java/sip/communicator/service/notification/NotificationAction.java (revision 0)
+++ trunk/src/net/java/sip/communicator/service/notification/NotificationAction.java (revision 9192)
@@ -0,0 +1,95 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.service.notification;
+
+/**
+ * Base class for actions of a notification.
+ *
+ * @author Ingo Bauersachs
+ */
+public abstract class NotificationAction
+{
+ /**
+ * The sound action type indicates that a sound would be played, when a
+ * notification is fired.
+ */
+ public static final String ACTION_SOUND = "SoundAction";
+
+ /**
+ * The popup message action type indicates that a window (or a systray
+ * popup), containing the corresponding notification message would be poped
+ * up, when a notification is fired.
+ */
+ public static final String ACTION_POPUP_MESSAGE = "PopupMessageAction";
+
+ /**
+ * The log message action type indicates that a message would be logged,
+ * when a notification is fired.
+ */
+ public static final String ACTION_LOG_MESSAGE = "LogMessageAction";
+
+ /**
+ * The command action type indicates that a command would be executed,
+ * when a notification is fired.
+ */
+ public static final String ACTION_COMMAND = "CommandAction";
+
+ /**
+ * Indicates if this handler is enabled.
+ */
+ private boolean isEnabled = true;
+
+ /**
+ * The action type name.
+ */
+ private String actionType;
+
+ /**
+ * Creates a new instance of this class.
+ * @param actionType The action type name.
+ */
+ protected NotificationAction(String actionType)
+ {
+ this.actionType = actionType;
+ }
+
+ /**
+ * Return the action type name.
+ * @return the action type name.
+ */
+ public String getActionType()
+ {
+ return actionType;
+ }
+
+ /**
+ * Returns TRUE if this notification action handler is enabled and FALSE
+ * otherwise. While the notification handler for the sound action type is
+ * disabled no sounds will be played when the <tt>fireNotification</tt>
+ * method is called.
+ *
+ * @return TRUE if this notification action handler is enabled and FALSE
+ * otherwise
+ */
+ public boolean isEnabled()
+ {
+ return isEnabled;
+ }
+
+ /**
+ * Enables or disables this notification handler. While the notification
+ * handler for the sound action type is disabled no sounds will be played
+ * when the <tt>fireNotification</tt> method is called.
+ *
+ * @param isEnabled TRUE to enable this notification handler, FALSE to
+ * disable it.
+ */
+ public void setEnabled(boolean isEnabled)
+ {
+ this.isEnabled = isEnabled;
+ }
+}
\ No newline at end of file
Index: trunk/src/net/java/sip/communicator/service/notification/NotificationHandler.java

--- trunk/src/net/java/sip/communicator/service/notification/NotificationHandler.java (revision 0)
+++ trunk/src/net/java/sip/communicator/service/notification/NotificationHandler.java (revision 9192)
@@ -0,0 +1,24 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.service.notification;
+
+/**
+ * The <tt>NotificationActionHandler</tt> is the parent interface of all specific
+ * notification handlers used for handling different action types. This
+ * interface is used in the NotificationService in all methods dealing with
+ * action handlers.
+ *
+ * @author Yana Stamcheva
+ */
+public interface NotificationHandler
+{
+ /**
+ * Gets the type of this handler.
+ * @return the type of this handler.
+ */
+ String getActionType();
+}
Index: trunk/src/net/java/sip/communicator/service/notification/NotificationServiceActivator.java

--- trunk/src/net/java/sip/communicator/service/notification/NotificationServiceActivator.java (revision 0)
+++ trunk/src/net/java/sip/communicator/service/notification/NotificationServiceActivator.java (revision 9192)
@@ -0,0 +1,77 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.service.notification;
+
+import net.java.sip.communicator.service.configuration.*;
+import net.java.sip.communicator.util.*;
+
+import org.osgi.framework.*;
+
+/**
+ * The <tt>NotificationActivator</tt> is the activator of the notification
+ * bundle.
+ *
+ * @author Yana Stamcheva
+ */
+public class NotificationServiceActivator
+ implements BundleActivator
+{
+ private final Logger logger
+ = Logger.getLogger(NotificationServiceActivator.class);
+
+ protected static BundleContext bundleContext;
+ private static ConfigurationService configService;
+ private ServiceRegistration notificationService;
+
+ public void start(BundleContext bc) throws Exception
+ {
+ bundleContext = bc;
+
+ try
+ {
+ logger.logEntry();
+ logger.info("Notification Service...[ STARTED ]");
+
+ notificationService = bundleContext.registerService(
+ NotificationService.class.getName(),
+ new NotificationServiceImpl(),
+ null);
+
+ logger.info("Notification Service ...[REGISTERED]");
+ }
+ finally
+ {
+ logger.logExit();
+ }
+ }
+
+ public void stop(BundleContext bc) throws Exception
+ {
+ notificationService.unregister();
+ logger.info("Notification Service ...[STOPPED]");
+ }
+
+ /**
+ * Returns the <tt>ConfigurationService</tt> obtained from the bundle
+ * context.
+ * @return the <tt>ConfigurationService</tt> obtained from the bundle
+ * context
+ */
+ public static ConfigurationService getConfigurationService()
+ {
+ if(configService == null)
+ {
+ ServiceReference configReference = bundleContext
+ .getServiceReference(ConfigurationService.class.getName());
+
+ configService = (ConfigurationService) bundleContext
+ .getService(configReference);
+ }
+
+ return configService;
+ }
+}
Index: trunk/src/net/java/sip/communicator/service/notification/Notification.java

--- trunk/src/net/java/sip/communicator/service/notification/Notification.java (revision 0)
+++ trunk/src/net/java/sip/communicator/service/notification/Notification.java (revision 9192)
@@ -0,0 +1,108 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.service.notification;
+
+import java.util.*;
+
+/**
+ * Represents an event notification.
+ *
+ * @author Yana Stamcheva
+ */
+public class Notification
+{
+ /**
+ * Indicates if this event notification is currently active. By default all
+ * notifications are active.
+ */
+ private boolean isActive = true;
+
+ /**
+ * Contains all actions which will be executed when this event notification
+ * is fired.
+ */
+ private final Hashtable<String, NotificationAction> actionsTable
+ = new Hashtable<String, NotificationAction>();
+
+ /**
+ * Creates an instance of <tt>EventNotification</tt> by specifying the
+ * event type as declared by the bundle registering it.
+ *
+ * @param eventType the name of the event
+ */
+ public Notification(String eventType)
+ {
+ }
+
+ /**
+ * Adds the given <tt>actionType</tt> to the list of actions for this event
+ * notifications.
+ * @param action the the handler that will process the given action
+ * type.
+ *
+ * @return the previous value of the actionHandler for the given actionType,
+ * if one existed, NULL if the actionType is a new one
+ */
+ public Object addAction(NotificationAction action)
+ {
+ return actionsTable.put(action.getActionType(), action);
+ }
+
+ /**
+ * Removes the action corresponding to the given <tt>actionType</tt>.
+ *
+ * @param actionType one of NotificationService.ACTION_XXX constants
+ */
+ public void removeAction(String actionType)
+ {
+ actionsTable.remove(actionType);
+ }
+
+ /**
+ * Returns the set of actions registered for this event notification.
+ *
+ * @return the set of actions registered for this event notification
+ */
+ public Map<String, NotificationAction> getActions()
+ {
+ return actionsTable;
+ }
+
+ /**
+ * Returns the <tt>Action</tt> corresponding to the given
+ * <tt>actionType</tt>.
+ *
+ * @param actionType one of NotificationService.ACTION_XXX constants
+ *
+ * @return the <tt>Action</tt> corresponding to the given
+ * <tt>actionType</tt>
+ */
+ public NotificationAction getAction(String actionType)
+ {
+ return actionsTable.get(actionType);
+ }
+
+ /**
+ * Indicates if this event notification is currently active.
+ *
+ * @return true if this event notification is active, false otherwise.
+ */
+ public boolean isActive()
+ {
+ return isActive;
+ }
+
+ /**
+ * Activates or deactivates this event notification.
+ *
+ * @param isActive indicates if this event notification is active
+ */
+ public void setActive(boolean isActive)
+ {
+ this.isActive = isActive;
+ }
+}

Property changes on: trunk/src/net/java/sip/communicator/service/notification/Notification.java
___________________________________________________________________
Added: svn:eol-style
+ native

Index: trunk/src/net/java/sip/communicator/service/notification/NotificationServiceImpl.java

--- trunk/src/net/java/sip/communicator/service/notification/NotificationServiceImpl.java (revision 0)
+++ trunk/src/net/java/sip/communicator/service/notification/NotificationServiceImpl.java (revision 9192)
@@ -0,0 +1,975 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.service.notification;
+
+import java.util.*;
+
+import net.java.sip.communicator.service.configuration.*;
+import net.java.sip.communicator.service.notification.event.*;
+import net.java.sip.communicator.util.*;
+import static net.java.sip.communicator.service.notification.NotificationAction.*;
+import static net.java.sip.communicator.service.notification.event.NotificationActionTypeEvent.*;
+import static net.java.sip.communicator.service.notification.event.NotificationEventTypeEvent.*;
+
+/**
+ * The implementation of the <tt>NotificationService</tt>.
+ *
+ * @author Yana Stamcheva
+ */
+class NotificationServiceImpl
+ implements NotificationService
+{
+ private final Logger logger
+ = Logger.getLogger(NotificationServiceImpl.class);
+
+ private final ConfigurationService configService =
+ NotificationServiceActivator.getConfigurationService();
+
+ private static final String NOTIFICATIONS_PREFIX
+ = "net.java.sip.communicator.impl.notifications";
+
+ /**
+ * A set of all registered event notifications.
+ */
+ private final Map<String, Notification> notifications
+ = new HashMap<String, Notification>();
+
+ /**
+ * A set of all registered event notifications.
+ */
+ private final Map<String, Notification> defaultNotifications
+ = new HashMap<String, Notification>();
+
+ /**
+ * Contains the notification handler per action type.
+ */
+ private final Map<String, NotificationHandler> handlers
+ = new HashMap<String, NotificationHandler>();
+
+ /**
+ * A list of all registered <tt>NotificationChangeListener</tt>s.
+ */
+ private final List<NotificationChangeListener> changeListeners
+ = new Vector<NotificationChangeListener>();
+
+ /**
+ * Creates an instance of <tt>NotificationServiceImpl</tt> by loading all
+ * previously saved notifications.
+ */
+ NotificationServiceImpl()
+ {
+ // Load all previously saved notifications.
+ this.loadNotifications();
+ }
+
+ /**
+ * Creates a new <tt>EventNotification</tt> or obtains the corresponding
+ * existing one and registers a new action in it.
+ *
+ * @param eventType the name of the event (as defined by the plugin that's
+ * registering it) that we are setting an action for.
+ * @param action the <tt>NotificationAction</tt> responsible for
+ * handling the given <tt>actionType</tt>
+ */
+ public void registerNotificationForEvent( String eventType,
+ NotificationAction action)
+ {
+ Notification notification = null;
+
+ if(notifications.containsKey(eventType))
+ notification = notifications.get(eventType);
+ else
+ {
+ notification = new Notification(eventType);
+ notifications.put(eventType, notification);
+
+ this.fireNotificationEventTypeEvent(
+ EVENT_TYPE_ADDED, eventType);
+ }
+
+ Object existingAction = notification.addAction(action);
+
+ // We fire the appropriate event depending on whether this is an
+ // already existing actionType or a new one.
+ if (existingAction != null)
+ {
+ fireNotificationActionTypeEvent(
+ ACTION_CHANGED,
+ eventType,
+ action);
+ }
+ else
+ {
+ fireNotificationActionTypeEvent(
+ ACTION_ADDED,
+ eventType,
+ action);
+ }
+
+ // Save the notification through the ConfigurationService.
+ this.saveNotification( eventType,
+ action,
+ true,
+ false);
+ }
+
+ /**
+ * Creates a new <tt>EventNotification</tt> or obtains the corresponding
+ * existing one and registers a new action in it.
+ *
+ * @param eventType the name of the event (as defined by the plugin that's
+ * registering it) that we are setting an action for.
+ * @param actionType the type of the action that is to be executed when the
+ * specified event occurs (could be one of the ACTION_XXX fields).
+ * @param actionDescriptor a String containing a description of the action
+ * (a URI to the sound file for audio notifications or a command line for
+ * exec action types) that should be executed when the action occurs.
+ * @param defaultMessage the default message to use if no specific message
+ * has been provided when firing the notification.
+ */
+ public void registerNotificationForEvent( String eventType,
+ String actionType,
+ String actionDescriptor,
+ String defaultMessage)
+ {
+ if (logger.isDebugEnabled())
+ logger.debug("Registering event " + eventType + "/" +
+ actionType + "/" + actionDescriptor + "/" + defaultMessage);
+
+ if (actionType.equals(ACTION_SOUND))
+ {
+ registerNotificationForEvent (eventType,
+ new SoundNotificationAction(actionDescriptor, -1));
+ }
+ else if (actionType.equals(ACTION_LOG_MESSAGE))
+ {
+ registerNotificationForEvent (eventType,
+ new LogMessageNotificationAction(
+ LogMessageNotificationAction.INFO_LOG_TYPE));
+ }
+ else if (actionType.equals(ACTION_POPUP_MESSAGE))
+ {
+ registerNotificationForEvent (eventType,
+ new PopupMessageNotificationAction(defaultMessa
[truncated due to length]


#2

Hey Damian,

I've been there and I find it a bit uncomfortable to be unable to
change a bundle's name because of a cache that does not function in
accord with Jitsi's intentions. Couldn't we implement a simple scheme
to purge Felix's cache whenever we rename or delete a bundle? For
example, we could keep an internal version of the cache which would be
incremented whenever we rename or delete a bundle and then upon
Jitsi's start it could purge the cache should the version of the cache
on the disk be less than the version compiled into Jitsi.

Regards,
Lyubomir

···

2011/12/6 Damian Minkov <damencho@sip-communicator.org>:

just one thing, when renaming bundles there comes a problem that
people that have already installed the previous version and install
the new one will end up running the same bundle twice, one with old
name and one with the new.


#3

Well I was looking at it and cannot see a cache for bundles (but was
sure I have seen such). So as long there are only references to the
files there will be no problem in renaming, cause updating application
removes old files and installs the new ones.

Sorry for the noise, seems I'm still using old information :slight_smile:

···

On Tue, Dec 6, 2011 at 10:04 AM, Lubomir Marinov <lubo@jitsi.org> wrote:

2011/12/6 Damian Minkov <damencho@sip-communicator.org>:

just one thing, when renaming bundles there comes a problem that
people that have already installed the previous version and install
the new one will end up running the same bundle twice, one with old
name and one with the new.

Hey Damian,

I've been there and I find it a bit uncomfortable to be unable to
change a bundle's name because of a cache that does not function in
accord with Jitsi's intentions. Couldn't we implement a simple scheme
to purge Felix's cache whenever we rename or delete a bundle? For
example, we could keep an internal version of the cache which would be
incremented whenever we rename or delete a bundle and then upon
Jitsi's start it could purge the cache should the version of the cache
on the disk be less than the version compiled into Jitsi.

Regards,
Lyubomir


#4

Hey

Well there is a cache of Felix, but it doesn't cache the bundle-jars itself, only some references to it. Problems might occur, when an old jar (that no longer exists in the build) is still lying in sc-bundles and when Felix' cache was never deleted. But such a situation only occurs for developers, easily solvable by doing "ant clean" or deleting ~/.jitsi/sip-communicator.bin.

The property org.osgi.framework.storage could be set to /tmp so the cache would get cleared from time to time (on Linux at least, Windows doesn't clear the temp directory as you might know).
In general, I keep it with Lyubomir's opinion: our bundle-names shouldn't be restricted by some caching. As OSGi-Bundles already wear a version number, wouldn't using this version number more intensively be enough to "flush" the cache for that bundle?

Regards,
Ingo

···

-----Original Message-----
From: damencho@damencho.com [mailto:damencho@damencho.com] On Behalf Of
Damian Minkov
Sent: Dienstag, 6. Dezember 2011 10:03
To: dev@jitsi.java.net
Subject: [jitsi-dev] Re: [jitsi~svn:9192] Separate notification service from
its handlers

Well I was looking at it and cannot see a cache for bundles (but was
sure I have seen such). So as long there are only references to the
files there will be no problem in renaming, cause updating application
removes old files and installs the new ones.

Sorry for the noise, seems I'm still using old information :slight_smile:

On Tue, Dec 6, 2011 at 10:04 AM, Lubomir Marinov <lubo@jitsi.org> wrote:
> 2011/12/6 Damian Minkov <damencho@sip-communicator.org>:
>> just one thing, when renaming bundles there comes a problem that
>> people that have already installed the previous version and install
>> the new one will end up running the same bundle twice, one with old
>> name and one with the new.
>
> Hey Damian,
>
> I've been there and I find it a bit uncomfortable to be unable to
> change a bundle's name because of a cache that does not function in
> accord with Jitsi's intentions. Couldn't we implement a simple scheme
> to purge Felix's cache whenever we rename or delete a bundle? For
> example, we could keep an internal version of the cache which would be
> incremented whenever we rename or delete a bundle and then upon
> Jitsi's start it could purge the cache should the version of the cache
> on the disk be less than the version compiled into Jitsi.
>
> Regards,
> Lyubomir