Permalink
Browse files

Adds log info when the addrbook plugin starts, stops, registers and u…

…nregisters. Corrects function to resolve the display name when receiving a call.
  • Loading branch information...
Vincent Lucas
Vincent Lucas committed May 17, 2013
1 parent d85567a commit e9f0e98ca433524f85efb0a529a8ed3f43f553a4
@@ -20,6 +20,7 @@
import net.java.sip.communicator.plugin.desktoputil.*;
import net.java.sip.communicator.plugin.desktoputil.transparent.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.contactsource.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
@@ -1368,11 +1369,20 @@ public static String getPeerDisplayName(CallPeer peer)
}
if (StringUtils.isNullOrEmpty(displayName, true))
{
displayName = (!StringUtils.isNullOrEmpty
(peer.getDisplayName(), true))
? peer.getDisplayName()
: peer.getAddress();
// Try to resolve the display name
String resolvedName = resolveContactSource(displayName);

This comment has been minimized.

Show comment
Hide comment
@ibauersachs

ibauersachs May 17, 2013

Member

Shouldn't this be above the last null-check (line 1370/1371) and always using the peerAddress rather than a peer DisplayName?

@ibauersachs

ibauersachs May 17, 2013

Member

Shouldn't this be above the last null-check (line 1370/1371) and always using the peerAddress rather than a peer DisplayName?

if(resolvedName != null)
{
displayName = resolvedName;
}
}
return displayName;
}
@@ -3555,4 +3565,81 @@ public static void call(UIContact uiContact,
invoker,
location);
}
/**
* Tries to resolves a peer address into a display name, by reqesting the
* <tt>ContactSourceService</tt>s. This function returns only the
* first match.
*
* @param peerAddress The peer address.
*
* @return The corresponding display name, if there is a match. Null
* otherwise.
*/
private static String resolveContactSource(String peerAddress)
{
String displayName = null;
if(!StringUtils.isNullOrEmpty(peerAddress))
{
Vector<ResolveAddressToDisplayNameContactQueryListener> resolvers
= new Vector<ResolveAddressToDisplayNameContactQueryListener>
(1, 1);
// Queries all available resolvers
for(ContactSourceService contactSourceService:
GuiActivator.getContactSources())
{
ContactQuery query
= contactSourceService.queryContactSource(peerAddress, 1);
resolvers.add(
new ResolveAddressToDisplayNameContactQueryListener(
query));
}
long startTime = System.currentTimeMillis();
long currentTime = startTime;
// The detault timeout is set to 500ms.
long timeout = 500;
// Loops until we found a valid display name, or waits for timeout.
while(displayName == null
&& currentTime - startTime < timeout)
{
for(int i = 0; i < resolvers.size() && displayName == null; ++i)
{
ResolveAddressToDisplayNameContactQueryListener resolver
= resolvers.get(i);
if(!resolver.isRunning())
{
if(resolver.isFound())
{
displayName = resolver.getResolvedName();
// If this is the same result as the peer address,
// then that is not what we are looking for. Then,
// continue the search.
if(displayName.equals(peerAddress))
{
displayName = null;
}
}
}
}
Thread.yield();
currentTime = System.currentTimeMillis();
}
// Free lasting resolvers.
for(int i = 0; i < resolvers.size(); ++i)
{
ResolveAddressToDisplayNameContactQueryListener resolver
= resolvers.get(i);
if(resolver.isRunning())
{
resolver.stop();
}
}
}
return displayName;
}
}
@@ -0,0 +1,128 @@
/*
* 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.impl.gui.main.call;
import net.java.sip.communicator.service.contactsource.*;
import org.jitsi.util.*;
/**
* Listener for a contact query, used in order to resolve a contact adress
* into a display name.
*
* @author Vincent Lucas
*/
public class ResolveAddressToDisplayNameContactQueryListener
implements ContactQueryListener
{
/**
* The query we are looking for events.
*/
private ContactQuery query;
/**
* The display name corresponding to the contact address.
*/
private String resolvedName;
/**
* Creates a new ResolvedContactQueryListener.
*/
public ResolveAddressToDisplayNameContactQueryListener(ContactQuery query)
{
this.resolvedName = null;
this.query = query;
if(this.query != null)
{
this.query.addContactQueryListener(this);
}
}
/**
* Indicates that a contact has been updated after a search.
*/
public void contactChanged(ContactChangedEvent event)
{
// NOT USED
}
/**
* Indicates that a new contact has been received for a search.
*/
public void contactReceived(ContactReceivedEvent event)
{
SourceContact contact = event.getContact();
if(contact != null)
{
this.resolvedName = contact.getDisplayName();
if(isFound())
{
this.stop();
}
}
}
/**
* Indicates that a contact has been removed after a search.
*/
public void contactRemoved(ContactRemovedEvent event)
{
// NOT USED
}
/**
* Indicates that the status of a search has been changed.
*/
public void queryStatusChanged(ContactQueryStatusEvent event)
{
this.stop();
}
/**
* Tells if the query is still running.
*
* @return True if the query is still running. False otherwise.
*/
public boolean isRunning()
{
return this.query != null;
}
/**
* Stops this ResolvedContactQueryListener.
*/
public synchronized void stop()
{
if(this.query != null)
{
this.query.removeContactQueryListener(this);
this.query.cancel();
this.query = null;
}
}
/**
* Tells if the query has found a match to resolve the contact address.
*
* @return True if the query has found a match to resolve the contact
* address. False otherwise.
*/
public boolean isFound()
{
return !StringUtils.isNullOrEmpty(resolvedName);
}
/**
* Returns the display name corresponding to the contact address.
*
* @return The display name corresponding to the contact address. Null
* or empty string if not found.
*/
public String getResolvedName()
{
return this.resolvedName;
}
}
@@ -126,6 +126,11 @@ public static ConfigurationService getConfigService()
public void start(BundleContext bundleContext)
throws Exception
{
if (logger.isInfoEnabled())
logger.info("Address book \""
+ "plugin.addrbook.ADDRESS_BOOKS"
+ "\" ... [STARTED]");
AddrBookActivator.bundleContext = bundleContext;
Dictionary<String, String> properties = new Hashtable<String, String>();
@@ -159,6 +164,11 @@ public void start(BundleContext bundleContext)
public void stop(BundleContext bundleContext)
throws Exception
{
if (logger.isInfoEnabled())
logger.info("Address book \""
+ "plugin.addrbook.ADDRESS_BOOKS"
+ "\" ... [STOPPED]");
stopService();
}
@@ -221,6 +231,13 @@ else if (OSUtils.IS_MAC
((AsyncContactSourceService) css).stop();
css = null;
}
else
{
if (logger.isInfoEnabled())
logger.info("Address book \""
+ css.getDisplayName()
+ "\" ... [REGISTERED]");
}
}
}
@@ -243,6 +260,12 @@ static void stopService()
{
if (css instanceof AsyncContactSourceService)
((AsyncContactSourceService) css).stop();
if (logger.isInfoEnabled())
logger.info("Address book \""
+ css.getDisplayName()
+ "\" ... [UNREGISTERED]");
css = null;
}
}

0 comments on commit e9f0e98

Please sign in to comment.