4747import java .util .concurrent .ThreadFactory ;
4848import java .util .concurrent .TimeUnit ;
4949import java .util .concurrent .locks .Lock ;
50- import java .util .function .Consumer ;
5150
5251import org .apposed .appose .Environment ;
5352import org .apposed .appose .util .Environments ;
@@ -79,7 +78,7 @@ final class ApposePythonEnvironments {
7978 * How long an environment's configuration must stay the same before it is
8079 * built, in milliseconds.
8180 */
82- static final long SETTLE = 5000 ;
81+ private static final long SETTLE = 5000 ;
8382
8483 /** Where settling environments are waited for. */
8584 private static final ScheduledExecutorService TIMER = Executors
@@ -89,15 +88,9 @@ final class ApposePythonEnvironments {
8988 private static final ExecutorService BUILDS = Executors
9089 .newSingleThreadExecutor (daemon ("appose-python-prebuild" ));
9190
92- /** The resident workers, to find built environments; or null if none . */
91+ /** The resident workers, to find built environments. */
9392 private final ResidentWorkerService workers ;
9493
95- /** How long a configuration must stay the same before it is built. */
96- private final long settle ;
97-
98- /** Builds an environment; or null, to build none. */
99- private final Consumer <ScriptEnvironment > build ;
100-
10194 /** Scripts waiting to settle, by path ("" if unsaved): what, and when. */
10295 private final Map <String , Settling > settling = new HashMap <>();
10396
@@ -120,25 +113,9 @@ protected boolean removeEldestEntry(
120113 }
121114 };
122115
123- /** @param workers The resident workers, or null if none (none built) . */
116+ /** @param workers The resident workers. */
124117 ApposePythonEnvironments (final ResidentWorkerService workers ) {
125- this (workers , SETTLE , null );
126- }
127-
128- /**
129- * @param workers The resident workers, or null if none.
130- * @param settle How long a configuration must stay the same before it is
131- * built, in milliseconds.
132- * @param build Builds an environment (e.g. a fake one, in tests); or null,
133- * to build them with the workers (if any).
134- */
135- ApposePythonEnvironments (final ResidentWorkerService workers ,
136- final long settle , final Consumer <ScriptEnvironment > build )
137- {
138118 this .workers = workers ;
139- this .settle = settle ;
140- this .build = build != null ? build : workers != null ? this ::build
141- : null ;
142119 }
143120
144121 /**
@@ -207,8 +184,8 @@ private String findScriptPython(final String text, final String path) {
207184 if (env == null ) return null ;
208185 // NB: A read-only lookup: worker(...) would replace the worker whenever
209186 // the configuration changed, i.e. as the user edits it.
210- final ResidentWorker worker = workers == null ? null : workers .find (
211- env . name , env . activate , env .config ());
187+ final ResidentWorker worker = workers .find (env . name , env . activate , env
188+ .config ());
212189 if (worker != null && worker .environment ().isBuilt ()) {
213190 try {
214191 final String python = pythonExecutable (worker .environment ().get ());
@@ -228,13 +205,12 @@ private String findScriptPython(final String text, final String path) {
228205
229206 /**
230207 * Builds an environment once its configuration has stayed the same for a
231- * while (see {@link #settle }), unless it was tried already.
208+ * while (see {@link #SETTLE }), unless it was tried already.
232209 */
233210 private void prepare (final String path , final ScriptEnvironment env ) {
234211 // NB: By script, not by environment: an unsaved script's environment
235212 // is named after its configuration, so changes to it with each edit.
236213 final String script = path == null ? "" : path ;
237- if (build == null ) return ;
238214 final String key = env .name + "\n " + env .config ();
239215 synchronized (settling ) {
240216 if (key .equals (tried .get (script ))) return ;
@@ -248,8 +224,8 @@ private void prepare(final String path, final ScriptEnvironment env) {
248224 settling .remove (script );
249225 if (key .equals (tried .put (script , key ))) return ;
250226 }
251- CompletableFuture .runAsync (() -> build . accept (env ), BUILDS );
252- }, settle , TimeUnit .MILLISECONDS )));
227+ CompletableFuture .runAsync (() -> build (env ), BUILDS );
228+ }, SETTLE , TimeUnit .MILLISECONDS )));
253229 }
254230 }
255231
0 commit comments