$search
00001 // Copyright 2003-2005 Arthur van Hoff, Rick Blair 00002 // Licensed under Apache License version 2.0 00003 // Original license LGPL 00004 00005 package javax.jmdns.impl.tasks.resolver; 00006 00007 import java.io.IOException; 00008 00009 import javax.jmdns.ServiceInfo; 00010 import javax.jmdns.impl.DNSOutgoing; 00011 import javax.jmdns.impl.DNSQuestion; 00012 import javax.jmdns.impl.DNSRecord; 00013 import javax.jmdns.impl.JmDNSImpl; 00014 import javax.jmdns.impl.constants.DNSConstants; 00015 import javax.jmdns.impl.constants.DNSRecordClass; 00016 import javax.jmdns.impl.constants.DNSRecordType; 00017 00023 public class ServiceResolver extends DNSResolverTask { 00024 00025 private final String _type; 00026 00027 public ServiceResolver(JmDNSImpl jmDNSImpl, String type) { 00028 super(jmDNSImpl); 00029 this._type = type; 00030 } 00031 00032 /* 00033 * (non-Javadoc) 00034 * @see javax.jmdns.impl.tasks.DNSTask#getName() 00035 */ 00036 @Override 00037 public String getName() { 00038 return "ServiceResolver(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; 00039 } 00040 00041 /* 00042 * (non-Javadoc) 00043 * @see javax.jmdns.impl.tasks.Resolver#addAnswers(javax.jmdns.impl.DNSOutgoing) 00044 */ 00045 @Override 00046 protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException { 00047 DNSOutgoing newOut = out; 00048 long now = System.currentTimeMillis(); 00049 for (ServiceInfo info : this.getDns().getServices().values()) { 00050 newOut = this.addAnswer(newOut, new DNSRecord.Pointer(info.getType(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getQualifiedName()), now); 00051 // newOut = this.addAnswer(newOut, new DNSRecord.Service(info.getQualifiedName(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getPriority(), info.getWeight(), info.getPort(), 00052 // this.getDns().getLocalHost().getName()), now); 00053 } 00054 return newOut; 00055 } 00056 00057 /* 00058 * (non-Javadoc) 00059 * @see javax.jmdns.impl.tasks.Resolver#addQuestions(javax.jmdns.impl.DNSOutgoing) 00060 */ 00061 @Override 00062 protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException { 00063 DNSOutgoing newOut = out; 00064 newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_type, DNSRecordType.TYPE_PTR, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 00065 //newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_type, DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); 00066 return newOut; 00067 } 00068 00069 /* 00070 * (non-Javadoc) 00071 * @see javax.jmdns.impl.tasks.Resolver#description() 00072 */ 00073 @Override 00074 protected String description() { 00075 return "querying service"; 00076 } 00077 }