use of org.glassfish.api.deployment.ResourceClassLoader in project Payara by payara.
the class ApplicationState method start.
/**
* Starts the Application state for new deployment by copying the cached
* metadata and properties to the new {@code DeploymentContext} instance.
*
* @param commandParams
* @param newContext
* @param events
* @return
*/
public boolean start(DeployCommandParameters commandParams, ExtendedDeploymentContext newContext, Events events) {
validateInactiveState();
this.active = true;
if (commandParams.sourcesChanged != null) {
this.classesChanged = new HashMap<>();
for (String sourcePath : commandParams.sourcesChanged) {
String className = getClassName(sourcePath);
if (className != null) {
this.classesChanged.put(className, sourcePath);
}
}
}
if (hotswap) {
final Map<Class<?>, byte[]> reloadMap = new HashMap<>();
ResourceClassLoader previousResourceClassLoader = ResourceClassLoader.class.cast(applicationClassLoader);
ConcurrentHashMap<String, ResourceEntry> previousResourceEntries = previousResourceClassLoader.getResourceEntries();
previousResourceEntries.entrySet().stream().filter(e -> classesChanged.containsKey(e.getKey())).forEach(e -> {
Class clazz = previousResourceClassLoader.reloadResourceEntry(e.getKey(), classesChanged.get(e.getKey()), e.getValue());
reloadMap.put(clazz, e.getValue().binaryContent);
});
// Update application classloader
HotSwapHelper.hotswap(reloadMap);
newContext.setClassLoader(applicationClassLoader);
ProgressTracker tracker = newContext.getTransientAppMetaData(ExtendedDeploymentContext.TRACKER, ProgressTracker.class);
try {
// Reload application metadata
reloadApplicationMetaData(newContext);
// Reload application engines
applicationInfo.reload(newContext, tracker);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
return false;
} else {
if (this.applicationInfo != null) {
this.previousClassLoaders = getClassLoaders(this.applicationInfo);
}
newContext.getAppProps().putAll(this.deploymentContext.getAppProps());
newContext.getModulePropsMap().putAll(this.deploymentContext.getModulePropsMap());
this.deploymentContext = newContext;
Set<Class> requiredMetaDataClasses = requiredMetaDataClasses();
this.modulesMetaData.values().stream().filter(md -> !requiredMetaDataClasses.contains(md.getClass())).forEach(newContext::addModuleMetaData);
this.getDescriptorMetadata().entrySet().forEach(e -> newContext.addTransientAppMetaData(e.getKey(), e.getValue()));
if (applicationClassLoader != null && applicationClassLoader instanceof ResourceClassLoader) {
ClassLoader newClassLoader = newContext.getArchiveHandler().getClassLoader(applicationClassLoader.getParent(), newContext);
ResourceClassLoader newResourceClassLoader = ResourceClassLoader.class.cast(newClassLoader);
ResourceClassLoader previousResourceClassLoader = ResourceClassLoader.class.cast(applicationClassLoader);
ConcurrentHashMap<String, ResourceEntry> previousResourceEntries = previousResourceClassLoader.getResourceEntries();
previousResourceEntries.entrySet().stream().filter(e -> !classesChanged.containsKey(e.getKey())).forEach(e -> newResourceClassLoader.addResourceEntry(e.getKey(), classesChanged.get(e.getKey()), e.getValue()));
newContext.setClassLoader(newClassLoader);
if (this.applicationInfo != null) {
// unload previous app
events.send(new EventListener.Event<>(Deployment.APPLICATION_UNLOADED, this.applicationInfo), false);
}
}
}
return true;
}
Aggregations