@Override public boolean equals(Object obj) { boolean result = false; if (obj instanceof DNSEntry) { DNSEntry other = (DNSEntry) obj; result = this.getKey().equals(other.getKey()) && this.getRecordType().equals(other.getRecordType()) && this.getRecordClass() == other.getRecordClass(); } return result; }
/** * @param dout * @exception IOException */ protected void toByteArray(DataOutputStream dout) throws IOException { dout.write(this.getName().getBytes("UTF8")); dout.writeShort(this.getRecordType().indexValue()); dout.writeShort(this.getRecordClass().indexValue()); }
/** * Returns the subtype of this entry * * @return subtype of this entry */ public String getSubtype() { String subtype = this.getQualifiedNameMap().get(Fields.Subtype); return (subtype != null ? subtype : ""); }
public boolean isReverseLookup() { return this.isV4ReverseLookup() || this.isV6ReverseLookup(); }
/** * Check if two entries have exactly the same name, type, and class. * * @param entry * @return <code>true</code> if the two entries have are for the same record, <code>false</code> otherwise */ public boolean isSameEntry(DNSEntry entry) { return this.getKey().equals(entry.getKey()) && this.matchRecordType(entry.getRecordType()) && this.matchRecordClass(entry.getRecordClass()); }
if ((rec instanceof DNSRecord) && !rec.isExpired(now)) { boolean serviceUpdated = false; switch (rec.getRecordType()) { case TYPE_A: // IPv4 if (rec.getName().equalsIgnoreCase(this.getServer())) { _ipv4Addresses.add((Inet4Address) ((DNSRecord.Address) rec).getAddress()); serviceUpdated = true; if (rec.getName().equalsIgnoreCase(this.getServer())) { _ipv6Addresses.add((Inet6Address) ((DNSRecord.Address) rec).getAddress()); serviceUpdated = true; if (rec.getName().equalsIgnoreCase(this.getQualifiedName())) { DNSRecord.Service srv = (DNSRecord.Service) rec; boolean serverChanged = (_server == null) || !_server.equalsIgnoreCase(srv.getServer()); if (rec.getName().equalsIgnoreCase(this.getQualifiedName())) { DNSRecord.Text txt = (DNSRecord.Text) rec; _text = txt.getText(); if ((this.getSubtype().length() == 0) && (rec.getSubtype().length() != 0)) { _subtype = rec.getSubtype(); serviceUpdated = true;
/** * Get all matching DNS entries from the table. * * @param name * @param type * @param recordClass * @return list of entries */ public synchronized Collection<? extends DNSEntry> getDNSEntryList(String name, DNSRecordType type, DNSRecordClass recordClass) { Collection<? extends DNSEntry> entryList = this._getDNSEntryList(name); if (entryList != null) { entryList = new ArrayList<DNSEntry>(entryList); for (Iterator<? extends DNSEntry> i = entryList.iterator(); i.hasNext();) { DNSEntry testDNSEntry = i.next(); if (!testDNSEntry.getRecordType().equals(type) || ((DNSRecordClass.CLASS_ANY != recordClass) && !testDNSEntry.getRecordClass().equals(recordClass))) { i.remove(); } } } else { entryList = Collections.emptyList(); } return entryList; }
@Override public String toString() { StringBuilder aLog = new StringBuilder(200); aLog.append("[" + this.getClass().getSimpleName() + "@" + System.identityHashCode(this)); aLog.append(" type: " + this.getRecordType()); aLog.append(", class: " + this.getRecordClass()); aLog.append((_unique ? "-unique," : ",")); aLog.append(" name: " + _name); this.toString(aLog); aLog.append("]"); return aLog.toString(); }
/** * Get a matching DNS entry from the table (using isSameEntry). Returns the entry that was found. * * @param dnsEntry * @return DNSEntry */ public synchronized DNSEntry getDNSEntry(DNSEntry dnsEntry) { DNSEntry result = null; if (dnsEntry != null) { Collection<? extends DNSEntry> entryList = this.getDNSEntryList(dnsEntry.getKey()); if (entryList != null) { for (DNSEntry testDNSEntry : entryList) { if (testDNSEntry.isSameEntry(dnsEntry)) { result = testDNSEntry; break; } } } } return result; }
if (DNSRecordType.TYPE_SRV.equals(dnsEntry.getRecordType()) && !dnsEntry.isExpired(now)) { final DNSRecord.Service s = (DNSRecord.Service) dnsEntry; if (s.getPort() != info.getPort() || !s.getServer().equals(_localHost.getName())) {
/** * Replace an existing entry by a new one.<br/> * <b>Note:</b> the 2 entries must have the same key. * * @param newDNSEntry * @param existingDNSEntry * @return <code>true</code> if the entry has been replace, <code>false</code> otherwise. */ public boolean replaceDNSEntry(DNSEntry newDNSEntry, DNSEntry existingDNSEntry) { boolean result = false; if ((newDNSEntry != null) && (existingDNSEntry != null) && (newDNSEntry.getKey().equals(existingDNSEntry.getKey()))) { List<DNSEntry> entryList = this.get(newDNSEntry.getKey()); if (entryList == null) { this.putIfAbsent(newDNSEntry.getKey(), new ArrayList<DNSEntry>()); entryList = this.get(newDNSEntry.getKey()); } synchronized (entryList) { entryList.remove(existingDNSEntry); entryList.add(newDNSEntry); } // This is probably not very informative result = true; } return result; }
/** * Create an entry. */ DNSEntry(String name, DNSRecordType type, DNSRecordClass recordClass, boolean unique) { _name = name; // _key = (name != null ? name.trim().toLowerCase() : null); _recordType = type; _dnsClass = recordClass; _unique = unique; _qualifiedNameMap = ServiceInfoImpl.decodeQualifiedNameMapForType(this.getName()); String domain = _qualifiedNameMap.get(Fields.Domain); String protocol = _qualifiedNameMap.get(Fields.Protocol); String application = _qualifiedNameMap.get(Fields.Application); String instance = _qualifiedNameMap.get(Fields.Instance).toLowerCase(); _type = (application.length() > 0 ? "_" + application + "." : "") + (protocol.length() > 0 ? "_" + protocol + "." : "") + domain + "."; _key = ((instance.length() > 0 ? instance + "." : "") + _type).toLowerCase(); }
/** * Check that 2 entries are of the same type. * * @param entry * @return <code>true</code> is the two type are the same, <code>false</code> otherwise. */ public boolean isSameType(DNSEntry entry) { return (entry != null) && (entry.getRecordType() == this.getRecordType()); }
/** * Check that 2 entries are of the same class. * * @param entry * @return <code>true</code> is the two class are the same, <code>false</code> otherwise. */ public boolean isSameRecordClass(DNSEntry entry) { return (entry != null) && (entry.getRecordClass() == this.getRecordClass()); }
/** * Check if two entries have the same subtype. * * @param other * @return <code>true</code> if the two entries have are for the same subtype, <code>false</code> otherwise */ public boolean sameSubtype(DNSEntry other) { return this.getSubtype().equals(other.getSubtype()); }
@Override public boolean equals(Object other) { return (other instanceof DNSRecord) && super.equals(other) && sameValue((DNSRecord) other); }
/** * Add a listener for a question. The listener will receive updates of answers to the question as they arrive, or from the cache if they are already available. * * @param listener * DSN listener * @param question * DNS query */ public void addListener(DNSListener listener, DNSQuestion question) { final long now = System.currentTimeMillis(); // add the new listener _listeners.add(listener); // report existing matched records if (question != null) { for (DNSEntry dnsEntry : this.getCache().getDNSEntryList(question.getName().toLowerCase())) { if (question.answeredBy(dnsEntry) && !dnsEntry.isExpired(now)) { listener.updateRecord(this.getCache(), now, dnsEntry); } } } }
if ((rec instanceof DNSRecord) && !rec.isExpired(now)) { boolean serviceUpdated = false; switch (rec.getRecordType()) { case TYPE_A: // IPv4 if (rec.getName().equalsIgnoreCase(this.getServer())) { _ipv4Addresses.add((Inet4Address) ((DNSRecord.Address) rec).getAddress()); serviceUpdated = true; if (rec.getName().equalsIgnoreCase(this.getServer())) { _ipv6Addresses.add((Inet6Address) ((DNSRecord.Address) rec).getAddress()); serviceUpdated = true; if (rec.getName().equalsIgnoreCase(this.getQualifiedName())) { DNSRecord.Service srv = (DNSRecord.Service) rec; boolean serverChanged = (_server == null) || !_server.equalsIgnoreCase(srv.getServer()); if (rec.getName().equalsIgnoreCase(this.getQualifiedName())) { DNSRecord.Text txt = (DNSRecord.Text) rec; _text = txt.getText(); if ((this.getSubtype().length() == 0) && (rec.getSubtype().length() != 0)) { _subtype = rec.getSubtype(); serviceUpdated = true;
/** * Get all matching DNS entries from the table. * * @param name * @param type * @param recordClass * @return list of entries */ public synchronized Collection<? extends DNSEntry> getDNSEntryList(String name, DNSRecordType type, DNSRecordClass recordClass) { Collection<? extends DNSEntry> entryList = this._getDNSEntryList(name); if (entryList != null) { entryList = new ArrayList<DNSEntry>(entryList); for (Iterator<? extends DNSEntry> i = entryList.iterator(); i.hasNext();) { DNSEntry testDNSEntry = i.next(); if (!testDNSEntry.getRecordType().equals(type) || ((DNSRecordClass.CLASS_ANY != recordClass) && !testDNSEntry.getRecordClass().equals(recordClass))) { i.remove(); } } } else { entryList = Collections.emptyList(); } return entryList; }
@Override public String toString() { StringBuilder aLog = new StringBuilder(200); aLog.append("[" + this.getClass().getSimpleName() + "@" + System.identityHashCode(this)); aLog.append(" type: " + this.getRecordType()); aLog.append(", class: " + this.getRecordClass()); aLog.append((_unique ? "-unique," : ",")); aLog.append(" name: " + _name); this.toString(aLog); aLog.append("]"); return aLog.toString(); }