Interface ConsoleSession<O,R extends ConsoleRequest<R>>

Type Parameters:
O - associated owner type
R - associated request type
All Known Subinterfaces:
ExecSession, ShellSession
All Known Implementing Classes:
AbstractConsoleSession, AbstractExecSession, AbstractShellSession, JShellShellSession, SimpleExec.Session, SimpleShell.Session

public interface ConsoleSession<O,R extends ConsoleRequest<R>>
A session associated with a console component.

ConsoleSessions are created by console components from ConsoleRequests and then executed synchronously. During execution, interrupt() may be invoked (by another thread) to signal that the execution should be interrupted.

ConsoleSessions are not reusable.

  • Method Summary

    Modifier and Type
    Method
    Description
    int
    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.
    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

      int execute() throws InterruptedException
      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 via interrupt()
      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 that execute() then either throws an InterruptedException 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