当前位置: 首页>>代码示例>>Java>>正文


Java DNSConstants类代码示例

本文整理汇总了Java中javax.jmdns.impl.constants.DNSConstants的典型用法代码示例。如果您正苦于以下问题:Java DNSConstants类的具体用法?Java DNSConstants怎么用?Java DNSConstants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DNSConstants类属于javax.jmdns.impl.constants包,在下文中一共展示了DNSConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
@Override
public void start(Timer timer) {
    long now = System.currentTimeMillis();
    if (now - this.getDns().getLastThrottleIncrement() < DNSConstants.PROBE_THROTTLE_COUNT_INTERVAL) {
        this.getDns().setThrottle(this.getDns().getThrottle() + 1);
    } else {
        this.getDns().setThrottle(1);
    }
    this.getDns().setLastThrottleIncrement(now);

    if (this.getDns().isAnnounced() && this.getDns().getThrottle() < DNSConstants.PROBE_THROTTLE_COUNT) {
        timer.schedule(this, JmDNSImpl.getRandom().nextInt(1 + DNSConstants.PROBE_WAIT_INTERVAL), DNSConstants.PROBE_WAIT_INTERVAL);
    } else if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) {
        timer.schedule(this, DNSConstants.PROBE_CONFLICT_INTERVAL, DNSConstants.PROBE_CONFLICT_INTERVAL);
    }
}
 
开发者ID:iilxy,项目名称:AndroidmDNS,代码行数:17,代码来源:Prober.java

示例2: unregisterService

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
/**
 * {@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 " + this.getName() + " unregistered service as " + info);
        }
    } else {
        logger.warning(this.getName() + " removing unregistered service info: " + infoAbstract.getKey());
    }
}
 
开发者ID:iilxy,项目名称:AndroidmDNS,代码行数:21,代码来源:JmDNSImpl.java

示例3: addAnswer

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
/**
 * Add an answer to a question. Deal with the case when the outgoing packet overflows
 *
 * @param in
 * @param addr
 * @param port
 * @param out
 * @param rec
 * @return outgoing answer
 * @exception IOException
 */
public DNSOutgoing addAnswer(DNSIncoming in, InetAddress addr, int port, DNSOutgoing out, DNSRecord rec) throws IOException {
    DNSOutgoing newOut = out;
    if (newOut == null) {
        newOut = new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA, false, in.getSenderUDPPayload());
    }
    try {
        newOut.addAnswer(in, rec);
    } catch (final IOException e) {
        newOut.setFlags(newOut.getFlags() | DNSConstants.FLAGS_TC);
        newOut.setId(in.getId());
        send(newOut);

        newOut = new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA, false, in.getSenderUDPPayload());
        newOut.addAnswer(in, rec);
    }
    return newOut;
}
 
开发者ID:iilxy,项目名称:AndroidmDNS,代码行数:29,代码来源:JmDNSImpl.java

示例4: send

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
/**
 * Send an outgoing multicast DNS message.
 *
 * @param out
 * @exception IOException
 */
public void send(DNSOutgoing out) throws IOException {
    if (!out.isEmpty()) {
        byte[] message = out.data();
        final DatagramPacket packet = new DatagramPacket(message, message.length, _group, DNSConstants.MDNS_PORT);

        if (logger.isLoggable(Level.FINEST)) {
            try {
                final DNSIncoming msg = new DNSIncoming(packet);
                if (logger.isLoggable(Level.FINEST)) {
                    logger.finest("send(" + this.getName() + ") JmDNS out:" + msg.print(true));
                }
            } catch (final IOException e) {
                logger.throwing(getClass().toString(), "send(" + this.getName() + ") - JmDNS can not parse what it sends!!!", e);
            }
        }
        final MulticastSocket ms = _socket;
        if (ms != null && !ms.isClosed()) {
            ms.send(packet);
        }
    }
}
 
开发者ID:iilxy,项目名称:AndroidmDNS,代码行数:28,代码来源:JmDNSImpl.java

示例5: addAnswers

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
@Override
public void addAnswers(JmDNSImpl jmDNSImpl, Set<DNSRecord> answers) {
    String loname = this.getName().toLowerCase();
    if (jmDNSImpl.getLocalHost().getName().equalsIgnoreCase(loname)) {
        // type = DNSConstants.TYPE_A;
        answers.addAll(jmDNSImpl.getLocalHost().answers(this.getRecordClass(), this.isUnique(), DNSConstants.DNS_TTL));
        return;
    }
    // Service type request
    if (jmDNSImpl.getServiceTypes().containsKey(loname)) {
        DNSQuestion question = new Pointer(this.getName(), DNSRecordType.TYPE_PTR, this.getRecordClass(), this.isUnique());
        question.addAnswers(jmDNSImpl, answers);
        return;
    }

    this.addAnswersForServiceInfo(jmDNSImpl, answers, (ServiceInfoImpl) jmDNSImpl.getServices().get(loname));
}
 
开发者ID:iilxy,项目名称:AndroidmDNS,代码行数:18,代码来源:DNSQuestion.java

示例6: addAnswers

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
@Override
public void addAnswers(JmDNSImpl jmDNSImpl, Set<DNSRecord> answers)
{
    String name = this.getName().toLowerCase();
    if (jmDNSImpl.getLocalHost().getName().equalsIgnoreCase(name))
    {
        // type = DNSConstants.TYPE_A;
        answers.addAll(jmDNSImpl.getLocalHost().answers(this.isUnique(), DNSConstants.DNS_TTL));
        return;
    }
    // Service type request
    if (jmDNSImpl.getServiceTypes().containsKey(name))
    {
        DNSQuestion question = new Pointer(this.getName(), DNSRecordType.TYPE_PTR, this.getRecordClass(), this.isUnique());
        question.addAnswers(jmDNSImpl, answers);
        return;
    }

    this.addAnswersForServiceInfo(jmDNSImpl, answers, (ServiceInfoImpl) jmDNSImpl.getServices().get(name));
}
 
开发者ID:blackshadowwalker,项目名称:log4j-collector,代码行数:21,代码来源:DNSQuestion.java

示例7: unregisterService

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
/**
 * {@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());
    }
}
 
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:21,代码来源:JmDNSImpl.java

示例8: addAnswers

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
@Override
public void addAnswers(JmDNSImpl jmDNSImpl, Set<DNSRecord> answers) {
    String loname = this.getName().toLowerCase();
    if (jmDNSImpl.getLocalHost().getName().equalsIgnoreCase(loname)) {
        // type = DNSConstants.TYPE_A;
        answers.addAll(jmDNSImpl.getLocalHost().answers(this.isUnique(), DNSConstants.DNS_TTL));
        return;
    }
    // Service type request
    if (jmDNSImpl.getServiceTypes().containsKey(loname)) {
        DNSQuestion question = new Pointer(this.getName(), DNSRecordType.TYPE_PTR, this.getRecordClass(), this.isUnique());
        question.addAnswers(jmDNSImpl, answers);
        return;
    }

    this.addAnswersForServiceInfo(jmDNSImpl, answers, (ServiceInfoImpl) jmDNSImpl.getServices().get(loname));
}
 
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:18,代码来源:DNSQuestion.java

示例9: start

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
@Override
public void start(Timer timer) {
    // According to draft-cheshire-dnsext-multicastdns.txt chapter "7 Responding":
    // We respond immediately if we know for sure, that we are the only one who can respond to the query.
    // In all other cases, we respond within 20-120 ms.
    //
    // According to draft-cheshire-dnsext-multicastdns.txt chapter "6.2 Multi-Packet Known Answer Suppression":
    // We respond after 20-120 ms if the query is truncated.

    boolean iAmTheOnlyOne = true;
    for (DNSQuestion question : _in.getQuestions()) {
        if (logger.isLoggable(Level.FINEST)) {
            logger.finest(this.getName() + "start() question=" + question);
        }
        iAmTheOnlyOne = question.iAmTheOnlyOne(this.getDns());
        if (!iAmTheOnlyOne) {
            break;
        }
    }
    int delay = (iAmTheOnlyOne && !_in.isTruncated()) ? 0 : DNSConstants.RESPONSE_MIN_WAIT_INTERVAL + JmDNSImpl.getRandom().nextInt(DNSConstants.RESPONSE_MAX_WAIT_INTERVAL - DNSConstants.RESPONSE_MIN_WAIT_INTERVAL + 1) - _in.elapseSinceArrival();
    if (delay < 0) {
        delay = 0;
    }
    if (logger.isLoggable(Level.FINEST)) {
        logger.finest(this.getName() + "start() Responder chosen delay=" + delay);
    }
    if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) {
        timer.schedule(this, delay);
    }
}
 
开发者ID:iilxy,项目名称:AndroidmDNS,代码行数:31,代码来源:Responder.java

示例10: addAnswers

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
@Override
protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException {
    DNSOutgoing newOut = out;
    long now = System.currentTimeMillis();
    for (ServiceInfo info : this.getDns().getServices().values()) {
        newOut = this.addAnswer(newOut, new DNSRecord.Pointer(info.getType(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getQualifiedName()), now);
        // newOut = this.addAnswer(newOut, new DNSRecord.Service(info.getQualifiedName(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getPriority(), info.getWeight(), info.getPort(),
        // this.getDns().getLocalHost().getName()), now);
    }
    return newOut;
}
 
开发者ID:iilxy,项目名称:AndroidmDNS,代码行数:12,代码来源:ServiceResolver.java

示例11: addAnswers

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
@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;
}
 
开发者ID:iilxy,项目名称:AndroidmDNS,代码行数:11,代码来源:TypeResolver.java

示例12: run

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:iilxy,项目名称:AndroidmDNS,代码行数:29,代码来源:DNSResolverTask.java

示例13: conflictWithRecord

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
public boolean conflictWithRecord(DNSRecord.Address record) {
    DNSRecord.Address hostAddress = this.getDNSAddressRecord(record.getRecordType(), record.isUnique(), DNSConstants.DNS_TTL);
    if (hostAddress != null) {
        return hostAddress.sameType(record) && hostAddress.sameName(record) && (!hostAddress.sameValue(record));
    }
    return false;
}
 
开发者ID:iilxy,项目名称:AndroidmDNS,代码行数:8,代码来源:HostInfo.java

示例14: registerService

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
/**
 * {@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.waitForAnnounced(DNSConstants.SERVICE_INFO_TIMEOUT);

    this.makeServiceNameUnique(info);
    while (_services.putIfAbsent(info.getKey(), info) != null) {
        this.makeServiceNameUnique(info);
    }

    this.startProber();
    info.waitForAnnounced(DNSConstants.SERVICE_INFO_TIMEOUT);

    if (logger.isLoggable(Level.FINE)) {
        logger.fine("registerService() JmDNS registered service as " + info);
    }
}
 
开发者ID:iilxy,项目名称:AndroidmDNS,代码行数:42,代码来源:JmDNSImpl.java

示例15: handleQuery

import javax.jmdns.impl.constants.DNSConstants; //导入依赖的package包/类
/**
 * Does the necessary actions, when this as a query.
 */
@Override
boolean handleQuery(JmDNSImpl dns, long expirationTime) {
    if (dns.getLocalHost().conflictWithRecord(this)) {
        DNSRecord.Address localAddress = dns.getLocalHost().getDNSAddressRecord(this.getRecordType(), this.isUnique(), DNSConstants.DNS_TTL);
        int comparison = this.compareTo(localAddress);

        if (comparison == 0) {
            // the 2 records are identical this probably means we are seeing our own record.
            // With multiple interfaces on a single computer it is possible to see our
            // own records come in on different interfaces than the ones they were sent on.
            // see section "10. Conflict Resolution" of mdns draft spec.
            logger1.finer("handleQuery() Ignoring an identical address query");
            return false;
        }

        logger1.finer("handleQuery() Conflicting query detected.");
        // Tie breaker test
        if (dns.isProbing() && comparison > 0) {
            // We lost the tie-break. We have to choose a different name.
            dns.getLocalHost().incrementHostName();
            dns.getCache().clear();
            for (ServiceInfo serviceInfo : dns.getServices().values()) {
                ServiceInfoImpl info = (ServiceInfoImpl) serviceInfo;
                info.revertState();
            }
        }
        dns.revertState();
        return true;
    }
    return false;
}
 
开发者ID:iilxy,项目名称:AndroidmDNS,代码行数:35,代码来源:DNSRecord.java


注:本文中的javax.jmdns.impl.constants.DNSConstants类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。