use of javax.jmdns.ServiceInfo in project JAirPort by froks.
the class JmDNSImpl method start.
private void start(Collection<? extends ServiceInfo> serviceInfos) {
if (_incomingListener == null) {
_incomingListener = new SocketListener(this);
_incomingListener.start();
}
this.startProber();
for (ServiceInfo info : serviceInfos) {
try {
this.registerService(new ServiceInfoImpl(info));
} catch (final Exception exception) {
logger.log(Level.WARNING, "start() Registration exception ", exception);
}
}
}
use of javax.jmdns.ServiceInfo in project JAirPort by froks.
the class JmmDNSImpl method listBySubtype.
/*
* (non-Javadoc)
* @see javax.jmdns.JmmDNS#listBySubtype(java.lang.String, long)
*/
@Override
public Map<String, ServiceInfo[]> listBySubtype(final String type, final long timeout) {
Map<String, List<ServiceInfo>> map = new HashMap<String, List<ServiceInfo>>(5);
for (ServiceInfo info : this.list(type, timeout)) {
String subtype = info.getSubtype();
if (!map.containsKey(subtype)) {
map.put(subtype, new ArrayList<ServiceInfo>(10));
}
map.get(subtype).add(info);
}
Map<String, ServiceInfo[]> result = new HashMap<String, ServiceInfo[]>(map.size());
for (String subtype : map.keySet()) {
List<ServiceInfo> infoForSubType = map.get(subtype);
result.put(subtype, infoForSubType.toArray(new ServiceInfo[infoForSubType.size()]));
}
return result;
}
use of javax.jmdns.ServiceInfo in project JAirPort by froks.
the class DNSStateTask method run.
@Override
public void run() {
DNSOutgoing out = this.createOugoing();
try {
if (!this.checkRunCondition()) {
this.cancel();
return;
}
List<DNSStatefulObject> stateObjects = new ArrayList<DNSStatefulObject>();
// send probes for JmDNS itself
synchronized (this.getDns()) {
if (this.getDns().isAssociatedWithTask(this, this.getTaskState())) {
logger1.finer(this.getName() + ".run() JmDNS " + this.getTaskDescription() + " " + this.getDns().getName());
stateObjects.add(this.getDns());
out = this.buildOutgoingForDNS(out);
}
}
// send probes for services
for (ServiceInfo serviceInfo : this.getDns().getServices().values()) {
ServiceInfoImpl info = (ServiceInfoImpl) serviceInfo;
synchronized (info) {
if (info.isAssociatedWithTask(this, this.getTaskState())) {
logger1.fine(this.getName() + ".run() JmDNS " + this.getTaskDescription() + " " + info.getQualifiedName());
stateObjects.add(info);
out = this.buildOutgoingForInfo(info, out);
}
}
}
if (!out.isEmpty()) {
logger1.finer(this.getName() + ".run() JmDNS " + this.getTaskDescription() + " #" + this.getTaskState());
this.getDns().send(out);
// Advance the state of objects.
this.advanceObjectsState(stateObjects);
} else {
// Advance the state of objects.
this.advanceObjectsState(stateObjects);
// If we have nothing to send, another timer taskState ahead of us has done the job for us. We can cancel.
cancel();
return;
}
} catch (Throwable e) {
logger1.log(Level.WARNING, this.getName() + ".run() exception ", e);
this.recoverTask(e);
}
this.advanceTask();
}
use of javax.jmdns.ServiceInfo in project JMRI by JMRI.
the class ZeroConfServiceTest method testServiceInfo.
/**
* Test of serviceInfo method, of class ZeroConfService.
*/
@Test
public void testServiceInfo() {
ZeroConfService instance = ZeroConfService.create(HTTP, 9999);
ServiceInfo result = instance.serviceInfo();
Assert.assertNotNull(result);
}
use of javax.jmdns.ServiceInfo in project coprhd-controller by CoprHD.
the class MulticastUtil method list.
/**
* List published node(s) configuration in the network via multicast
*
* @param serviceName name of service published. (e.g. release version for installation)
* @return node(s) configuration list
*/
public Map<String, Map<String, String>> list(String serviceName) {
Map<String, Map<String, String>> results = new HashMap<String, Map<String, String>>();
ServiceInfo[] infos = jmdns.list("_" + serviceName + "._tcp.local.");
for (ServiceInfo info : infos) {
_log.info("ServiceInfo:{}", info);
// Construct the key
final String[] hostAddrs = info.getHostAddresses();
final StringBuffer buf = new StringBuffer();
for (String hostAddr : hostAddrs) {
buf.append(hostAddr);
buf.append(';');
}
final String key = buf.toString();
_log.info("\tkey:{}", key);
// Construct the values
final Map<String, String> values = new HashMap<String, String>();
for (Enumeration<String> e = info.getPropertyNames(); e.hasMoreElements(); ) {
final String prop = e.nextElement();
final String value = new String(info.getPropertyBytes(prop));
_log.info("\tprop:{}, value:{}", prop, value);
values.put(prop, value);
}
// Put <key,values> into the results
if (values.isEmpty()) {
_log.warn("values are empty for key: {}", key);
}
results.put(key, values.isEmpty() ? null : values);
}
return results;
}
Aggregations