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


Java CloseableUtils類代碼示例

本文整理匯總了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);
  }
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:26,代碼來源:ZkDiscoveryService.java

示例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);
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:23,代碼來源:ServiceCacheImplProxy.java

示例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);
  });
}
 
開發者ID:edgar615,項目名稱:direwolves,代碼行數:24,代碼來源:ZookeeperServiceImporter.java

示例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;

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

示例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);
    }
}
 
開發者ID:benson-git,項目名稱:ibole-microservice,代碼行數:24,代碼來源:DiscoveryExample.java

示例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);
    }
}
 
開發者ID:thingsboard,項目名稱:thingsboard,代碼行數:25,代碼來源:ZkDiscoveryService.java

示例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);
	}
}
 
開發者ID:easycodebox,項目名稱:easycode,代碼行數:21,代碼來源:ZooKeeperTest.java

示例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);
	}
}
 
開發者ID:Spedge,項目名稱:hangar,代碼行數:23,代碼來源:TestZookeeperIndex.java

示例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);
    }
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:21,代碼來源:IndexMetaData.java

示例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();
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:23,代碼來源:Exhibitor.java

示例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());
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:21,代碼來源:NoneConfigProvider.java

示例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);
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:21,代碼來源:NoneConfigProvider.java

示例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());
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:27,代碼來源:S3ConfigProvider.java

示例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);
        }
    }
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:23,代碼來源:FileBasedPreferences.java

示例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);
    }
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:24,代碼來源:FileBasedPreferences.java


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