use of javax.jmdns.impl.DNSRecord.Text in project EngineDriver by JMRI.
the class ServiceInfoImpl method answers.
/**
* Create a series of answer that correspond with the give service info.
*
* @param recordClass
* record class of the query
* @param unique
* @param ttl
* @param localHost
* @return collection of answers
*/
public Collection<DNSRecord> answers(DNSRecordClass recordClass, boolean unique, int ttl, HostInfo localHost) {
List<DNSRecord> list = new ArrayList<DNSRecord>();
// [PJYF Dec 6 2011] This is bad hack as I don't know what the spec should really means in this case. i.e. what is the class of our registered services.
if ((recordClass == DNSRecordClass.CLASS_ANY) || (recordClass == DNSRecordClass.CLASS_IN)) {
if (this.getSubtype().length() > 0) {
list.add(new Pointer(this.getTypeWithSubtype(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, ttl, this.getQualifiedName()));
}
list.add(new Pointer(this.getType(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, ttl, this.getQualifiedName()));
list.add(new Service(this.getQualifiedName(), DNSRecordClass.CLASS_IN, unique, ttl, _priority, _weight, _port, localHost.getName()));
list.add(new Text(this.getQualifiedName(), DNSRecordClass.CLASS_IN, unique, ttl, this.getTextBytes()));
}
return list;
}
use of javax.jmdns.impl.DNSRecord.Text in project ecf by eclipse.
the class ServiceInfoImpl method addAnswers.
public void addAnswers(DNSOutgoing out, int ttl, HostInfo localHost) throws IOException {
out.addAnswer(new Pointer(type, DNSConstants.TYPE_PTR, DNSConstants.CLASS_IN, ttl, getQualifiedName()), 0);
out.addAnswer(new Service(getQualifiedName(), DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN | DNSConstants.CLASS_UNIQUE, ttl, priority, weight, port, localHost.getName()), 0);
out.addAnswer(new Text(getQualifiedName(), DNSConstants.TYPE_TXT, DNSConstants.CLASS_IN | DNSConstants.CLASS_UNIQUE, ttl, getText()), 0);
}
use of javax.jmdns.impl.DNSRecord.Text in project EngineDriver by JMRI.
the class ServiceInfoImpl method updateRecord.
/**
* JmDNS callback to update a DNS record.
*
* @param dnsCache
* @param now
* @param rec
*/
@Override
public void updateRecord(DNSCache dnsCache, long now, DNSEntry rec) {
if ((rec instanceof DNSRecord) && !rec.isExpired(now)) {
boolean serviceUpdated = false;
switch(rec.getRecordType()) {
case // IPv4
TYPE_A:
if (rec.getName().equalsIgnoreCase(this.getServer())) {
_ipv4Addresses.add((Inet4Address) ((DNSRecord.Address) rec).getAddress());
serviceUpdated = true;
}
break;
case // IPv6
TYPE_AAAA:
if (rec.getName().equalsIgnoreCase(this.getServer())) {
_ipv6Addresses.add((Inet6Address) ((DNSRecord.Address) rec).getAddress());
serviceUpdated = true;
}
break;
case TYPE_SRV:
if (rec.getName().equalsIgnoreCase(this.getQualifiedName())) {
DNSRecord.Service srv = (DNSRecord.Service) rec;
boolean serverChanged = (_server == null) || !_server.equalsIgnoreCase(srv.getServer());
_server = srv.getServer();
_port = srv.getPort();
_weight = srv.getWeight();
_priority = srv.getPriority();
if (serverChanged) {
_ipv4Addresses.clear();
_ipv6Addresses.clear();
for (DNSEntry entry : dnsCache.getDNSEntryList(_server, DNSRecordType.TYPE_A, DNSRecordClass.CLASS_IN)) {
this.updateRecord(dnsCache, now, entry);
}
for (DNSEntry entry : dnsCache.getDNSEntryList(_server, DNSRecordType.TYPE_AAAA, DNSRecordClass.CLASS_IN)) {
this.updateRecord(dnsCache, now, entry);
}
// We do not want to trigger the listener in this case as it will be triggered if the address resolves.
} else {
serviceUpdated = true;
}
}
break;
case TYPE_TXT:
if (rec.getName().equalsIgnoreCase(this.getQualifiedName())) {
DNSRecord.Text txt = (DNSRecord.Text) rec;
_text = txt.getText();
// set it null for apply update text data
_props = null;
serviceUpdated = true;
}
break;
case TYPE_PTR:
if ((this.getSubtype().length() == 0) && (rec.getSubtype().length() != 0)) {
_subtype = rec.getSubtype();
serviceUpdated = true;
}
break;
default:
break;
}
if (serviceUpdated && this.hasData()) {
JmDNSImpl dns = this.getDns();
if (dns != null) {
// ServiceEvent event = ((DNSRecord) rec).getServiceEvent(dns);
// event = new ServiceEventImpl(dns, event.getType(), event.getName(), this);
// Failure to resolve services - ID: 3517826
ServiceEvent event = new ServiceEventImpl(dns, this.getType(), this.getName(), this);
dns.handleServiceResolved(event);
}
}
// This is done, to notify the wait loop in method JmDNS.waitForInfoData(ServiceInfo info, int timeout);
synchronized (this) {
this.notifyAll();
}
}
}
use of javax.jmdns.impl.DNSRecord.Text in project JAirPort by froks.
the class ServiceInfoImpl method answers.
public Collection<DNSRecord> answers(boolean unique, int ttl, HostInfo localHost) {
List<DNSRecord> list = new ArrayList<DNSRecord>();
if (this.getSubtype().length() > 0) {
list.add(new Pointer(this.getTypeWithSubtype(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, ttl, this.getQualifiedName()));
}
list.add(new Text(this.getQualifiedName(), DNSRecordClass.CLASS_IN, unique, ttl, textBytesToValidTextBytes(this.getTextBytes())));
list.add(new Pointer(this.getType(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, ttl, this.getQualifiedName()));
list.add(new Service(this.getQualifiedName(), DNSRecordClass.CLASS_IN, unique, ttl, _priority, _weight, _port, localHost.getName()));
// }
for (Inet4Address adr : this.getInet4Addresses()) {
list.add(new DNSRecord.IPv4Address(removeLastDot(this.getServer()), DNSRecordClass.CLASS_IN, false, ttl, adr));
}
list.add(new Pointer("_services._dns-sd._udp.local", DNSRecordClass.CLASS_IN, false, ttl, "_raop._tcp.local"));
return list;
}
Aggregations