jdk/src/share/classes/sun/net/dns/ResolverConfiguration.java
author weijun
Mon, 19 Jul 2010 10:02:50 +0800
changeset 6112 b9d1b10c662c
parent 5506 202f599c92aa
permissions -rw-r--r--
6969683: Generify ResolverConfiguration codes Reviewed-by: alanb, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
6112
b9d1b10c662c 6969683: Generify ResolverConfiguration codes
weijun
parents: 5506
diff changeset
     2
 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.net.dns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * The configuration of the client resolver.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <p>A ResolverConfiguration is a singleton that represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * configuration of the client resolver. The ResolverConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * is opened by invoking the {@link #open() open} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public abstract class ResolverConfiguration {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static final Object lock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static ResolverConfiguration provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    protected ResolverConfiguration() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * Opens the resolver configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @return the resolver configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static ResolverConfiguration open() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            if (provider == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                provider = new sun.net.dns.ResolverConfigurationImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Returns a list corresponding to the domain search path. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * list is ordered by the search order used for host name lookup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Each element in the list returns a {@link java.lang.String}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * containing a domain name or suffix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @return list of domain names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
6112
b9d1b10c662c 6969683: Generify ResolverConfiguration codes
weijun
parents: 5506
diff changeset
    70
    public abstract List<String> searchlist();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Returns a list of name servers used for host name lookup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Each element in the list returns a {@link java.lang.String}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * containing the textual representation of the IP address of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * the name server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @return list of the name servers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
6112
b9d1b10c662c 6969683: Generify ResolverConfiguration codes
weijun
parents: 5506
diff changeset
    80
    public abstract List<String> nameservers();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Options representing certain resolver variables of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * a {@link ResolverConfiguration}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static abstract class Options {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         * Returns the maximum number of attempts the resolver
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         * will connect to each name server before giving up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         * and returning an error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         * @return the resolver attempts value or -1 is unknown
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        public int attempts() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         * Returns the basic retransmit timeout, in milliseconds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
         * used by the resolver. The resolver will typically use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
         * an exponential backoff algorithm where the timeout is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         * doubled for every retransmit attempt. The basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
         * retransmit timeout, returned here, is the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
         * timeout for the exponential backoff algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
         * @return the basic retransmit timeout value or -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
         *         if unknown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        public int retrans() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Returns the {@link #Options} for the resolver.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @return options for the resolver
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public abstract Options options();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}