本文整理匯總了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);
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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());
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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
}
}
}
}
示例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);
}
}
示例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);
}
}