Interface ConsoleSession<O,R extends ConsoleRequest<R>>
- Type Parameters:
O
- associated owner typeR
- associated request type
- All Known Subinterfaces:
ExecSession
,ShellSession
- All Known Implementing Classes:
AbstractConsoleSession
,AbstractExecSession
,AbstractShellSession
,JShellShellSession
,SimpleExec.Session
,SimpleShell.Session
ConsoleSession
s are created by console components from ConsoleRequest
s and then executed
synchronously. During execution, interrupt()
may be invoked (by another thread) to signal that the execution
should be interrupted.
ConsoleSession
s are not reusable.
-
Method Summary
Modifier and TypeMethodDescriptionint
execute()
Execute this session synchronously in the current thread.Get this session's error output stream.Get this session's input stream.Get this session's output stream.getOwner()
Get the owner, i.e., the console component that created this session.Get the request from which this session was created.boolean
Interrupt the execution of this session.
-
Method Details
-
getOwner
O getOwner()Get the owner, i.e., the console component that created this session.- Returns:
- owning component
-
getRequest
R getRequest()Get the request from which this session was created.- Returns:
- original request
-
getInputStream
InputStream getInputStream()Get this session's input stream.- Returns:
- session input
-
getOutputStream
PrintStream getOutputStream()Get this session's output stream.- Returns:
- session output
-
getErrorStream
PrintStream getErrorStream()Get this session's error output stream.- Returns:
- session error output
-
execute
Execute this session synchronously in the current thread.Instances should ensure any associated resources are cleaned up when this method returns, whether normally or via thrown exception.
- Returns:
- zero if successful, non-zero error code if an error occurred
- Throws:
InterruptedException
- if execution is interrupted viainterrupt()
IllegalStateException
- if this method has already been invoked
-
interrupt
boolean interrupt()Interrupt the execution of this session.This method no effect unless
execute()
has been invoked and not yet returned.How this method is handled is up to the session: in general, it should cause the execution of
execute()
to be interrupted, such thatexecute()
then either throws anInterruptedException
or at least returns immediately. In general, it should have roughly the same effect as one would expect when pressing Control-C on a controlling terminal.- Returns:
- true if execution was interrupted, false if it was not possible to interrupt execution
-