本文整理匯總了Java中org.apache.curator.utils.CloseableUtils類的典型用法代碼示例。如果您正苦於以下問題:Java CloseableUtils類的具體用法?Java CloseableUtils怎麽用?Java CloseableUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CloseableUtils類屬於org.apache.curator.utils包,在下文中一共展示了CloseableUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
}
示例2: 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);
}
示例3: close
import org.apache.curator.utils.CloseableUtils; //導入依賴的package包/類
@Override
public void close(Handler<Void> closeHandler) {
Future<Void> done = Future.future();
//刪除所有服務實例
unregisterAllServices(done);
done.setHandler(v -> {
try {
if (cache != null) {
CloseableUtils.closeQuietly(cache);
}
if (serviceDiscovery != null) {
CloseableUtils.closeQuietly(serviceDiscovery);
}
if (client != null) {
CloseableUtils.closeQuietly(client);
}
} catch (Exception e) {
// Ignore them
}
closeHandler.handle(null);
});
}
示例4: 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;
}
示例5: 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);
}
}
示例6: 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);
}
}
示例7: main
import org.apache.curator.utils.CloseableUtils; //導入依賴的package包/類
public static void main(String[] args) {
String connectString = "192.168.1.101:2181,192.168.1.102:2181,192.168.1.103:2181/conf/easycode/auth";
CuratorFramework client = null;
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
try {
client = CuratorFrameworkFactory.newClient(connectString, retryPolicy);
client.start();
ZooKeeperTest test = new ZooKeeperTest(client);
test.addCfgFile2LatentIoNode("", Envs.DEV, new String[] {
"zk-test.properties"
});
} catch (Exception e) {
e.printStackTrace();
} finally {
CloseableUtils.closeQuietly(client);
}
}
示例8: 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);
}
}
示例9: write
import org.apache.curator.utils.CloseableUtils; //導入依賴的package包/類
public static void write(IndexMetaData meta, File to) throws Exception
{
DateFormat format = DateFormat.getDateTimeInstance();
Properties properties = new Properties();
properties.setProperty(PROPERTY_FROM, format.format(meta.from));
properties.setProperty(PROPERTY_TO, format.format(meta.to));
properties.setProperty(PROPERTY_VERSION, Integer.toString(VERSION));
properties.setProperty(PROPERTY_COUNT, Integer.toString(meta.entryCount));
OutputStream out = new BufferedOutputStream(new FileOutputStream(to));
try
{
properties.store(out, "Auto-generated by Exhibitor");
}
finally
{
CloseableUtils.closeQuietly(out);
}
}
示例10: close
import org.apache.curator.utils.CloseableUtils; //導入依賴的package包/類
@Override
public void close() throws IOException
{
Preconditions.checkState(state.compareAndSet(State.STARTED, State.STOPPED));
if ( (arguments.servoRegistration != null) && (servoCompositeMonitor != null) )
{
arguments.servoRegistration.getMonitorRegistry().unregister(servoCompositeMonitor);
}
CloseableUtils.closeQuietly(servoMonitoring);
CloseableUtils.closeQuietly(autoInstanceManagement);
CloseableUtils.closeQuietly(processMonitor);
CloseableUtils.closeQuietly(indexCache);
CloseableUtils.closeQuietly(backupManager);
CloseableUtils.closeQuietly(cleanupManager);
CloseableUtils.closeQuietly(monitorRunningInstance);
CloseableUtils.closeQuietly(configManager);
CloseableUtils.closeQuietly(activityQueue);
CloseableUtils.closeQuietly(remoteInstanceRequestClient);
closeLocalConnection();
}
示例11: loadConfig
import org.apache.curator.utils.CloseableUtils; //導入依賴的package包/類
@Override
public LoadedInstanceConfig loadConfig() throws Exception
{
File propertiesFile = new File(directory, FILE_NAME);
Properties properties = new Properties();
if ( propertiesFile.exists() )
{
BufferedInputStream in = new BufferedInputStream(new FileInputStream(propertiesFile));
try
{
properties.load(in);
}
finally
{
CloseableUtils.closeQuietly(in);
}
}
PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, defaultProperties);
return new LoadedInstanceConfig(config, propertiesFile.lastModified());
}
示例12: storeConfig
import org.apache.curator.utils.CloseableUtils; //導入依賴的package包/類
@Override
public LoadedInstanceConfig storeConfig(ConfigCollection config, long compareVersion) throws Exception
{
File propertiesFile = new File(directory, FILE_NAME);
PropertyBasedInstanceConfig propertyBasedInstanceConfig = new PropertyBasedInstanceConfig(config);
long lastModified = 0;
OutputStream out = new BufferedOutputStream(new FileOutputStream(propertiesFile));
try
{
propertyBasedInstanceConfig.getProperties().store(out, "Auto-generated by Exhibitor");
lastModified = propertiesFile.lastModified();
}
finally
{
CloseableUtils.closeQuietly(out);
}
return new LoadedInstanceConfig(propertyBasedInstanceConfig, lastModified);
}
示例13: loadConfig
import org.apache.curator.utils.CloseableUtils; //導入依賴的package包/類
@Override
public LoadedInstanceConfig loadConfig() throws Exception
{
Date lastModified;
Properties properties = new Properties();
S3Object object = getConfigObject();
if ( object != null )
{
try
{
lastModified = object.getObjectMetadata().getLastModified();
properties.load(object.getObjectContent());
}
finally
{
CloseableUtils.closeQuietly(object.getObjectContent());
}
}
else
{
lastModified = new Date(0L);
}
PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, defaults);
return new LoadedInstanceConfig(config, lastModified.getTime());
}
示例14: FileBasedPreferences
import org.apache.curator.utils.CloseableUtils; //導入依賴的package包/類
/**
* @param file file to use as backing store
* @throws IOException errors
*/
public FileBasedPreferences(File file) throws IOException
{
super(null, "");
this.file = file;
if ( file.exists() )
{
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
try
{
properties.load(in);
}
finally
{
CloseableUtils.closeQuietly(in);
}
}
}
示例15: flushSpi
import org.apache.curator.utils.CloseableUtils; //導入依賴的package包/類
@Override
protected void flushSpi() throws BackingStoreException
{
if ( !file.getParentFile().exists() && !file.getParentFile().mkdirs() )
{
throw new BackingStoreException("Could not create parent directories for: " + file);
}
OutputStream out = null;
try
{
out = new BufferedOutputStream(new FileOutputStream(file));
properties.store(out, "# Auto-generated by " + FileBasedPreferences.class.getName());
}
catch ( IOException e )
{
throw new BackingStoreException(e);
}
finally
{
CloseableUtils.closeQuietly(out);
}
}