List of usage examples for java.lang AutoCloseable AutoCloseable
AutoCloseable
From source file:io.fluo.core.metrics.ReporterUtil.java
public static AutoCloseable setupReporters(final Environment env, final String domain) { ServiceLoader<ReporterStarter> serviceLoader = ServiceLoader.load(ReporterStarter.class); final List<AutoCloseable> allReporters = new ArrayList<>(); for (ReporterStarter rs : serviceLoader) { List<AutoCloseable> reporters = rs.start(new Params() { @Override/*from ww w. ja v a 2 s. c om*/ public Configuration getConfiguration() { return env.getConfiguration(); } @Override public MetricRegistry getMetricRegistry() { return env.getSharedResources().getMetricRegistry(); } @Override public String getDomain() { return domain; } }); allReporters.addAll(reporters); } if (allReporters.size() == 0) { JmxReporter jmxReporter = JmxReporter.forRegistry(env.getSharedResources().getMetricRegistry()) .inDomain(domain).build(); jmxReporter.start(); allReporters.add(jmxReporter); } return new AutoCloseable() { @Override public void close() { for (AutoCloseable closeable : allReporters) { try { closeable.close(); } catch (Exception e) { e.printStackTrace(); } } } }; }
From source file:com.gargoylesoftware.htmlunit.html.HtmlPageTest.java
/** * @exception Exception If the test fails *///from w w w . j ava 2 s. c o m @Test public void addAutoCloseable() throws Exception { final String html = ""; final HtmlPage page = loadPage(html); page.addAutoCloseable(new AutoCloseable() { @Override public void close() throws Exception { page.addAutoCloseable(new WebSocket()); } }); }
From source file:net.ravendb.client.connection.ServerClient.java
@Override public AutoCloseable forceReadFromMaster() { final int old = readStripingBase; readStripingBase = -1;//from ww w . java 2s.c om return new AutoCloseable() { @Override public void close() throws Exception { readStripingBase = old; } }; }