@@ -27,6 +27,7 @@ public class JShellService implements Closeable {
27
27
private final long evalTimeout ;
28
28
private boolean doingOperation ;
29
29
private final DockerService dockerService ;
30
+ private final int startupScriptSize ;
30
31
31
32
public JShellService (DockerService dockerService , JShellSessionService sessionService , String id , long timeout , boolean renewable , long evalTimeout , long evalTimeoutValidationLeeway , int sysOutCharLimit , int maxMemory , double cpus , String startupScript ) throws DockerException {
32
33
this .dockerService = dockerService ;
@@ -38,7 +39,7 @@ public JShellService(DockerService dockerService, JShellSessionService sessionSe
38
39
this .evalTimeoutValidationLeeway = evalTimeoutValidationLeeway ;
39
40
this .lastTimeoutUpdate = Instant .now ();
40
41
if (!dockerService .isDead (containerName ())) {
41
- LOGGER .error ("Tried to create an existing container {}." , containerName ());
42
+ LOGGER .warn ("Tried to create an existing container {}." , containerName ());
42
43
throw new DockerException ("The session isn't completely destroyed, try again later." );
43
44
}
44
45
try {
@@ -58,9 +59,12 @@ public JShellService(DockerService dockerService, JShellSessionService sessionSe
58
59
reader = new BufferedReader (new InputStreamReader (containerOutput ));
59
60
writer .write (sanitize (startupScript ));
60
61
writer .newLine ();
61
- } catch (IOException | InterruptedException e ) {
62
+ writer .flush ();
63
+ checkContainerOK ();
64
+ startupScriptSize = Integer .parseInt (reader .readLine ());
65
+ } catch (Exception e ) {
62
66
LOGGER .warn ("Unexpected error during creation." , e );
63
- throw new DockerException (e );
67
+ throw new DockerException ("Creation of the session failed." , e );
64
68
}
65
69
this .doingOperation = false ;
66
70
}
@@ -136,7 +140,7 @@ private JShellResult readResult() throws IOException, NumberFormatException, Doc
136
140
return new JShellResult (snippetResults , abortion , stdoutOverflow , stdout );
137
141
}
138
142
139
- public Optional <List <String >> snippets () throws DockerException {
143
+ public Optional <List <String >> snippets (boolean includeStartupScript ) throws DockerException {
140
144
synchronized (this ) {
141
145
if (!tryStartOperation ()) {
142
146
return Optional .empty ();
@@ -155,7 +159,9 @@ public Optional<List<String>> snippets() throws DockerException {
155
159
while (!(snippet = reader .readLine ()).isEmpty ()) {
156
160
snippets .add (cleanCode (snippet ));
157
161
}
158
- return Optional .of (snippets );
162
+ return Optional .of (
163
+ includeStartupScript ? snippets : snippets .subList (startupScriptSize , snippets .size ())
164
+ );
159
165
} catch (IOException ex ) {
160
166
LOGGER .warn ("Unexpected error." , ex );
161
167
close ();
0 commit comments