List of usage examples for java.io Closeable Closeable
Closeable
From source file:org.apache.jackrabbit.oak.plugins.tika.TextExtractorMain.java
private static Closeable asCloseable(final DocumentNodeStore dns) { return new Closeable() { @Override//from w w w .j ava 2s . c o m public void close() throws IOException { dns.dispose(); } }; }
From source file:org.apache.jackrabbit.oak.plugins.tika.TextExtractorMain.java
private static Closeable asCloseable(final MongoConnection con) { return new Closeable() { @Override/*from w ww . ja v a 2 s.c o m*/ public void close() throws IOException { con.close(); } }; }
From source file:org.apache.bval.jsr.ConfigurationImpl.java
public Closeable getClosable() { return new Closeable() { public void close() throws IOException { for (final BValExtension.Releasable<?> releasable : releasables) { releasable.release();/*from www . jav a 2 s . co m*/ } releasables.clear(); } }; }
From source file:org.apache.gobblin.scheduler.JobScheduler.java
/** * Start the job configuration file monitor using generic file system API. * * <p>/*from w w w . j a v a 2s.c o m*/ * The job configuration file monitor currently only supports monitoring the following types of changes: * * <ul> * <li>New job configuration files.</li> * <li>Changes to existing job configuration files.</li> * <li>Changes to existing common properties file with a .properties extension.</li> * <li>Deletion to existing job configuration files.</li> * <li>Deletion to existing common properties file with a .properties extension.</li> * </ul> * </p> * * <p> * This monitor has one limitation: in case more than one file including at least one common properties * file are changed between two adjacent checks, the reloading of affected job configuration files may * be intermixed and applied in an order that is not desirable. This is because the order the listener * is called on the changes is not controlled by Gobblin, but instead by the monitor itself. * </p> */ private void startGeneralJobConfigFileMonitor() throws Exception { SchedulerUtils.addPathAlterationObserver(this.pathAlterationDetector, this.listener, jobConfigFileDirPath); this.pathAlterationDetector.start(); this.closer.register(new Closeable() { @Override public void close() throws IOException { try { pathAlterationDetector.stop(1000); } catch (InterruptedException e) { throw new IOException(e); } } }); }
From source file:mil.nga.giat.geowave.datastore.accumulo.AccumuloDataStore.java
protected <T> CloseableIterator<T> getBatchDeleters(final DataStoreCallbackManager callbackCache, final MemoryAdapterStore tempAdapterStore, final List<Pair<PrimaryIndex, List<DataAdapter<Object>>>> indexAdapterPairs, final QueryOptions sanitizedQueryOptions, final Query sanitizedQuery, final DupTracker dupTracker) { final boolean DELETE = true; // for readability final List<CloseableIterator<Object>> results = new ArrayList<CloseableIterator<Object>>(); for (final Pair<PrimaryIndex, List<DataAdapter<Object>>> indexAdapterPair : indexAdapterPairs) { final List<ByteArrayId> adapterIdsToQuery = new ArrayList<>(); for (final DataAdapter<Object> adapter : indexAdapterPair.getRight()) { // Add scan callback for bookkeeping final ScanCallback<Object> callback = new ScanCallback<Object>() { @Override/*from w w w . j av a 2 s .c om*/ public void entryScanned(final DataStoreEntryInfo entryInfo, final Object entry) { updateDupCounts(dupTracker, adapter.getAdapterId(), entryInfo); callbackCache.getDeleteCallback((WritableDataAdapter<Object>) adapter, indexAdapterPair.getLeft()).entryDeleted(entryInfo, entry); } }; sanitizedQueryOptions.setScanCallback(callback); if (sanitizedQuery instanceof RowIdQuery) { sanitizedQueryOptions.setLimit(-1); results.add(queryRowIds(adapter, indexAdapterPair.getLeft(), ((RowIdQuery) sanitizedQuery).getRowIds(), null, sanitizedQueryOptions, tempAdapterStore, DELETE)); continue; } else if (sanitizedQuery instanceof PrefixIdQuery) { final PrefixIdQuery prefixIdQuery = (PrefixIdQuery) sanitizedQuery; results.add(queryRowPrefix(indexAdapterPair.getLeft(), prefixIdQuery.getRowPrefix(), sanitizedQueryOptions, tempAdapterStore, adapterIdsToQuery, DELETE)); continue; } adapterIdsToQuery.add(adapter.getAdapterId()); } // supports querying multiple adapters in a single index // in one query instance (one scanner) for efficiency if (adapterIdsToQuery.size() > 0) { results.add(queryConstraints(adapterIdsToQuery, indexAdapterPair.getLeft(), sanitizedQuery, null, sanitizedQueryOptions, tempAdapterStore, DELETE)); } } return new CloseableIteratorWrapper<T>(new Closeable() { @Override public void close() throws IOException { for (final CloseableIterator<Object> result : results) { result.close(); } } }, Iterators.concat(new CastIterator<T>(results.iterator()))); }