jmri.util.zeroconf
Class ZeroConfService

java.lang.Object
  extended by jmri.util.zeroconf.ZeroConfService

public class ZeroConfService
extends Object

ZeroConfService objects manage a zeroConf network service advertisement.

ZeroConfService objects encapsulate zeroConf network services created using JmDNS, providing methods to start and stop service advertisements and to query service state. Typical usage would be:

 ZeroConfService myService = ZeroConfService.create("_withrottle._tcp.local.", port);
 
or, if you do not wish to retain the ZeroConfService object:
 ZeroConfService.create("_http._tcp.local.", port).publish();
 
ZeroConfService objects can also be created with a HashMap of properties that are included in the TXT record for the service advertisement. This HashMap should remain small, but it could include information such as the XMLIO path (for a web server), the default path (also for a web server), a specific protocol version, or other information. Note that all service advertisements include the JMRI version, using the key "jmri".

All ZeroConfServices are automatically stopped when the JMRI application shuts down. A collection of all ZeroConfService objects is available with:

ZeroConfService.allServices()
.
This file is part of JMRI.

JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.

JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Author:
Randall Wood Copyright (C) 2011
See Also:
JmDNS, ServiceInfo

Constructor Summary
protected ZeroConfService(javax.jmdns.ServiceInfo service)
          Create a ZeroConfService object.
 
Method Summary
 Collection<ZeroConfService> allServices()
          A list of published ZeroConfServices
static ZeroConfService create(String type, int port)
          Create a ZeroConfService with the minimal required settings.
static ZeroConfService create(String type, int port, HashMap<String,String> props)
          Create a ZeroConfService with an automatically detected server name.
static ZeroConfService create(String type, String name, int port, int weight, int priority, HashMap<String,String> props)
          Create a ZeroConfService.
static String hostName()
          Return the system name or "computer" if the system name cannot be determined.
 Boolean isPublished()
          Get the state of the service.
 String key()
          Get the key of the ZeroConfService object.
protected static String key(String type, String name)
          Generate a ZeroConfService key for searching in the HashMap of running services.
 String name()
          Get the name of the ZeroConfService object.
 void publish()
          Start advertising the service.
 javax.jmdns.ServiceInfo serviceInfo()
          Get the ServiceInfo property of the object.
 void stop()
          Stop advertising the service.
static void stopAll()
          Stop advertising all services.
 String type()
          Get the type of the ZeroConfService object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZeroConfService

protected ZeroConfService(javax.jmdns.ServiceInfo service)
Create a ZeroConfService object.

Parameters:
service -
Method Detail

create

public static ZeroConfService create(String type,
                                     int port)
Create a ZeroConfService with the minimal required settings. This method calls
create(type, port, props)
with an empty props HashMap.

Parameters:
type -
port -

create

public static ZeroConfService create(String type,
                                     int port,
                                     HashMap<String,String> props)
Create a ZeroConfService with an automatically detected server name. This method calls
create
with the default weight and priority, and with the name "hostName" with dots and dashes replaced with spaces.

Parameters:
type -
port -
props -

create

public static ZeroConfService create(String type,
                                     String name,
                                     int port,
                                     int weight,
                                     int priority,
                                     HashMap<String,String> props)
Create a ZeroConfService. The TXT record property "jmri" is added or replaced with the current JMRI version as its value. If a service with the same key as the new service is already published, that service is returned instead of a new object.

Parameters:
name -
type -
port -
weight -
priority -
props -

key

public String key()
Get the key of the ZeroConfService object. The key is fully qualified name of the service in all lowercase, jmri._http.local.


key

protected static String key(String type,
                            String name)
Generate a ZeroConfService key for searching in the HashMap of running services.

Parameters:
type -
name -

name

public String name()
Get the name of the ZeroConfService object. The name can only be set when creating the object.


type

public String type()
Get the type of the ZeroConfService object. The type can only be set when creating the object.


serviceInfo

public javax.jmdns.ServiceInfo serviceInfo()
Get the ServiceInfo property of the object. This is the JmDNS implementation of a zeroConf service.


isPublished

public Boolean isPublished()
Get the state of the service. True if the service is being advertised, and false otherwise.


publish

public void publish()
Start advertising the service.


stop

public void stop()
Stop advertising the service.


stopAll

public static void stopAll()
Stop advertising all services.


allServices

public Collection<ZeroConfService> allServices()
A list of published ZeroConfServices


hostName

public static String hostName()
Return the system name or "computer" if the system name cannot be determined. This method uses the JmDNS.getHostName() method.



Copyright © 1997 - 2011 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads