org.livetribe.slp
Class ServiceInfo

java.lang.Object
  extended by org.livetribe.slp.ServiceInfo

public class ServiceInfo
extends Object

This class represents a service, exposed by ServiceAgents and cached by DirectoryAgents.
In SLP, services are distinguished by their ServiceURL and by their language; these two elements form the key of the service. Two service registration with the same key overwrite each other.
IMPLEMENTATION NOTES: There is an asymmetry in SLP that allows (ServiceURL1, language1) to be registered under two different ServiceTypes (this is allowed by the format of SrvReg), but not deregistered from one ServiceType only (as SrvDeReg does not support an additional ServiceType field).
Attributes are not involved in service equality since they can contain locale-specific information (for example: (color=Yellow) with language English, and (color=Giallo) with language Italian.

Version:
$Rev: 258 $ $Date: 2006-08-23 15:45:17 +0200 (Wed, 23 Aug 2006) $
See Also:
ServiceURL, Attributes

Nested Class Summary
static class ServiceInfo.Key
          Services in SLP are identified by their ServiceURL and their language.
 
Constructor Summary
ServiceInfo(ServiceType serviceType, ServiceURL serviceURL, Scopes scopes, Attributes attributes, String language)
          Creates a ServiceInfo from the given arguments; the ServiceInfo(ServiceURL, Scopes, Attributes, String) constructor should be preferred to this one, as it does not introduce ambiguity between the ServiceType argument and the ServiceType of the ServiceURL argument.
ServiceInfo(ServiceURL serviceURL, Scopes scopes, Attributes attributes, String language)
          Creates a ServiceInfo from a the given arguments.
 
Method Summary
protected  ServiceInfo clone(ServiceType serviceType, ServiceURL serviceURL, Scopes scopes, Attributes attributes, String language)
          Returns a new clone of this ServiceInfo with the given arguments.
static ServiceInfo from(SrvDeReg message)
          Creates a ServiceInfo from a SrvDeReg message.
static ServiceInfo from(SrvReg message)
          Creates a ServiceInfo from a SrvReg message.
 Attributes getAttributes()
          Returns the Attributes of this ServiceInfo.
 ServiceInfo.Key getKey()
          Returns the key of this ServiceInfo.
 String getLanguage()
          Returns the language of this ServiceInfo.
 long getRegistrationTime()
          Returns the registration time of this ServiceInfo, in milliseconds since the Unix epoch.
 Scopes getScopes()
          Returns the Scopes of this ServiceInfo.
 ServiceType getServiceType()
          Returns the ServiceType as provided to the constructors; prefer resolveServiceType() to get the ServiceType of this ServiceInfo.
 ServiceURL getServiceURL()
          Returns the ServiceURL of this ServiceInfo.
 boolean hasAttributes()
          Returns whether this ServiceInfo has attributes or not.
 boolean isExpiredAsOf(long time)
          Returns true if the ServiceURL's lifetime is expired, since its registration, as of the specified time.
 ServiceInfo merge(ServiceInfo that)
          Merges the attributes of this ServiceInfo with the attributes of the given ServiceInfo, provided the two ServiceInfos have the same key.
 ServiceType resolveServiceType()
          Returns the ServiceType as provided to the constructor; if this value is null, returns the ServiceType of the ServiceURL of this ServiceInfo.
 void setRegistrationTime(long registrationTime)
          Set the registration time of this ServiceInfo, in milliseconds since the Unix epoch.
 ServiceInfo unmerge(ServiceInfo that)
          Unmerges the attributes of this ServiceInfo with the attributes of the given ServiceInfo, provided the two ServiceInfos have the same key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceInfo

public ServiceInfo(ServiceURL serviceURL,
                   Scopes scopes,
                   Attributes attributes,
                   String language)
Creates a ServiceInfo from a the given arguments.

Parameters:
serviceURL - The service URL of the service
scopes - The scopes of the service
attributes - The attributes of the service
language - The language of the service

ServiceInfo

public ServiceInfo(ServiceType serviceType,
                   ServiceURL serviceURL,
                   Scopes scopes,
                   Attributes attributes,
                   String language)
Creates a ServiceInfo from the given arguments; the ServiceInfo(ServiceURL, Scopes, Attributes, String) constructor should be preferred to this one, as it does not introduce ambiguity between the ServiceType argument and the ServiceType of the ServiceURL argument.

Method Detail

from

public static ServiceInfo from(SrvReg message)
Creates a ServiceInfo from a SrvReg message.


from

public static ServiceInfo from(SrvDeReg message)
Creates a ServiceInfo from a SrvDeReg message.


getKey

public ServiceInfo.Key getKey()
Returns the key of this ServiceInfo.


getServiceType

public ServiceType getServiceType()
Returns the ServiceType as provided to the constructors; prefer resolveServiceType() to get the ServiceType of this ServiceInfo.

See Also:
resolveServiceType()

getServiceURL

public ServiceURL getServiceURL()
Returns the ServiceURL of this ServiceInfo.


getScopes

public Scopes getScopes()
Returns the Scopes of this ServiceInfo.


getAttributes

public Attributes getAttributes()
Returns the Attributes of this ServiceInfo.


hasAttributes

public boolean hasAttributes()
Returns whether this ServiceInfo has attributes or not.


getLanguage

public String getLanguage()
Returns the language of this ServiceInfo.


resolveServiceType

public ServiceType resolveServiceType()
Returns the ServiceType as provided to the constructor; if this value is null, returns the ServiceType of the ServiceURL of this ServiceInfo.


merge

public ServiceInfo merge(ServiceInfo that)
Merges the attributes of this ServiceInfo with the attributes of the given ServiceInfo, provided the two ServiceInfos have the same key.

Parameters:
that - The ServiceInfo to merge with
Returns:
A newly created ServiceInfo, result of the merge, or null if this ServiceInfo and the given ServiceInfo do not have the same key.
See Also:
Attributes.merge(Attributes)

unmerge

public ServiceInfo unmerge(ServiceInfo that)
Unmerges the attributes of this ServiceInfo with the attributes of the given ServiceInfo, provided the two ServiceInfos have the same key.

Parameters:
that - The ServiceInfo to unmerge with
Returns:
A newly created ServiceInfo, result of the unmerge, or null if this ServiceInfo and the given ServiceInfo do not have the same key.
See Also:
Attributes.unmerge(Attributes)

clone

protected ServiceInfo clone(ServiceType serviceType,
                            ServiceURL serviceURL,
                            Scopes scopes,
                            Attributes attributes,
                            String language)
Returns a new clone of this ServiceInfo with the given arguments. Subclasses may override to clone additional state.


getRegistrationTime

public long getRegistrationTime()
Returns the registration time of this ServiceInfo, in milliseconds since the Unix epoch.


setRegistrationTime

public void setRegistrationTime(long registrationTime)
Set the registration time of this ServiceInfo, in milliseconds since the Unix epoch.


isExpiredAsOf

public boolean isExpiredAsOf(long time)
Returns true if the ServiceURL's lifetime is expired, since its registration, as of the specified time.

Parameters:
time - The time, in milliseconds, to check if the lifetime is expired.
See Also:
getRegistrationTime(), ServiceURL.getLifetime()


Copyright © 2006-2012 LiveTribe. All Rights Reserved.