當前位置: 首頁>>代碼示例>>Java>>正文


Java CloseableUtils.closeQuietly方法代碼示例

本文整理匯總了Java中org.apache.curator.utils.CloseableUtils.closeQuietly方法的典型用法代碼示例。如果您正苦於以下問題:Java CloseableUtils.closeQuietly方法的具體用法?Java CloseableUtils.closeQuietly怎麽用?Java CloseableUtils.closeQuietly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.curator.utils.CloseableUtils的用法示例。


在下文中一共展示了CloseableUtils.closeQuietly方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: close

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
@Override
public void close() throws IOException {
    Preconditions.checkState(state.compareAndSet(State.STARTED, State.STOPPED), "Already closed or has not been started");

    listenerContainer.forEach
            (
                    new Function<ServiceCacheListener, Void>()
                    {
                        @Override
                        public Void apply(ServiceCacheListener listener)
                        {
                            discovery.getClient().getConnectionStateListenable().removeListener(listener);
                            return null;
                        }
                    }
            );
    listenerContainer.clear();

    CloseableUtils.closeQuietly(cache);

    discovery.cacheClosed(this);
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:23,代碼來源:ServiceCacheImplProxy.java

示例2: testAddArtifact

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
@Test
public void testAddArtifact() throws Exception
{
	TestingServer testingServer = new TestingServer();
	index.startClient(testingServer.getConnectString());
	
	try
	{
		// Add an artifact.
		index.addArtifact(IndexUtils.TEST1.getKey(), IndexUtils.TEST1.getArtifact());
		
		// Is there an artifact?
		Assert.assertTrue(index.isArtifact(IndexUtils.TEST1.getKey()));
		
		// Get the artifact.
		assertEquals(IndexUtils.TEST1.getArtifact(), index.getArtifact(IndexUtils.TEST1.getKey()));
	}
	finally
	{
		CloseableUtils.closeQuietly(testingServer);
	}
}
 
開發者ID:Spedge,項目名稱:hangar,代碼行數:23,代碼來源:TestZookeeperIndex.java

示例3: contextDestroyed

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
@Override
public void contextDestroyed(ServletContextEvent event)
{
    if ( exhibitor != null )
    {
        CloseableUtils.closeQuietly(exhibitor);
        exhibitor = null;
    }

    if ( exhibitorCreator != null )
    {
        for ( Closeable closeable : exhibitorCreator.getCloseables() )
        {
            CloseableUtils.closeQuietly(closeable);
        }
    }
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:18,代碼來源:ExhibitorServletContextListener.java

示例4: testMissingServer

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
@Test
public void     testMissingServer() throws URISyntaxException
{
    RemoteInstanceRequestClientImpl         client = new RemoteInstanceRequestClientImpl(new RemoteConnectionConfiguration());
    try
    {
        // a non-existent port should generate an exception
        client.getWebResource(new URI("http://localhost:" + InstanceSpec.getRandomPort()), MediaType.WILDCARD_TYPE, Object.class);
    }
    catch ( Exception e )
    {
        Throwable cause = e.getCause();
        if ( cause == null )
        {
            cause = e;
        }
        Assert.assertTrue(cause instanceof ConnectException, cause.getClass().getName());
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:24,代碼來源:TestRemoteInstanceRequestClient.java

示例5: init

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
@PostConstruct
public void init() {
    log.info("Initializing...");
    Assert.hasLength(zkUrl, MiscUtils.missingProperty("zk.url"));
    Assert.notNull(zkRetryInterval, MiscUtils.missingProperty("zk.retry_interval_ms"));
    Assert.notNull(zkConnectionTimeout, MiscUtils.missingProperty("zk.connection_timeout_ms"));
    Assert.notNull(zkSessionTimeout, MiscUtils.missingProperty("zk.session_timeout_ms"));

    log.info("Initializing discovery service using ZK connect string: {}", zkUrl);

    zkNodesDir = zkDir + "/nodes";
    try {
        client = CuratorFrameworkFactory.newClient(zkUrl, zkSessionTimeout, zkConnectionTimeout, new RetryForever(zkRetryInterval));
        client.start();
        client.blockUntilConnected();
        cache = new PathChildrenCache(client, zkNodesDir, true);
        cache.getListenable().addListener(this);
        cache.start();
    } catch (Exception e) {
        log.error("Failed to connect to ZK: {}", e.getMessage(), e);
        CloseableUtils.closeQuietly(client);
        throw new RuntimeException(e);
    }
}
 
開發者ID:thingsboard,項目名稱:thingsboard,代碼行數:25,代碼來源:ZkDiscoveryService.java

示例6: listInstances

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
private static void listInstances(ServiceDiscovery<InstanceDetails> serviceDiscovery) throws Exception
{
    // This shows how to query all the instances in service discovery

    try
    {
        Collection<String>  serviceNames = serviceDiscovery.queryForNames();
        System.out.println(serviceNames.size() + " type(s)");
        for ( String serviceName : serviceNames )
        {
            Collection<ServiceInstance<InstanceDetails>> instances = serviceDiscovery.queryForInstances(serviceName);
            System.out.println(serviceName);
            for ( ServiceInstance<InstanceDetails> instance : instances )
            {
                outputInstance(instance);
            }
        }
    }
    finally
    {
        CloseableUtils.closeQuietly(serviceDiscovery);
    }
}
 
開發者ID:benson-git,項目名稱:ibole-microservice,代碼行數:24,代碼來源:DiscoveryExample.java

示例7: closeStuff

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
@AfterMethod
public void closeStuff() throws Exception {

    CloseableUtils.closeQuietly(zkClient);
    LOG.info("ZK Client state {}", zkClient.getState());
    zkClient = null;

    CloseableUtils.closeQuietly(storageInternalZKClient);
    LOG.info("ZK Internal Client state {}", storageInternalZKClient.getState());
    storageInternalZKClient = null;

    CloseableUtils.closeQuietly(zkServer);
    LOG.info("ZK Server Stopped");
    zkServer = null;

}
 
開發者ID:apache,項目名稱:incubator-omid,代碼行數:17,代碼來源:TestZKTimestampStorage.java

示例8: main

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    TestingServer server = new TestingServer(1234);

    try {
        prepare(server);
        Thread.sleep(1000);

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring-context.xml");
        DataSource dataSource = applicationContext.getBean(DataSource.class);
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        List<Map<String, Object>> result = jdbcTemplate.queryForList("SELECT DATABASE();");
        System.out.println(result);
    } finally {
        CloseableUtils.closeQuietly(server);
    }
}
 
開發者ID:hekailiang,項目名稱:cloud-config,代碼行數:17,代碼來源:CloudConfigSample.java

示例9: run

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
@Override
public void run(T configuration, Environment environment) throws Exception
{
    CuratorConfiguration curatorConfiguration = ComposedConfigurationAccessor.access(configuration, environment, CuratorConfiguration.class);
    // TODO more config
    final CuratorFramework curator = CuratorFrameworkFactory.newClient(curatorConfiguration.getConnectionString(), new RetryOneTime(1));

    Managed managed = new Managed()
    {
        @Override
        public void start() throws Exception
        {
            curator.start();
        }

        @Override
        public void stop() throws Exception
        {
            CloseableUtils.closeQuietly(curator);
        }
    };
    environment.lifecycle().manage(managed);

    SoaBundle.getFeatures(environment).putNamed(curator, CuratorFramework.class, curatorConfiguration.getCuratorName());
}
 
開發者ID:soabase,項目名稱:soabase,代碼行數:26,代碼來源:CuratorBundle.java

示例10: save

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
/**
 * Save file.
 *
 * @return the file
 */
public File save() {
    ConfigRenderOptions renderOptions = ConfigRenderOptions.defaults()
        .setComments(true)
        .setFormatted(true)
        .setOriginComments(false)
        .setJson(false);
    bumpVersion();
    String configData = configImpl.root().render(renderOptions);
    FileWriter writer = null;
    try {
        writer = new FileWriter(tmpFile.toFile());
        writer.write(configData);
    } catch (IOException e) {
        logger.warn("failed to write file, message={}", e.getMessage());
    } finally {
        CloseableUtils.closeQuietly(writer);
    }
    return tmpFile.toFile();
}
 
開發者ID:yahoo,項目名稱:gondola,代碼行數:25,代碼來源:ConfigWriter.java

示例11: close

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
@Override
public void close() throws IOException
{
    log.debug("Closing");

    CloseableUtils.closeQuietly(ensembleProvider);
    try
    {
        zooKeeper.closeAndClear();
    }
    catch ( Exception e )
    {
        ThreadUtils.checkInterrupted(e);
        throw new IOException(e);
    }
    finally
    {
        isConnected.set(false);
    }
}
 
開發者ID:apache,項目名稱:curator,代碼行數:21,代碼來源:ConnectionState.java

示例12: testBasic

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
@Test
public void testBasic() throws Exception
{
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try
    {
        client.start();

        EnsureContainers ensureContainers = new EnsureContainers(client, "/one/two/three");
        ensureContainers.ensure();

        Assert.assertNotNull(client.checkExists().forPath("/one/two/three"));
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
開發者ID:apache,項目名稱:curator,代碼行數:19,代碼來源:TestEnsureContainers.java

示例13: internalUnregisterService

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
private void internalUnregisterService(final Entry<T> entry) throws Exception
{
    if ( entry != null )
    {
        synchronized(entry)
        {
            if ( entry.cache != null )
            {
                CloseableUtils.closeQuietly(entry.cache);
                entry.cache = null;
            }

            String path = pathForInstance(entry.service.getName(), entry.service.getId());
            try
            {
                client.delete().guaranteed().forPath(path);
            }
            catch ( KeeperException.NoNodeException ignore )
            {
                // ignore
            }
        }
    }
}
 
開發者ID:apache,項目名稱:curator,代碼行數:25,代碼來源:ServiceDiscoveryImpl.java

示例14: testSimultaneous

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
@Test
public void     testSimultaneous() throws Exception
{
    CuratorFramework    client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try
    {
        client.start();

        CuratorFramework fooClient = client.usingNamespace("foo");
        CuratorFramework barClient = client.usingNamespace("bar");

        fooClient.create().forPath("/one");
        barClient.create().forPath("/one");

        Assert.assertNotNull(client.getZookeeperClient().getZooKeeper().exists("/foo/one", false));
        Assert.assertNotNull(client.getZookeeperClient().getZooKeeper().exists("/bar/one", false));
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
開發者ID:apache,項目名稱:curator,代碼行數:23,代碼來源:TestNamespaceFacade.java

示例15: testSetData

import org.apache.curator.utils.CloseableUtils; //導入方法依賴的package包/類
@Test
public void testSetData() throws Exception
{
    final byte[]            data = "here's a string".getBytes();

    CuratorFramework        client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try
    {
        client.start();

        client.create().creatingParentsIfNeeded().forPath("/a/b/c", data);
        Assert.assertEquals(data, client.getData().forPath("/a/b/c"));

        client.setData().compressed().forPath("/a/b/c", data);
        Assert.assertEquals(data.length, client.getData().decompressed().forPath("/a/b/c").length);
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
開發者ID:apache,項目名稱:curator,代碼行數:22,代碼來源:TestCompression.java


注:本文中的org.apache.curator.utils.CloseableUtils.closeQuietly方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。