private ResourceHandle installUnsharedResourceInternal(Context context, Resource resource) throws Exception {
LOGGER.info("Installing unshared resource: {}", resource);
String runtimeName = getRuntimeName(resource, false);
final ServerDeploymentHelper serverDeployer = new ServerDeploymentHelper(serverDeploymentManager);
final ResourceWrapper wrapper = getWrappedResourceContent(runtimeName, resource, context.getResourceMapping());
runtimeName = wrapper.getRuntimeName();
NamedResourceAssociation.putResource(wrapper.getRuntimeName(), resource);
try {
String deploymentName = wrapper.getDeploymentName();
serverDeployer.deploy(deploymentName, wrapper.getInputStream());
} finally {
NamedResourceAssociation.removeResource(runtimeName);
}
// Install the resource as module if it has not happend already
Runtime runtime = RuntimeLocator.getRequiredRuntime();
Module module = runtime.getModule(resource.getIdentity());
if (module == null) {
ModuleLoader moduleLoader = injectedServiceModuleLoader.getValue();
ModuleIdentifier modid = ModuleIdentifier.create(ServiceModuleLoader.MODULE_PREFIX + runtimeName);
ClassLoader classLoader = moduleLoader.loadModule(modid).getClassLoader();
module = runtime.installModule(classLoader, resource, null);
}
Resource modres = module != null ? module.adapt(Resource.class) : resource;
return new AbstractResourceHandle(modres, module) {
@Override
public void uninstall() {
try {
String deploymentName = wrapper.getDeploymentName();
serverDeployer.undeploy(deploymentName);
} catch (Throwable th) {
LOGGER.warn("Cannot uninstall provisioned resource: " + getResource(), th);
}
}
};