@Override public ServiceInfoImpl clone() { ServiceInfoImpl serviceInfo = new ServiceInfoImpl(this.getQualifiedNameMap(), _port, _weight, _priority, _persistent, _text); Inet6Address[] ipv6Addresses = this.getInet6Addresses(); for (Inet6Address address : ipv6Addresses) { serviceInfo._ipv6Addresses.add(address); } Inet4Address[] ipv4Addresses = this.getInet4Addresses(); for (Inet4Address address : ipv4Addresses) { serviceInfo._ipv4Addresses.add(address); } return serviceInfo; }
@Override public ServiceInfo getServiceInfo(boolean persistent) { ServiceInfoImpl info = (ServiceInfoImpl) super.getServiceInfo(persistent); info.addAddress((Inet6Address) _addr); return info; }
public static Map<Fields, String> decodeQualifiedNameMap(String type, String name, String subtype) { Map<Fields, String> qualifiedNameMap = decodeQualifiedNameMapForType(type); qualifiedNameMap.put(Fields.Instance, name); qualifiedNameMap.put(Fields.Subtype, subtype); return checkQualifiedNameMap(qualifiedNameMap); }
/** * @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)); }
/** * {@inheritDoc} */ @Override public String getType() { String domain = this.getDomain(); String protocol = this.getProtocol(); String application = this.getApplication(); return (application.length() > 0 ? "_" + application + "." : "") + (protocol.length() > 0 ? "_" + protocol + "." : "") + domain + "."; }
/** * {@inheritDoc} */ @Override public void registerService(ServiceInfo infoAbstract) throws IOException { if (this.isClosing() || this.isClosed()) { throw new IllegalStateException("This DNS is closed."); } final ServiceInfoImpl info = (ServiceInfoImpl) infoAbstract; if (info.getDns() != null) { if (info.getDns() != this) { throw new IllegalStateException("A service information can only be registered with a single instamce of JmDNS."); } else if (_services.get(info.getKey()) != null) { throw new IllegalStateException("A service information can only be registered once."); } } info.setDns(this); this.registerServiceType(info.getTypeWithSubtype()); // bind the service to this address info.recoverState(); info.setServer(_localHost.getName()); info.addAddress(_localHost.getInet4Address()); info.addAddress(_localHost.getInet6Address()); this.makeServiceNameUnique(info); while (_services.putIfAbsent(info.getKey(), info) != null) { this.makeServiceNameUnique(info); } this.startProber(); logger.debug("registerService() JmDNS registered service as {}", info); }
/** * {@inheritDoc} */ @Override public String getQualifiedName() { String domain = this.getDomain(); String protocol = this.getProtocol(); String application = this.getApplication(); String instance = this.getName(); // String subtype = this.getSubtype(); // return (instance.length() > 0 ? instance + "." : "") + (application.length() > 0 ? "_" + application + "." : "") + (protocol.length() > 0 ? "_" + protocol + (subtype.length() > 0 ? ",_" + subtype.toLowerCase() + "." : ".") : "") + domain // + "."; return (instance.length() > 0 ? instance + "." : "") + (application.length() > 0 ? "_" + application + "." : "") + (protocol.length() > 0 ? "_" + protocol + "." : "") + domain + "."; }
ServiceInfoImpl info = new ServiceInfoImpl(type, name, subtype, 0, 0, 0, persistent, (byte[]) null); DNSEntry pointerEntry = this.getCache().getDNSEntry(new DNSRecord.Pointer(type, DNSRecordClass.CLASS_ANY, false, 0, info.getQualifiedName())); if (pointerEntry instanceof DNSRecord) { ServiceInfoImpl cachedInfo = (ServiceInfoImpl) ((DNSRecord) pointerEntry).getServiceInfo(persistent); Map<Fields, String> map = cachedInfo.getQualifiedNameMap(); byte[] srvBytes = null; String server = ""; DNSEntry serviceEntry = this.getCache().getDNSEntry(info.getQualifiedName(), DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_ANY); if (serviceEntry instanceof DNSRecord) { ServiceInfo cachedServiceEntryInfo = ((DNSRecord) serviceEntry).getServiceInfo(persistent); if (cachedServiceEntryInfo != null) { cachedInfo = new ServiceInfoImpl(map, cachedServiceEntryInfo.getPort(), cachedServiceEntryInfo.getWeight(), cachedServiceEntryInfo.getPriority(), persistent, (byte[]) null); srvBytes = cachedServiceEntryInfo.getTextBytes(); server = cachedServiceEntryInfo.getServer(); if (cachedAddressInfo != null) { for (Inet4Address address : cachedAddressInfo.getInet4Addresses()) { cachedInfo.addAddress(address); cachedInfo._setText(cachedAddressInfo.getTextBytes()); if (cachedAddressInfo != null) { for (Inet6Address address : cachedAddressInfo.getInet6Addresses()) { cachedInfo.addAddress(address); cachedInfo._setText(cachedAddressInfo.getTextBytes()); DNSEntry textEntry = this.getCache().getDNSEntry(cachedInfo.getQualifiedName(), DNSRecordType.TYPE_TXT, DNSRecordClass.CLASS_ANY);
protected void addAnswersForServiceInfo(JmDNSImpl jmDNSImpl, Set<DNSRecord> answers, ServiceInfoImpl info) { if ((info != null) && info.isAnnounced()) { if (this.getName().equalsIgnoreCase(info.getQualifiedName()) || this.getName().equalsIgnoreCase(info.getType())) { answers.addAll(jmDNSImpl.getLocalHost().answers(DNSRecordClass.UNIQUE, DNSConstants.DNS_TTL)); answers.addAll(info.answers(DNSRecordClass.UNIQUE, DNSConstants.DNS_TTL, jmDNSImpl.getLocalHost())); } if (logger.isLoggable(Level.FINER)) { logger.finer(jmDNSImpl.getName() + " DNSQuestion(" + this.getName() + ").addAnswersForServiceInfo(): info: " + info + "\n" + answers); } } }
/** * {@inheritDoc} */ @Override public void unregisterService(ServiceInfo infoAbstract) { final ServiceInfoImpl info = (ServiceInfoImpl) _services.get(infoAbstract.getKey()); if (info != null) { info.cancelState(); this.startCanceler(); info.waitForCanceled(DNSConstants.CLOSE_TIMEOUT); _services.remove(info.getKey(), info); if (logger.isLoggable(Level.FINE)) { logger.fine("unregisterService() JmDNS unregistered service as " + info); } } else { logger.warning("Removing unregistered service info: " + infoAbstract.getKey()); } }
@Override public ServiceInfo getServiceInfo(boolean persistent) { if (this.isServicesDiscoveryMetaQuery()) { // The service name is in the alias Map<Fields, String> map = ServiceInfoImpl.decodeQualifiedNameMapForType(this.getAlias()); return new ServiceInfoImpl(map, 0, 0, 0, persistent, (byte[]) null); } else if (this.isReverseLookup()) { return new ServiceInfoImpl(this.getQualifiedNameMap(), 0, 0, 0, persistent, (byte[]) null); } else if (this.isDomainDiscoveryQuery()) { // FIXME [PJYF Nov 16 2010] We do not currently support domain discovery return new ServiceInfoImpl(this.getQualifiedNameMap(), 0, 0, 0, persistent, (byte[]) null); } Map<Fields, String> map = ServiceInfoImpl.decodeQualifiedNameMapForType(this.getAlias()); map.put(Fields.Subtype, this.getQualifiedNameMap().get(Fields.Subtype)); return new ServiceInfoImpl(map, 0, 0, 0, persistent, this.getAlias()); }
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>()); }
/** * {@inheritDoc} */ @Override public void unregisterAllServices() { logger.debug("unregisterAllServices()"); for (final ServiceInfo info : _services.values()) { if (info != null) { final ServiceInfoImpl infoImpl = (ServiceInfoImpl) info; logger.debug("Cancelling service info: {}", info); infoImpl.cancelState(); } } this.startCanceler(); for (final Map.Entry<String, ServiceInfo> entry : _services.entrySet()) { final ServiceInfo info = entry.getValue(); if (info != null) { final ServiceInfoImpl infoImpl = (ServiceInfoImpl) info; final String name = entry.getKey(); logger.debug("Wait for service info cancel: {}", info); infoImpl.waitForCanceled(DNSConstants.CLOSE_TIMEOUT); _services.remove(name, info); } } }
@Override public ServiceInfo getServiceInfo(boolean persistent) { ServiceInfoImpl info = new ServiceInfoImpl(this.getQualifiedNameMap(), 0, 0, 0, persistent, (byte[]) null); // info.setAddress(_addr); This is done in the sub class so we don't have to test for class type return info; }
@Override protected DNSOutgoing buildOutgoingForInfo(ServiceInfoImpl info, DNSOutgoing out) throws IOException { DNSOutgoing newOut = out; for (DNSRecord answer : info.answers(DNSRecordClass.UNIQUE, this.getTTL(), this.getDns().getLocalHost())) { newOut = this.addAnswer(newOut, null, answer); } return newOut; }
/** * @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; try { ByteArrayOutputStream out = new ByteArrayOutputStream(text.length()); writeUTF(out, text); this._text = out.toByteArray(); } catch (IOException e) { throw new RuntimeException("unexpected exception: " + e); } }
/** * @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); }
/** * 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(); }
/** * Associate the DNS host and the service infos with this task if not already associated and in the same state. * * @param state * target state */ protected void associate(DNSState state) { synchronized (this.getDns()) { this.getDns().associateWithTask(this, state); } for (ServiceInfo serviceInfo : this.getDns().getServices().values()) { ((ServiceInfoImpl) serviceInfo).associateWithTask(this, state); } }
if (info.getDns() != null) { if (info.getDns() != this) { throw new IllegalStateException("A service information can only be registered with a single instamce of JmDNS."); } else if (_services.get(info.getKey()) != null) { throw new IllegalStateException("A service information can only be registered once."); info.setDns(this); this.registerServiceType(info.getTypeWithSubtype()); info.recoverState(); info.setServer(_localHost.getName()); info.addAddress(_localHost.getInet4Address()); info.addAddress(_localHost.getInet6Address()); while (_services.putIfAbsent(info.getKey(), info) != null) { this.makeServiceNameUnique(info); info.waitForAnnounced(DNSConstants.SERVICE_INFO_TIMEOUT);