Skip to content

Commit

Permalink
fixup! Add initial support of Project CRaC
Browse files Browse the repository at this point in the history
Move CRaC actions to internal class
  • Loading branch information
AntonKozlov committed Feb 28, 2022
1 parent f326619 commit e59ec67
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* The implementation also contains optimizations that allow the ClassLoader to keep a minimum number of jars open
* while also preventing the lookup of the entire classpath for missing resources in known directories (like META-INF/services).
*/
public final class RunnerClassLoader extends ClassLoader implements Resource {
public final class RunnerClassLoader extends ClassLoader {

/**
* A map of resources by dir name. Root dir/default package is represented by the empty string
Expand All @@ -43,6 +43,8 @@ public final class RunnerClassLoader extends ClassLoader implements Resource {
//Protected by synchronization on the above field, as they are related.
private boolean postBootPhase = false;

private final CracResource resource;

RunnerClassLoader(ClassLoader parent, Map<String, ClassLoadingResource[]> resourceDirectoryMap,
Set<String> parentFirstPackages, Set<String> nonExistentResources,
List<String> fullyIndexedDirectories, Map<String, ClassLoadingResource[]> directlyIndexedResourcesIndexMap) {
Expand All @@ -52,7 +54,9 @@ public final class RunnerClassLoader extends ClassLoader implements Resource {
this.nonExistentResources = nonExistentResources;
this.fullyIndexedDirectories = fullyIndexedDirectories;
this.directlyIndexedResourcesIndexMap = directlyIndexedResourcesIndexMap;
org.crac.Core.getGlobalContext().register(this);

resource = new CracResource();
org.crac.Core.getGlobalContext().register(resource);
}

@Override
Expand Down Expand Up @@ -294,19 +298,21 @@ public void resetInternalCaches() {
}
}

@Override
public void beforeCheckpoint(Context<? extends Resource> ctx) {
synchronized (this.currentlyBufferedResources) {
for (int i = 0; i < currentlyBufferedResources.length; ++i) {
if (currentlyBufferedResources[i] != null) {
currentlyBufferedResources[i].resetInternalCaches();
currentlyBufferedResources[i] = null;
class CracResource implements Resource {
@Override
public void beforeCheckpoint(Context<? extends Resource> ctx) {
synchronized (currentlyBufferedResources) {
for (int i = 0; i < currentlyBufferedResources.length; ++i) {
if (currentlyBufferedResources[i] != null) {
currentlyBufferedResources[i].resetInternalCaches();
currentlyBufferedResources[i] = null;
}
}
}
}
}

@Override
public void afterRestore(Context<? extends Resource> ctx) {
@Override
public void afterRestore(Context<? extends Resource> ctx) {
}
}
}

0 comments on commit e59ec67

Please sign in to comment.