From 386c559bb287e352bf063cbeaec41d72a0121e8f Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Sat, 20 Oct 2012 18:40:29 +0000 Subject: [PATCH] Fixes a memory leak in NotificationManager. Removes an unnecessary copying of a List in CallManager. --- .../impl/gui/main/call/CallManager.java | 22 ++--- .../SoundNotificationHandlerImpl.java | 2 +- .../NotificationManager.java | 84 ++++++++++++++----- 3 files changed, 70 insertions(+), 38 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java index fe6ed9bca..9d74398a2 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java @@ -1200,11 +1200,11 @@ public static List getTelephonyProviders() } /** - * Returns a collection of all currently active calls. + * Returns a list of all currently active calls. * - * @return a collection of all currently active calls + * @return a list of all currently active calls */ - public static Collection getActiveCalls() + private static List getActiveCalls() { CallConference[] conferences; @@ -1229,23 +1229,15 @@ public static Collection getActiveCalls() } /** - * Returns a collection of all currently in progress calls. + * Returns a collection of all currently in progress calls. A call is active + * if it is in progress so the method merely delegates to + * {@link #getActiveCalls()}. * * @return a collection of all currently in progress calls. */ public static Collection getInProgressCalls() { - /* TODO Synchronize the access to the callPanels field. */ - - Collection calls = getActiveCalls(); - List inProgressCalls = new ArrayList(calls.size()); - - for (Call call : calls) - { - if (call.getCallState() == CallState.CALL_IN_PROGRESS) - inProgressCalls.add(call); - } - return inProgressCalls; + return getActiveCalls(); } /** diff --git a/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java b/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java index 5e6156fc4..adb789ab6 100644 --- a/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java +++ b/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java @@ -80,7 +80,7 @@ private void play( { UIService uiService = NotificationActivator.getUIService(); - if(uiService.getInProgressCalls().size() > 0) + if(!uiService.getInProgressCalls().isEmpty()) return; } diff --git a/src/net/java/sip/communicator/plugin/notificationwiring/NotificationManager.java b/src/net/java/sip/communicator/plugin/notificationwiring/NotificationManager.java index 6cb0231a9..42deed6d0 100644 --- a/src/net/java/sip/communicator/plugin/notificationwiring/NotificationManager.java +++ b/src/net/java/sip/communicator/plugin/notificationwiring/NotificationManager.java @@ -565,21 +565,6 @@ private static boolean shouldPlayDialingSound( return play; } - /** - * Stops all sounds for the given event type. - * - * @param data the event type for which we should stop sounds. One of - * the static event types defined in this class. - */ - public static void stopSound(NotificationData data) - { - NotificationService notificationService - = NotificationWiringActivator.getNotificationService(); - - if(notificationService != null) - notificationService.stopNotification(data); - } - /** * Stores notification references to stop them if a notification has expired * (e.g. to stop the dialing sound). @@ -617,7 +602,15 @@ public void callEnded(CallEvent ev) } catch(Throwable t) { - logger.error("Error notifying for call ended", t); + if (t instanceof ThreadDeath) + throw (ThreadDeath) t; + else + { + logger.error( + "An error occurred while trying to notify" + + " about the end of a call.", + t); + } } } @@ -1453,7 +1446,15 @@ else if ((newState == CallPeerState.DISCONNECTED) } catch(Throwable t) { - logger.error("Error notifying after peer state changed", t); + if (t instanceof ThreadDeath) + throw (ThreadDeath) t; + else + { + logger.error( + "An error occurred while trying to notify" + + " about a change in the state of a call peer.", + t); + } } } @@ -1539,13 +1540,12 @@ private void registerDefaultNotifications() inCallSoundHandler); // Register outgoing call notifications. - SoundNotificationAction outCallSoundHandler - = new SoundNotificationAction( - SoundProperties.OUTGOING_CALL, 3000, false, true, false); - notificationService.registerDefaultNotificationForEvent( OUTGOING_CALL, - outCallSoundHandler); + new SoundNotificationAction( + SoundProperties.OUTGOING_CALL, + 3000, + false, true, false)); // Register busy call notifications. notificationService.registerDefaultNotificationForEvent( @@ -1766,6 +1766,46 @@ public void serviceChanged(ServiceEvent event) } } + /** + * Stops all sounds for the given event type. + * + * @param data the event type for which we should stop sounds. One of + * the static event types defined in this class. + */ + private void stopSound(NotificationData data) + { + if (data == null) + return; + + try + { + NotificationService notificationService + = NotificationWiringActivator.getNotificationService(); + + if(notificationService != null) + notificationService.stopNotification(data); + } + finally + { + /* + * The field callNotifications associates a Call with a + * NotificationData for the purposes of the stopSound method so the + * stopSound method should dissociate them upon stopping a specific + * NotificationData. + */ + Iterator> i + = callNotifications.entrySet().iterator(); + + while (i.hasNext()) + { + Map.Entry e = i.next(); + + if (data.equals(e.getValue())) + i.remove(); + } + } + } + /** * {@inheritDoc} *