-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clear caches from the runtime hook (#10954)
close #10897 Changelog: - add: implement `RuntimeHooks` to defer some logic until the program execution happens. (cherry picked from commit 6c80f8f)
- Loading branch information
1 parent
c87e6c1
commit 875710a
Showing
9 changed files
with
153 additions
and
55 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...rument-common/src/main/java/org/enso/interpreter/instrument/execution/ExecutionHooks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.enso.interpreter.instrument.execution; | ||
|
||
public interface ExecutionHooks { | ||
|
||
/** | ||
* Add a hook to run before the execution. | ||
* | ||
* @param hook the runnable hook | ||
*/ | ||
void add(Runnable hook); | ||
|
||
/** Consume and run all the stored execution hooks. */ | ||
void run(); | ||
} |
35 changes: 35 additions & 0 deletions
35
...common/src/main/java/org/enso/interpreter/instrument/execution/RuntimeExecutionHooks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.enso.interpreter.instrument.execution; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public final class RuntimeExecutionHooks implements ExecutionHooks { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
private final Set<Runnable> hooks = new LinkedHashSet<>(); | ||
|
||
public RuntimeExecutionHooks() {} | ||
|
||
@Override | ||
public void add(Runnable hook) { | ||
synchronized (hooks) { | ||
hooks.add(hook); | ||
} | ||
} | ||
|
||
@Override | ||
public void run() { | ||
synchronized (hooks) { | ||
for (Runnable hook : hooks) { | ||
try { | ||
hook.run(); | ||
} catch (Exception e) { | ||
logger.error("Failed to run execution hook.", e); | ||
} | ||
} | ||
hooks.clear(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...ent-common/src/test/scala/org/enso/interpreter/instrument/job/SlowEnsureCompiledJob.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.enso.interpreter.instrument.job | ||
|
||
import org.enso.interpreter.instrument.execution.RuntimeContext | ||
import org.enso.interpreter.instrument.job.EnsureCompiledJob.CompilationStatus | ||
|
||
import java.io.File | ||
|
||
class SlowEnsureCompiledJob( | ||
files: Iterable[File], | ||
isCancellable: Boolean = true | ||
) extends EnsureCompiledJob(files, isCancellable) { | ||
|
||
override def run(implicit ctx: RuntimeContext): CompilationStatus = { | ||
Thread.sleep(1000) | ||
super.run(ctx) | ||
} | ||
|
||
} |