use of java.io.Closeable in project bazel by bazelbuild.
the class AndroidResourceMerger method mergeData.
/** Merges all secondary resources with the primary resources. */
static MergedAndroidData mergeData(final ParsedAndroidData primary, final Path primaryManifest, final List<? extends SerializedAndroidData> direct, final List<? extends SerializedAndroidData> transitive, final Path resourcesOut, final Path assetsOut, @Nullable final PngCruncher cruncher, final VariantType type, @Nullable final Path symbolsOut, @Nullable AndroidResourceClassWriter rclassWriter) throws MergingException {
Stopwatch timer = Stopwatch.createStarted();
final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(15));
try (Closeable closeable = ExecutorServiceCloser.createWith(executorService)) {
AndroidDataMerger merger = AndroidDataMerger.createWithPathDeduplictor(executorService);
UnwrittenMergedAndroidData merged = merger.loadAndMerge(transitive, direct, primary, primaryManifest, type != VariantType.LIBRARY);
logger.fine(String.format("merge finished in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
timer.reset().start();
if (symbolsOut != null) {
AndroidDataSerializer serializer = AndroidDataSerializer.create();
merged.serializeTo(serializer);
serializer.flushTo(symbolsOut);
logger.fine(String.format("serialize merge finished in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
timer.reset().start();
}
if (rclassWriter != null) {
merged.writeResourceClass(rclassWriter);
logger.fine(String.format("write classes finished in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
timer.reset().start();
}
AndroidDataWriter writer = AndroidDataWriter.createWith(resourcesOut.getParent(), resourcesOut, assetsOut, cruncher, executorService);
return merged.write(writer);
} catch (IOException e) {
throw MergingException.wrapException(e).build();
} finally {
logger.fine(String.format("write merge finished in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
}
}
use of java.io.Closeable in project hazelcast by hazelcast.
the class AbstractCacheService method registerListenerInternal.
protected String registerListenerInternal(String name, CacheEventListener listener, EventFilter eventFilter, boolean isLocal) {
EventService eventService = getNodeEngine().getEventService();
EventRegistration reg;
if (isLocal) {
if (eventFilter == null) {
reg = eventService.registerLocalListener(AbstractCacheService.SERVICE_NAME, name, listener);
} else {
reg = eventService.registerLocalListener(AbstractCacheService.SERVICE_NAME, name, eventFilter, listener);
}
} else {
if (eventFilter == null) {
reg = eventService.registerListener(AbstractCacheService.SERVICE_NAME, name, listener);
} else {
reg = eventService.registerListener(AbstractCacheService.SERVICE_NAME, name, eventFilter, listener);
}
}
String id = reg.getId();
if (listener instanceof Closeable) {
closeableListeners.put(id, (Closeable) listener);
} else if (listener instanceof CacheEntryListenerProvider) {
CacheEntryListener cacheEntryListener = ((CacheEntryListenerProvider) listener).getCacheEntryListener();
if (cacheEntryListener instanceof Closeable) {
closeableListeners.put(id, (Closeable) cacheEntryListener);
}
}
return id;
}
use of java.io.Closeable in project hazelcast by hazelcast.
the class AbstractCacheService method deleteCacheResources.
private void deleteCacheResources(String name) {
Set<Closeable> cacheResources;
ContextMutexFactory.Mutex mutex = cacheResourcesMutexFactory.mutexFor(name);
try {
synchronized (mutex) {
cacheResources = resources.remove(name);
}
} finally {
mutex.close();
}
if (cacheResources != null) {
for (Closeable resource : cacheResources) {
IOUtil.closeResource(resource);
}
cacheResources.clear();
}
}
use of java.io.Closeable in project h2o-3 by h2oai.
the class MojoReaderBackendFactoryTest method testCreateReaderBackend_URL_Memory.
@Test
public void testCreateReaderBackend_URL_Memory() throws Exception {
URL dumjo = MojoReaderBackendFactoryTest.class.getResource("dumjo.zip");
assertNotNull(dumjo);
MojoReaderBackend r = MojoReaderBackendFactory.createReaderBackend(dumjo, CachingStrategy.MEMORY);
assertTrue(r instanceof InMemoryMojoReaderBackend);
try {
assertTrue(r.exists("binary-file"));
assertTrue(r.exists("text-file"));
assertEquals("line1", r.getTextFile("text-file").readLine());
} finally {
((Closeable) r).close();
}
}
use of java.io.Closeable in project hazelcast by hazelcast.
the class ClassLocator method tryToGetClassFromRemote.
private Class<?> tryToGetClassFromRemote(String name) throws ClassNotFoundException {
// we need to acquire a classloading lock before defining a class
// Java 7+ can use locks with per-class granularity while Java 6 has to use a single lock
// mutexFactory abstract these differences away
Closeable classMutex = mutexFactory.getMutexForClass(name);
try {
synchronized (classMutex) {
ClassSource classSource = classSourceMap.get(name);
if (classSource != null) {
if (logger.isFineEnabled()) {
logger.finest("Class " + name + " is already in a local cache. ");
}
return classSource.getClazz();
}
byte[] classDef = fetchBytecodeFromRemote(name);
if (classDef == null) {
throw new ClassNotFoundException("Failed to load class " + name + " from other members.");
}
return defineAndCacheClass(name, classDef);
}
} finally {
IOUtil.closeResource(classMutex);
}
}
Aggregations