public ServiceInfoResolver(JmDNSImpl jmDNSImpl, ServiceInfoImpl info) { super(jmDNSImpl); this._info = info; info.setDns(this._jmDNSImpl); this._jmDNSImpl.addListener( info, DNSQuestion.newQuestion( info.getQualifiedName(), DNSRecordType.TYPE_ANY, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); }
ServiceInfoImpl( Map<Fields, String> qualifiedNameMap, int port, int weight, int priority, boolean persistent, byte text[]) { Map<Fields, String> map = ServiceInfoImpl.checkQualifiedNameMap(qualifiedNameMap); this._domain = map.get(Fields.Domain); this._protocol = map.get(Fields.Protocol); this._application = map.get(Fields.Application); this._name = map.get(Fields.Instance); this._subtype = map.get(Fields.Subtype); this._port = port; this._weight = weight; this._priority = priority; this._text = text; this.setNeedTextAnnouncing(false); this._state = new ServiceInfoState(this); this._persistent = persistent; this._ipv4Addresses = Collections.synchronizedSet(new LinkedHashSet<Inet4Address>()); this._ipv6Addresses = Collections.synchronizedSet(new LinkedHashSet<Inet6Address>()); }
public Prober(JmDNSImpl jmDNSImpl) { this.jmDNSImpl = jmDNSImpl; // Associate the host name to this, if it needs probing if (this.jmDNSImpl.getState() == DNSState.PROBING_1) { this.jmDNSImpl.setTask(this); } // Associate services to this, if they need probing synchronized (this.jmDNSImpl) { for (Iterator iterator = this.jmDNSImpl.getServices().values().iterator(); iterator.hasNext(); ) { ServiceInfoImpl info = (ServiceInfoImpl) iterator.next(); if (info.getState() == DNSState.PROBING_1) { info.setTask(this); } } } }
public boolean cancel() { // Remove association from host name to this if (this.jmDNSImpl.getTask() == this) { this.jmDNSImpl.setTask(null); } // Remove associations from services to this synchronized (this.jmDNSImpl) { for (Iterator i = this.jmDNSImpl.getServices().values().iterator(); i.hasNext(); ) { ServiceInfoImpl info = (ServiceInfoImpl) i.next(); if (info.getTask() == this) { info.setTask(null); } } } return super.cancel(); }
@Override protected void setTask(DNSTask task) { super.setTask(task); if ((this._task == null) && _info.needTextAnnouncing()) { this.lock(); try { if ((this._task == null) && _info.needTextAnnouncing()) { if (this._state.isAnnounced()) { this.setState(DNSState.ANNOUNCING_1); if (this.getDns() != null) { this.getDns().startAnnouncer(); } } _info.setNeedTextAnnouncing(false); } } finally { this.unlock(); } } }
public void run() { try { if (this.jmDNSImpl.getState() == DNSState.ANNOUNCED) { if (count++ < 3) { logger.finer("run() JmDNS querying service"); long now = System.currentTimeMillis(); DNSOutgoing out = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY); out.addQuestion(new DNSQuestion(type, DNSConstants.TYPE_PTR, DNSConstants.CLASS_IN)); for (Iterator s = this.jmDNSImpl.getServices().values().iterator(); s.hasNext(); ) { final ServiceInfoImpl info = (ServiceInfoImpl) s.next(); try { out.addAnswer( new DNSRecord.Pointer( info.getType(), DNSConstants.TYPE_PTR, DNSConstants.CLASS_IN, DNSConstants.DNS_TTL, info.getQualifiedName()), now); } catch (IOException ee) { break; } } this.jmDNSImpl.send(out); } else { // After three queries, we can quit. this.cancel(); } } else { if (this.jmDNSImpl.getState() == DNSState.CANCELED) { this.cancel(); } } } catch (Throwable e) { logger.log(Level.WARNING, "run() exception ", e); this.jmDNSImpl.recover(); } }
/** * @param type * @param name * @param subtype * @param port * @param weight * @param priority * @param persistent * @param text * @see javax.jmdns.ServiceInfo#create(String, String, int, int, int, byte[]) */ public ServiceInfoImpl( String type, String name, String subtype, int port, int weight, int priority, boolean persistent, byte text[]) { this( ServiceInfoImpl.decodeQualifiedNameMap(type, name, subtype), port, weight, priority, persistent, text); }
/** * @param type * @param name * @param subtype * @param port * @param weight * @param priority * @param persistent * @param props * @see javax.jmdns.ServiceInfo#create(String, String, int, int, int, Map) */ public ServiceInfoImpl( String type, String name, String subtype, int port, int weight, int priority, boolean persistent, Map<String, ?> props) { this( ServiceInfoImpl.decodeQualifiedNameMap(type, name, subtype), port, weight, priority, persistent, textFromProperties(props)); }
/** * @param type * @param name * @param subtype * @param port * @param weight * @param priority * @param persistent * @param text * @see javax.jmdns.ServiceInfo#create(String, String, int, int, int, String) */ public ServiceInfoImpl( String type, String name, String subtype, int port, int weight, int priority, boolean persistent, String text) { this( ServiceInfoImpl.decodeQualifiedNameMap(type, name, subtype), port, weight, priority, persistent, (byte[]) null); _server = text; byte[] encodedText = null; try { ByteArrayOutputStream out = new ByteArrayOutputStream(256); ByteArrayOutputStream out2 = new ByteArrayOutputStream(100); writeUTF(out2, text); byte data[] = out2.toByteArray(); if (data.length > 255) { throw new IOException( "Cannot have individual values larger that 255 chars. Offending value: " + text); } out.write((byte) data.length); out.write(data, 0, data.length); encodedText = out.toByteArray(); } catch (IOException e) { throw new RuntimeException("unexpected exception: " + e); } this._text = (encodedText != null && encodedText.length > 0 ? encodedText : DNSRecord.EMPTY_TXT); }
@Override public void run() { try { if (this._jmDNSImpl.getState() == DNSState.ANNOUNCED) { if (_count++ < 3 && !_info.hasData()) { long now = System.currentTimeMillis(); DNSOutgoing out = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY); out.addQuestion( DNSQuestion.newQuestion( _info.getQualifiedName(), DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); out.addQuestion( DNSQuestion.newQuestion( _info.getQualifiedName(), DNSRecordType.TYPE_TXT, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); if (_info.getServer() != null) { out.addQuestion( DNSQuestion.newQuestion( _info.getServer(), DNSRecordType.TYPE_A, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); out.addQuestion( DNSQuestion.newQuestion( _info.getServer(), DNSRecordType.TYPE_AAAA, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); } out.addAnswer( (DNSRecord) this._jmDNSImpl .getCache() .getDNSEntry( _info.getQualifiedName(), DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN), now); out.addAnswer( (DNSRecord) this._jmDNSImpl .getCache() .getDNSEntry( _info.getQualifiedName(), DNSRecordType.TYPE_TXT, DNSRecordClass.CLASS_IN), now); if (_info.getServer() != null) { out.addAnswer( (DNSRecord) this._jmDNSImpl .getCache() .getDNSEntry( _info.getServer(), DNSRecordType.TYPE_A, DNSRecordClass.CLASS_IN), now); out.addAnswer( (DNSRecord) this._jmDNSImpl .getCache() .getDNSEntry( _info.getServer(), DNSRecordType.TYPE_AAAA, DNSRecordClass.CLASS_IN), now); } this._jmDNSImpl.send(out); } else { // After three queries, we can quit. this.cancel(); this._jmDNSImpl.removeListener(_info); } } else { if (this._jmDNSImpl.getState() == DNSState.CANCELED) { this.cancel(); this._jmDNSImpl.removeListener(_info); } } } catch (Throwable e) { logger.log(Level.WARNING, "run() exception ", e); this._jmDNSImpl.recover(); } }
public void run() { synchronized (this.jmDNSImpl.getIoLock()) { DNSOutgoing out = null; try { // send probes for JmDNS itself if (this.jmDNSImpl.getState() == taskState && this.jmDNSImpl.getTask() == this) { if (out == null) { out = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY); } out.addQuestion( new DNSQuestion( this.jmDNSImpl.getLocalHost().getName(), DNSConstants.TYPE_ANY, DNSConstants.CLASS_IN)); this.jmDNSImpl.getLocalHost().addAddressRecords(out, true); this.jmDNSImpl.advanceState(); } // send probes for services // Defensively copy the services into a local list, // to prevent race conditions with methods registerService // and unregisterService. List list; synchronized (this.jmDNSImpl) { list = new LinkedList(this.jmDNSImpl.getServices().values()); } for (Iterator i = list.iterator(); i.hasNext(); ) { ServiceInfoImpl info = (ServiceInfoImpl) i.next(); synchronized (info) { if (info.getState() == taskState && info.getTask() == this) { info.advanceState(); if (out == null) { out = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY); out.addQuestion( new DNSQuestion( info.getQualifiedName(), DNSConstants.TYPE_ANY, DNSConstants.CLASS_IN)); } // 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 out.addAuthorativeAnswer( new DNSRecord.Service( info.getQualifiedName(), DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN, DNSConstants.DNS_TTL, info.getPriority(), info.getWeight(), info.getPort(), this.jmDNSImpl.getLocalHost().getName())); } } } if (out != null) { this.jmDNSImpl.send(out); } else { // 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) { this.jmDNSImpl.recover(); } taskState = taskState.advance(); if (!taskState.isProbing()) { cancel(); this.jmDNSImpl.startAnnouncer(); } } }