use of java.io.Closeable in project wildfly by wildfly.
the class RaOperationUtil method installRaServicesAndDeployFromModule.
public static void installRaServicesAndDeployFromModule(OperationContext context, String name, ModifiableResourceAdapter resourceAdapter, String fullModuleName, final List<ServiceController<?>> newControllers) throws OperationFailedException {
ServiceName raServiceName = installRaServices(context, name, resourceAdapter, newControllers);
final boolean resolveProperties = true;
final ServiceTarget serviceTarget = context.getServiceTarget();
final String moduleName;
//load module
String slot = "main";
if (fullModuleName.contains(":")) {
slot = fullModuleName.substring(fullModuleName.indexOf(":") + 1);
moduleName = fullModuleName.substring(0, fullModuleName.indexOf(":"));
} else {
moduleName = fullModuleName;
}
Module module;
try {
ModuleIdentifier moduleId = ModuleIdentifier.create(moduleName, slot);
module = Module.getCallerModuleLoader().loadModule(moduleId);
} catch (ModuleLoadException e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName), e);
}
URL path = module.getExportedResource("META-INF/ra.xml");
Closeable closable = null;
try {
VirtualFile child;
if (path.getPath().contains("!")) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.compressedRarNotSupportedInModuleRA(moduleName));
} else {
child = VFS.getChild(path.getPath().split("META-INF")[0]);
closable = VFS.mountReal(new File(path.getPath().split("META-INF")[0]), child);
}
//final Closeable closable = VFS.mountZip((InputStream) new JarInputStream(new FileInputStream(path.getPath().split("!")[0].split(":")[1])), path.getPath().split("!")[0].split(":")[1], child, TempFileProviderService.provider());
final MountHandle mountHandle = new MountHandle(closable);
final ResourceRoot resourceRoot = new ResourceRoot(child, mountHandle);
final VirtualFile deploymentRoot = resourceRoot.getRoot();
if (deploymentRoot == null || !deploymentRoot.exists())
return;
ConnectorXmlDescriptor connectorXmlDescriptor = RaDeploymentParsingProcessor.process(resolveProperties, deploymentRoot, null, name);
IronJacamarXmlDescriptor ironJacamarXmlDescriptor = IronJacamarDeploymentParsingProcessor.process(deploymentRoot, resolveProperties);
RaNativeProcessor.process(deploymentRoot);
Map<ResourceRoot, Index> annotationIndexes = new HashMap<ResourceRoot, Index>();
ResourceRootIndexer.indexResourceRoot(resourceRoot);
Index index = resourceRoot.getAttachment(Attachments.ANNOTATION_INDEX);
if (index != null) {
annotationIndexes.put(resourceRoot, index);
}
if (ironJacamarXmlDescriptor != null) {
ConnectorLogger.SUBSYSTEM_RA_LOGGER.forceIJToNull();
ironJacamarXmlDescriptor = null;
}
final ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(connectorXmlDescriptor.getDeploymentName());
final ServiceController<?> deployerService = context.getServiceRegistry(true).getService(deployerServiceName);
if (deployerService == null) {
ServiceBuilder builder = ParsedRaDeploymentProcessor.process(connectorXmlDescriptor, ironJacamarXmlDescriptor, module.getClassLoader(), serviceTarget, annotationIndexes, RAR_MODULE.append(name), null, null);
newControllers.add(builder.addDependency(raServiceName).setInitialMode(ServiceController.Mode.ACTIVE).install());
}
String rarName = resourceAdapter.getArchive();
if (fullModuleName.equals(rarName)) {
ServiceName serviceName = ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(name);
InactiveResourceAdapterDeploymentService service = new InactiveResourceAdapterDeploymentService(connectorXmlDescriptor, module, name, name, RAR_MODULE.append(name), null, serviceTarget, null);
newControllers.add(serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).install());
}
} catch (Exception e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName), e);
} finally {
if (closable != null) {
try {
closable.close();
} catch (IOException e) {
}
}
}
}
use of java.io.Closeable in project wildfly by wildfly.
the class JaxrsSpringProcessor method getResteasySpringVirtualFile.
/**
* Lookup Seam integration resource loader.
*
* @return the Seam integration resource loader
* @throws DeploymentUnitProcessingException
* for any error
*/
protected synchronized VirtualFile getResteasySpringVirtualFile() throws DeploymentUnitProcessingException {
if (resourceRoot != null) {
return resourceRoot;
}
try {
Module module = Module.getBootModuleLoader().loadModule(MODULE);
URL fileUrl = module.getClassLoader().getResource(JAR_LOCATION);
if (fileUrl == null) {
throw JaxrsLogger.JAXRS_LOGGER.noSpringIntegrationJar();
}
File dir = new File(fileUrl.toURI());
File file = null;
for (String jar : dir.list()) {
if (jar.endsWith(".jar")) {
file = new File(dir, jar);
break;
}
}
if (file == null) {
throw JaxrsLogger.JAXRS_LOGGER.noSpringIntegrationJar();
}
VirtualFile vf = VFS.getChild(file.toURI());
final Closeable mountHandle = VFS.mountZip(file, vf, TempFileProviderService.provider());
Service<Closeable> mountHandleService = new Service<Closeable>() {
public void start(StartContext startContext) throws StartException {
}
public void stop(StopContext stopContext) {
VFSUtils.safeClose(mountHandle);
}
public Closeable getValue() throws IllegalStateException, IllegalArgumentException {
return mountHandle;
}
};
ServiceBuilder<Closeable> builder = serviceTarget.addService(ServiceName.JBOSS.append(SERVICE_NAME), mountHandleService);
builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
resourceRoot = vf;
return resourceRoot;
} catch (Exception e) {
throw new DeploymentUnitProcessingException(e);
}
}
use of java.io.Closeable in project eiger by wlloyd.
the class RowIteratorFactory method getIterator.
/**
* Get a row iterator over the provided memtables and sstables, between the provided keys
* and filtered by the queryfilter.
* @param memtables Memtables pending flush.
* @param sstables SStables to scan through.
* @param startWith Start at this key
* @param stopAt Stop and this key
* @param filter Used to decide which columns to pull out
* @param cfs
* @return A row iterator following all the given restrictions
*/
public static CloseableIterator<Row> getIterator(final Iterable<Memtable> memtables, final Collection<SSTableReader> sstables, final RowPosition startWith, final RowPosition stopAt, final QueryFilter filter, final ColumnFamilyStore cfs) {
// fetch data from current memtable, historical memtables, and SSTables in the correct order.
final List<CloseableIterator<IColumnIterator>> iterators = new ArrayList<CloseableIterator<IColumnIterator>>();
// memtables
for (Memtable memtable : memtables) {
iterators.add(new ConvertToColumnIterator(filter, memtable.getEntryIterator(startWith, stopAt)));
}
for (SSTableReader sstable : sstables) {
final SSTableScanner scanner = sstable.getScanner(filter);
scanner.seekTo(startWith);
// otherwise we leak FDs
assert scanner instanceof Closeable;
iterators.add(scanner);
}
// reduce rows from all sources into a single row
return MergeIterator.get(iterators, COMPARE_BY_KEY, new MergeIterator.Reducer<IColumnIterator, Row>() {
private final int gcBefore = (int) (System.currentTimeMillis() / 1000) - cfs.metadata.getGcGraceSeconds();
private final List<IColumnIterator> colIters = new ArrayList<IColumnIterator>();
private DecoratedKey key;
private ColumnFamily returnCF;
@Override
protected void onKeyChange() {
this.returnCF = ColumnFamily.create(cfs.metadata);
}
public void reduce(IColumnIterator current) {
this.colIters.add(current);
this.key = current.getKey();
this.returnCF.delete(current.getColumnFamily());
}
protected Row getReduced() {
// First check if this row is in the rowCache. If it is we can skip the rest
ColumnFamily cached = cfs.getRawCachedRow(key);
if (cached == null)
// not cached: collate
filter.collateColumns(returnCF, colIters, gcBefore);
else {
QueryFilter keyFilter = new QueryFilter(key, filter.path, filter.filter);
returnCF = cfs.filterColumnFamily(cached, keyFilter, gcBefore);
}
Row rv = new Row(key, returnCF);
colIters.clear();
key = null;
return rv;
}
});
}
use of java.io.Closeable in project tika by apache.
the class TemporaryResources method close.
/**
* Closes all tracked resources. The resources are closed in reverse order
* from how they were added.
* <p>
* Any suppressed exceptions from managed resources are collected and
* then added to the first thrown exception, which is re-thrown once
* all the resources have been closed.
*
* @throws IOException if one or more of the tracked resources
* could not be closed
*/
public void close() throws IOException {
// Release all resources and keep track of any exceptions
IOException exception = null;
for (Closeable resource : resources) {
try {
resource.close();
} catch (IOException e) {
if (exception == null) {
exception = e;
} else {
exception.addSuppressed(e);
}
}
}
resources.clear();
// Throw any exceptions that were captured from above
if (exception != null) {
throw exception;
}
}
use of java.io.Closeable in project tika by apache.
the class TemporaryResources method createTempFile.
/**
* Creates a temporary file that will automatically be deleted when
* the {@link #close()} method is called, returning its path.
*
* @return Path to created temporary file that will be deleted after closing
* @throws IOException
*/
public Path createTempFile() throws IOException {
final Path path = tempFileDir == null ? Files.createTempFile("apache-tika-", ".tmp") : Files.createTempFile(tempFileDir, "apache-tika-", ".tmp");
addResource(new Closeable() {
public void close() throws IOException {
Files.delete(path);
}
});
return path;
}
Aggregations