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


Java NameService类代码示例

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


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

示例1: install

import sun.net.spi.nameservice.NameService; //导入依赖的package包/类
/**
 * Install the fake DNS resolver into the Java runtime.
 * 
 * <p>
 * In Java, name services are chained. So if one name service doesn't 
 * respond (or responds with {@code UnknownHostException}) then the next
 * name service in the chain will be queried. If you want to do negative
 * tests, i.e. "this should give me UnknownHostException", then you'll have
 * to remove other name services too, so that only the FakeDns name service
 * is installed. You do this by setting {@code removeOthers} to {@code true}.
 * 
 * @param removeOthers if other name services should be removed
 */
public synchronized void install(boolean removeOthers) {
    if (installed) {
        return;
    }
    List<NameService> nameServices = getKnownNameServices();
    if (nameServices != null) {

        if (removeOthers) {
            orgNameServices.clear();
            orgNameServices.addAll(nameServices);
            nameServices.clear();
        }
        // Install ourselves in position 0, ahead of everyone else
        nameServices.add(0, new NameServiceInMemory());

        installed = true;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:FakeDns.java

示例2: unInstall

import sun.net.spi.nameservice.NameService; //导入依赖的package包/类
/**
 * Puts Java's internal name service chain back to its original state.
 * Clears any forward or reverse mappings that has been put into the
 * FakeDns.
 */
public synchronized void unInstall() {
    if (!installed) {
        return;
    }
    List<NameService> nameServices = getKnownNameServices();
    if (nameServices != null) {

        NameService ns = nameServices.get(0);
        if (ns != null) {
            if (ns instanceof NameServiceInMemory) {
                nameServices.remove(0);
                installed = false;
            }
        }
        
        if (!orgNameServices.isEmpty()) {
            nameServices.addAll(orgNameServices);
            orgNameServices.clear();
        }
    }
    forwardResolutions.clear();
    reverseResolutions.clear();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:FakeDns.java

示例3: spyOnNameService

import sun.net.spi.nameservice.NameService; //导入依赖的package包/类
/**
 * Spy on the Java DNS infrastructure.
 * This likely only works on Sun-derived JDKs, but uses JUnit's
 * Assume functionality so that any tests using it are skipped on
 * incompatible JDKs.
 */
private NameService spyOnNameService() {
  try {
    Field f = InetAddress.class.getDeclaredField("nameServices");
    f.setAccessible(true);
    Assume.assumeNotNull(f);
    @SuppressWarnings("unchecked")
    List<NameService> nsList = (List<NameService>) f.get(null);

    NameService ns = nsList.get(0);
    Log log = LogFactory.getLog("NameServiceSpy");
    
    ns = Mockito.mock(NameService.class,
        new GenericTestUtils.DelegateAnswer(log, ns));
    nsList.set(0, ns);
    return ns;
  } catch (Throwable t) {
    LOG.info("Unable to spy on DNS. Skipping test.", t);
    // In case the JDK we're testing on doesn't work like Sun's, just
    // skip the test.
    Assume.assumeNoException(t);
    throw new RuntimeException(t);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:30,代码来源:TestDFSClientFailover.java

示例4: testFileContextDoesntDnsResolveLogicalURI

import sun.net.spi.nameservice.NameService; //导入依赖的package包/类
/**
 * Same test as above, but for FileContext.
 */
@Test
public void testFileContextDoesntDnsResolveLogicalURI() throws Exception {
  FileSystem fs = HATestUtil.configureFailoverFs(cluster, conf);
  NameService spyNS = spyOnNameService();
  String logicalHost = fs.getUri().getHost();
  Configuration haClientConf = fs.getConf();
  
  FileContext fc = FileContext.getFileContext(haClientConf);
  Path root = new Path("/");
  fc.listStatus(root);
  fc.listStatus(fc.makeQualified(root));
  fc.getDefaultFileSystem().getCanonicalServiceName();

  // Ensure that the logical hostname was never resolved.
  Mockito.verify(spyNS, Mockito.never()).lookupAllHostAddr(Mockito.eq(logicalHost));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:TestDFSClientFailover.java

示例5: createNameService

import sun.net.spi.nameservice.NameService; //导入依赖的package包/类
@Override
public NameService createNameService() throws Exception {
    NameService ns = new NameService() {
        @Override
        public InetAddress[] lookupAllHostAddr(String host)
                throws UnknownHostException {
            // Everything is localhost except NOT_EXISTING_HOST
            if (NOT_EXISTING_HOST.equals(host)) {
                throw new UnknownHostException("Unknown host name: "
                        + NOT_EXISTING_HOST);
            }
            return new InetAddress[]{
                InetAddress.getByAddress(host, new byte[]{127,0,0,1})
            };
        }
        @Override
        public String getHostByAddr(byte[] addr)
                throws UnknownHostException {
            // No reverse lookup, PrincipalName use original string
            throw new UnknownHostException();
        }
    };
    return ns;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:KDC.java

示例6: testDoesntDnsResolveLogicalURI

import sun.net.spi.nameservice.NameService; //导入依赖的package包/类
/**
 * Test that the client doesn't ever try to DNS-resolve the logical URI.
 * Regression test for HADOOP-9150.
 */
@Test
public void testDoesntDnsResolveLogicalURI() throws Exception {
  NameService spyNS = spyOnNameService();
  
  FileSystem fs = HATestUtil.configureFailoverFs(cluster, conf);
  String logicalHost = fs.getUri().getHost();
  Path qualifiedRoot = fs.makeQualified(new Path("/"));
  
  // Make a few calls against the filesystem.
  fs.getCanonicalServiceName();
  fs.listStatus(qualifiedRoot);
  
  // Ensure that the logical hostname was never resolved.
  Mockito.verify(spyNS, Mockito.never()).lookupAllHostAddr(Mockito.eq(logicalHost));
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:20,代码来源:TestDFSClientFailover.java

示例7: testFileContextDoesntDnsResolveLogicalURI

import sun.net.spi.nameservice.NameService; //导入依赖的package包/类
/**
 * Same test as above, but for FileContext.
 */
@Test
public void testFileContextDoesntDnsResolveLogicalURI() throws Exception {
  NameService spyNS = spyOnNameService();
  FileSystem fs = HATestUtil.configureFailoverFs(cluster, conf);
  String logicalHost = fs.getUri().getHost();
  Configuration haClientConf = fs.getConf();
  
  FileContext fc = FileContext.getFileContext(haClientConf);
  Path root = new Path("/");
  fc.listStatus(root);
  fc.listStatus(fc.makeQualified(root));
  fc.getDefaultFileSystem().getCanonicalServiceName();

  // Ensure that the logical hostname was never resolved.
  Mockito.verify(spyNS, Mockito.never()).lookupAllHostAddr(Mockito.eq(logicalHost));
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:20,代码来源:TestDFSClientFailover.java

示例8: createNameService

import sun.net.spi.nameservice.NameService; //导入依赖的package包/类
@Override
public NameService createNameService() throws Exception {
    NameService ns = new NameService() {
        @Override
        public InetAddress[] lookupAllHostAddr(String host)
                throws UnknownHostException {
            // Everything is localhost
            return new InetAddress[]{
                InetAddress.getByAddress(host, new byte[]{127,0,0,1})
            };
        }
        @Override
        public String getHostByAddr(byte[] addr)
                throws UnknownHostException {
            // No reverse lookup, PrincipalName use original string
            throw new UnknownHostException();
        }
    };
    return ns;
}
 
开发者ID:infobip,项目名称:infobip-open-jdk-8,代码行数:21,代码来源:KDC.java

示例9: getKnownNameServices

import sun.net.spi.nameservice.NameService; //导入依赖的package包/类
private List<NameService> getKnownNameServices() {
    try {
        Field field = InetAddress.class.getDeclaredField("nameServices");
        field.setAccessible(true);
        return (List<NameService>) field.get(null);
    } catch (IllegalAccessException | IllegalArgumentException | NoSuchFieldException | SecurityException e) {
        //throw Throwables.propagate(e);
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:FakeDns.java

示例10: testDoesntDnsResolveLogicalURI

import sun.net.spi.nameservice.NameService; //导入依赖的package包/类
/**
 * Test that the client doesn't ever try to DNS-resolve the logical URI.
 * Regression test for HADOOP-9150.
 */
@Test
public void testDoesntDnsResolveLogicalURI() throws Exception {
  FileSystem fs = HATestUtil.configureFailoverFs(cluster, conf);
  NameService spyNS = spyOnNameService();
  String logicalHost = fs.getUri().getHost();
  Path qualifiedRoot = fs.makeQualified(new Path("/"));
  
  // Make a few calls against the filesystem.
  fs.getCanonicalServiceName();
  fs.listStatus(qualifiedRoot);
  
  // Ensure that the logical hostname was never resolved.
  Mockito.verify(spyNS, Mockito.never()).lookupAllHostAddr(Mockito.eq(logicalHost));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:TestDFSClientFailover.java

示例11: createNameService

import sun.net.spi.nameservice.NameService; //导入依赖的package包/类
@Override
public NameService
createNameService()

	throws Exception
{
	if ( proxy_name_service == null ){

		throw( new Exception( "Failed to create proxy name service" ));
	}

	return( proxy_name_service );
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:14,代码来源:AENameServiceDescriptor.java

示例12: createNameService

import sun.net.spi.nameservice.NameService; //导入依赖的package包/类
/**
 * Intended for use by java.net.InetAddress static initializer.
 * 
 * @return a reference to the name service provider that was already created
 *         as class load time
 */
@Override
public NameService createNameService()
{
	LOG.debug("NetlibNameServiceDescriptor.createNameService() called");
	return nameService;
}
 
开发者ID:B4dT0bi,项目名称:silvertunnel-ng,代码行数:13,代码来源:NetlibNameServiceDescriptor.java


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