Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.zeroconf.jmdns
Class ServiceInfo

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.zeroconf.jmdns.ServiceInfo
All Implemented Interfaces:
DNSListener

public class ServiceInfo
extends Object
implements DNSListener

JmDNS service information.

Version:
%I%, %G%
Author:
Arthur van Hoff, Jeff Sonstein, Werner Randelshofer

Field Summary
(package private)  InetAddress addr
           
(package private)  JmDNS dns
           
static byte[] NO_VALUE
           
(package private)  int port
           
(package private)  int priority
           
(package private)  String server
           
(package private)  TimerTask task
          Task associated to this service info.
(package private)  byte[] text
           
(package private)  String type
           
(package private)  int weight
           
 
Constructor Summary
ServiceInfo(ServiceInfo info)
          During recovery we need to duplicate service info to reregister them
ServiceInfo(String type, String name)
          Construct a service record during service discovery.
ServiceInfo(String type, String name, int port, int weight, int priority, byte[] text)
          Construct a service description for registrating with JmDNS.
ServiceInfo(String type, String name, int port, int weight, int priority, Map<String,Object> props)
          Construct a service description for registrating with JmDNS.
ServiceInfo(String type, String name, int port, int weight, int priority, String text)
          Construct a service description for registrating with JmDNS.
ServiceInfo(String type, String name, int port, String text)
          Construct a service description for registrating with JmDNS.
 
Method Summary
(package private)  void advanceState()
          Sets the state and notifies all objects that wait on the ServiceInfo.
(package private)  void cancel()
          Sets the state and notifies all objects that wait on the ServiceInfo.
 boolean equals(Object obj)
           
 InetAddress getAddress()
           
 String getHostAddress()
          Get the host address of the service (ie X.X.X.X).
 InetAddress getInetAddress()
          Get the InetAddress of the service.
 String getName()
          Unqualified service instance name, such as foobar .
 String getNiceTextString()
           
 int getPort()
          Get the port for the service.
 int getPriority()
          Get the priority of the service.
(package private)  Map<String,Object> getProperties()
           
 byte[] getPropertyBytes(String name)
          Get a property of the service.
 Iterator<String> getPropertyNames()
          Iterator of the property names.
 String getPropertyString(String name)
          Get a property of the service.
 String getQualifiedName()
          Fully qualified service name, such as foobar._http._tcp.local. .
 String getServer()
          Get the name of the server.
(package private)  DNSState getState()
          Returns the current state of this info.
 byte[] getTextBytes()
          Get the text for the serivce as raw bytes.
 String getTextString()
          Get the text for the service.
 String getType()
          Fully qualified service type name, such as _http._tcp.local. .
 String getURL()
          Get the URL for this service.
 String getURL(String protocol)
          Get the URL for this service.
 int getWeight()
          Get the weight of the service.
(package private)  boolean hasData()
          Returns true if the service info is filled with data.
 int hashCode()
           
(package private)  String readUTF(byte[] data, int off, int len)
          Read data bytes as a UTF stream.
(package private)  void revertState()
          Sets the state and notifies all objects that wait on the ServiceInfo.
(package private)  void setName(String name)
          Sets the service instance name.
 void setProps(Map<String,Object> props)
          SC-Bonjour Implementation: Method used to set the properties of an existing ServiceInfo.
 String toString()
           
 void updateRecord(JmDNS jmdns, long now, DNSRecord rec)
          JmDNS callback to update a DNS record.
(package private)  void writeUTF(OutputStream out, String str)
          Write a UTF string with a length to a stream.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_VALUE

public static final byte[] NO_VALUE

dns

JmDNS dns

task

TimerTask task
Task associated to this service info. Possible tasks are JmDNS.Prober, JmDNS.Announcer, JmDNS.Responder, JmDNS.Canceler.


type

String type

server

String server

port

int port

weight

int weight

priority

int priority

text

byte[] text

addr

InetAddress addr
Constructor Detail

ServiceInfo

public ServiceInfo(String type,
                   String name,
                   int port,
                   String text)
Construct a service description for registrating with JmDNS.

Parameters:
type - fully qualified service type name, such as _http._tcp.local..
name - unqualified service instance name, such as foobar
port - the local port on which the service runs
text - string describing the service

ServiceInfo

public ServiceInfo(String type,
                   String name,
                   int port,
                   int weight,
                   int priority,
                   String text)
Construct a service description for registrating with JmDNS.

Parameters:
type - fully qualified service type name, such as _http._tcp.local..
name - unqualified service instance name, such as foobar
port - the local port on which the service runs
weight - weight of the service
priority - priority of the service
text - string describing the service

ServiceInfo

public ServiceInfo(String type,
                   String name,
                   int port,
                   int weight,
                   int priority,
                   Map<String,Object> props)
Construct a service description for registrating with JmDNS. The properties hashtable must map property names to either Strings or byte arrays describing the property values.

Parameters:
type - fully qualified service type name, such as _http._tcp.local..
name - unqualified service instance name, such as foobar
port - the local port on which the service runs
weight - weight of the service
priority - priority of the service
props - properties describing the service

ServiceInfo

public ServiceInfo(String type,
                   String name,
                   int port,
                   int weight,
                   int priority,
                   byte[] text)
Construct a service description for registrating with JmDNS.

Parameters:
type - fully qualified service type name, such as _http._tcp.local..
name - unqualified service instance name, such as foobar
port - the local port on which the service runs
weight - weight of the service
priority - priority of the service
text - bytes describing the service

ServiceInfo

ServiceInfo(String type,
            String name)
Construct a service record during service discovery.


ServiceInfo

ServiceInfo(ServiceInfo info)
During recovery we need to duplicate service info to reregister them

Method Detail

getType

public String getType()
Fully qualified service type name, such as _http._tcp.local. .

Returns:
Returns fully qualified service type name.

getName

public String getName()
Unqualified service instance name, such as foobar .

Returns:
Returns unqualified service instance name.

setName

void setName(String name)
Sets the service instance name.

Parameters:
name - unqualified service instance name, such as foobar

getQualifiedName

public String getQualifiedName()
Fully qualified service name, such as foobar._http._tcp.local. .

Returns:
Returns fully qualified service name.

getServer

public String getServer()
Get the name of the server.

Returns:
Returns name of the server.

getHostAddress

public String getHostAddress()
Get the host address of the service (ie X.X.X.X).

Returns:
Returns host address of the service.

getAddress

public InetAddress getAddress()

getInetAddress

public InetAddress getInetAddress()
Get the InetAddress of the service.

Returns:
Returns the InetAddress of the service.

getPort

public int getPort()
Get the port for the service.

Returns:
Returns port for the service.

getPriority

public int getPriority()
Get the priority of the service.

Returns:
Returns the priority of the service.

getWeight

public int getWeight()
Get the weight of the service.

Returns:
Returns the weight of the service.

getTextBytes

public byte[] getTextBytes()
Get the text for the serivce as raw bytes.

Returns:
Returns the text for the serivce as raw bytes.

getTextString

public String getTextString()
Get the text for the service. This will interpret the text bytes as a UTF8 encoded string. Will return null if the bytes are not a valid UTF8 encoded string.

Returns:
Returns the text for the service.

getURL

public String getURL()
Get the URL for this service. An http URL is created by combining the address, port, and path properties.

Returns:
Returns the URL for this service.

getURL

public String getURL(String protocol)
Get the URL for this service. An URL is created by combining the protocol, address, port, and path properties.

Parameters:
protocol -
Returns:
Returns URL for this service.

getPropertyBytes

public byte[] getPropertyBytes(String name)
Get a property of the service. This involves decoding the text bytes into a property list. Returns null if the property is not found or the text data could not be decoded correctly.

Parameters:
name -
Returns:
Returns property of the service as bytes.

getPropertyString

public String getPropertyString(String name)
Get a property of the service. This involves decoding the text bytes into a property list. Returns null if the property is not found, the text data could not be decoded correctly, or the resulting bytes are not a valid UTF8 string.

Parameters:
name -
Returns:
Returns property of the service as string.

getPropertyNames

public Iterator<String> getPropertyNames()
Iterator of the property names.

Returns:
Iterator of the property names.

writeUTF

void writeUTF(OutputStream out,
              String str)
        throws IOException
Write a UTF string with a length to a stream.

Throws:
IOException

readUTF

String readUTF(byte[] data,
               int off,
               int len)
Read data bytes as a UTF stream.


getProperties

Map<String,Object> getProperties()

updateRecord

public void updateRecord(JmDNS jmdns,
                         long now,
                         DNSRecord rec)
JmDNS callback to update a DNS record.

Specified by:
updateRecord in interface DNSListener
Parameters:
rec -

hasData

boolean hasData()
Returns true if the service info is filled with data.


advanceState

void advanceState()
Sets the state and notifies all objects that wait on the ServiceInfo.


revertState

void revertState()
Sets the state and notifies all objects that wait on the ServiceInfo.


cancel

void cancel()
Sets the state and notifies all objects that wait on the ServiceInfo.


getState

DNSState getState()
Returns the current state of this info.


hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

getNiceTextString

public String getNiceTextString()

toString

public String toString()
Overrides:
toString in class Object

setProps

public void setProps(Map<String,Object> props)
SC-Bonjour Implementation: Method used to set the properties of an existing ServiceInfo. This is used in the implementation of Bonjour in SIP Communicator to be able to replace old properties of the service we've declared to announce the local user with new properties (for example in case of a status change).

Parameters:
props - Hashtable containing all the new properties to set

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.