1616import org .apache .logging .log4j .core .LoggerContext ;
1717import org .apache .logging .log4j .core .config .Configuration ;
1818import org .apache .logging .log4j .core .config .LoggerConfig ;
19+ import org .jruby .embed .internal .BiVariableMap ;
1920
2021import java .io .File ;
2122import java .io .IOException ;
2526import java .util .HashMap ;
2627import java .util .List ;
2728import java .util .Map ;
29+ import java .util .function .BiConsumer ;
2830import java .util .function .Consumer ;
2931import java .util .function .Supplier ;
3032
@@ -551,7 +553,8 @@ public NuixVersion getNuixVersion() {
551553 */
552554 public RubyScriptRunner runRubyScriptAsync (String script , @ Nullable Map <String , Object > additionalVariables ,
553555 @ Nullable Consumer <String > standardOutputReceiver ,
554- @ Nullable Consumer <String > errorOutputReceiver ) throws Exception {
556+ @ Nullable Consumer <String > errorOutputReceiver ,
557+ @ Nullable BiConsumer <Object , BiVariableMap > completedCallback ) throws Exception {
555558 Map <String , Object > vars = new HashMap <>();
556559 if (additionalVariables != null ) {
557560 vars .putAll (additionalVariables );
@@ -562,6 +565,9 @@ public RubyScriptRunner runRubyScriptAsync(String script, @Nullable Map<String,
562565 RubyScriptRunner rubyScriptRunner = new RubyScriptRunner ();
563566 rubyScriptRunner .setStandardOutputConsumer (standardOutputReceiver );
564567 rubyScriptRunner .setErrorOutputConsumer (errorOutputReceiver );
568+ if (completedCallback != null ) {
569+ rubyScriptRunner .whenScriptCompletes (completedCallback );
570+ }
565571 rubyScriptRunner .runScriptAsync (script , getNuixVersionString (), vars );
566572 return rubyScriptRunner ;
567573 }
@@ -580,8 +586,9 @@ public RubyScriptRunner runRubyScriptAsync(String script, @Nullable Map<String,
580586 * @return A {@link RubyScriptRunner} instance. Call {@link RubyScriptRunner#join()} to wait for script to complete.
581587 * @throws Exception Exceptions are allowed to bubble up.
582588 */
583- public RubyScriptRunner runRubyScriptAsync (String script , @ Nullable Map <String , Object > additionalVariables ) throws Exception {
584- return runRubyScriptAsync (script , additionalVariables , null , null );
589+ public RubyScriptRunner runRubyScriptAsync (String script , @ Nullable Map <String , Object > additionalVariables ,
590+ @ Nullable BiConsumer <Object , BiVariableMap > completedCallback ) throws Exception {
591+ return runRubyScriptAsync (script , additionalVariables , null , null , completedCallback );
585592 }
586593
587594 /***
@@ -596,8 +603,9 @@ public RubyScriptRunner runRubyScriptAsync(String script, @Nullable Map<String,
596603 * @return A {@link RubyScriptRunner} instance. Call {@link RubyScriptRunner#join()} to wait for script to complete.
597604 * @throws Exception Exceptions are allowed to bubble up.
598605 */
599- public RubyScriptRunner runRubyScriptAsync (String script ) throws Exception {
600- return runRubyScriptAsync (script , null , null , null );
606+ public RubyScriptRunner runRubyScriptAsync (String script ,
607+ @ Nullable BiConsumer <Object , BiVariableMap > completedCallback ) throws Exception {
608+ return runRubyScriptAsync (script , null , null , null , completedCallback );
601609 }
602610
603611 /***
@@ -622,7 +630,8 @@ public RubyScriptRunner runRubyScriptAsync(String script) throws Exception {
622630 */
623631 public RubyScriptRunner runRubyScriptFileAsync (File scriptFile , @ Nullable Map <String , Object > additionalVariables ,
624632 @ Nullable Consumer <String > standardOutputReceiver ,
625- @ Nullable Consumer <String > errorOutputReceiver ) throws Exception {
633+ @ Nullable Consumer <String > errorOutputReceiver ,
634+ @ Nullable BiConsumer <Object , BiVariableMap > completedCallback ) throws Exception {
626635 Map <String , Object > vars = new HashMap <>();
627636 if (additionalVariables != null ) {
628637 vars .putAll (additionalVariables );
@@ -633,6 +642,9 @@ public RubyScriptRunner runRubyScriptFileAsync(File scriptFile, @Nullable Map<St
633642 RubyScriptRunner rubyScriptRunner = new RubyScriptRunner ();
634643 rubyScriptRunner .setStandardOutputConsumer (standardOutputReceiver );
635644 rubyScriptRunner .setErrorOutputConsumer (errorOutputReceiver );
645+ if (completedCallback != null ) {
646+ rubyScriptRunner .whenScriptCompletes (completedCallback );
647+ }
636648 rubyScriptRunner .runFileAsync (scriptFile , getNuixVersionString (), vars );
637649 return rubyScriptRunner ;
638650 }
@@ -653,8 +665,9 @@ public RubyScriptRunner runRubyScriptFileAsync(File scriptFile, @Nullable Map<St
653665 * @return A {@link RubyScriptRunner} instance. Call {@link RubyScriptRunner#join()} to wait for script to complete.
654666 * @throws Exception Exceptions are allowed to bubble up.
655667 */
656- public RubyScriptRunner runRubyScriptFileAsync (File scriptFile , @ Nullable Map <String , Object > additionalVariables ) throws Exception {
657- return runRubyScriptFileAsync (scriptFile , additionalVariables , null , null );
668+ public RubyScriptRunner runRubyScriptFileAsync (File scriptFile , @ Nullable Map <String , Object > additionalVariables ,
669+ @ Nullable BiConsumer <Object , BiVariableMap > completedCallback ) throws Exception {
670+ return runRubyScriptFileAsync (scriptFile , additionalVariables , null , null , completedCallback );
658671 }
659672
660673 /***
@@ -671,8 +684,9 @@ public RubyScriptRunner runRubyScriptFileAsync(File scriptFile, @Nullable Map<St
671684 * @return A {@link RubyScriptRunner} instance. Call {@link RubyScriptRunner#join()} to wait for script to complete.
672685 * @throws Exception Exceptions are allowed to bubble up.
673686 */
674- public RubyScriptRunner runRubyScriptFileAsync (File scriptFile ) throws Exception {
675- return runRubyScriptFileAsync (scriptFile , null , null , null );
687+ public RubyScriptRunner runRubyScriptFileAsync (File scriptFile ,
688+ @ Nullable BiConsumer <Object , BiVariableMap > completedCallback ) throws Exception {
689+ return runRubyScriptFileAsync (scriptFile , null , null , null , completedCallback );
676690 }
677691
678692 /***
0 commit comments