use of javax.jmdns.impl.DNSOutgoing in project JAirPort by froks.
the class Prober method buildOutgoingForInfo.
/*
* (non-Javadoc)
* @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForInfo(javax.jmdns.impl.ServiceInfoImpl, javax.jmdns.impl.DNSOutgoing)
*/
@Override
protected DNSOutgoing buildOutgoingForInfo(ServiceInfoImpl info, DNSOutgoing out) throws IOException {
DNSOutgoing newOut = out;
newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(info.getQualifiedName(), DNSRecordType.TYPE_ANY, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
// the "unique" flag should be not set here because these answers haven't been proven unique yet this means the record will not exactly match the announcement record
newOut = this.addAuthoritativeAnswer(newOut, new DNSRecord.Service(info.getQualifiedName(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, this.getTTL(), info.getPriority(), info.getWeight(), info.getPort(), this.getDns().getLocalHost().getName()));
if (info.getTextBytes().length > 0) {
newOut = this.addAuthoritativeAnswer(newOut, new DNSRecord.Text(info.getQualifiedName(), DNSRecordClass.CLASS_IN, false, defaultTTL(), ServiceInfoImpl.textBytesToValidTextBytes(info.getTextBytes())));
}
return newOut;
}
use of javax.jmdns.impl.DNSOutgoing in project JAirPort by froks.
the class DNSResolverTask method run.
/*
* (non-Javadoc)
* @see java.util.TimerTask#run()
*/
@Override
public void run() {
try {
if (this.getDns().isCanceling() || this.getDns().isCanceled()) {
this.cancel();
} else {
if (_count++ < 3) {
if (logger.isLoggable(Level.FINER)) {
logger.finer(this.getName() + ".run() JmDNS " + this.description());
}
DNSOutgoing out = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY);
out = this.addQuestions(out);
if (this.getDns().isAnnounced()) {
out = this.addAnswers(out);
}
if (!out.isEmpty()) {
this.getDns().send(out);
}
} else {
// After three queries, we can quit.
this.cancel();
}
}
} catch (Throwable e) {
logger.log(Level.WARNING, this.getName() + ".run() exception ", e);
this.getDns().recover();
}
}
use of javax.jmdns.impl.DNSOutgoing in project JAirPort by froks.
the class ServiceResolver method addQuestions.
/*
* (non-Javadoc)
* @see javax.jmdns.impl.tasks.Resolver#addQuestions(javax.jmdns.impl.DNSOutgoing)
*/
@Override
protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException {
DNSOutgoing newOut = out;
newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_type, DNSRecordType.TYPE_PTR, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
// newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_type, DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
return newOut;
}
use of javax.jmdns.impl.DNSOutgoing in project JAirPort by froks.
the class TypeResolver method addAnswers.
/*
* (non-Javadoc)
* @see javax.jmdns.impl.tasks.Resolver#addAnswers(javax.jmdns.impl.DNSOutgoing)
*/
@Override
protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException {
DNSOutgoing newOut = out;
long now = System.currentTimeMillis();
for (String type : this.getDns().getServiceTypes().keySet()) {
ServiceTypeEntry typeEntry = this.getDns().getServiceTypes().get(type);
newOut = this.addAnswer(newOut, new DNSRecord.Pointer("_services._dns-sd._udp.local.", DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, typeEntry.getType()), now);
}
return newOut;
}
use of javax.jmdns.impl.DNSOutgoing 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();
}
Aggregations