Class REPL

java.lang.Object
de.uni_kiel.rz.fdr.repl.REPL

public class REPL extends Object
This class represents a single REPL interface with an associated SSH service.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The default name of the work subdirectory containing the REPL's persistent state.
    static boolean
    Does this build of cau-repl contain GPL licensed code?
    static boolean
    Are we running in a JVM whith MyCoRe?
    static boolean
    Are we running in a JVM with MyCoRe's MODS module?
    static final String
    Threads of cau-repl have a name that starts with this prefix
    static final org.apache.sshd.common.AttributeRepository.AttributeKey<String>
    The user name used for login will be accessible from each SSH Session using this key.
    static final String
    cau-repl's version
  • Constructor Summary

    Constructors
    Constructor
    Description
    REPL(String listenAddr, Integer port, Integer timeoutSecs, File workDir, ClassLoader groovyClassLoader)
    Creates the REPL.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add a startup script from our .jar to be executed in the REPL each time a user has connected.
    void
    addSessionListener(org.apache.sshd.common.session.SessionListener sessionListener)
    Respond to SSH events by installing your own listener.
    void
    Adds a command to be executed inside the REPL each time a user has connected.
    void
    Add a startup script to be executed in the REPL each time a user has connected.
    static void
    Update the various HAVE_* fields.
    org.apache.sshd.server.auth.password.PasswordAuthenticator
    Gets the authenticator in use for the SSH session.
    Gets the ClassLoader that will be used for the REPL.
    Gets the IP that the SSH service will bind to.
    int
    Gets the port that the SSH service will listen on.
    List<org.apache.sshd.common.session.SessionListener>
    Gets the session listeners that were configured for the SSH service.
    Get the startup commands that were configured for the REPL.
    Get the startup scripts that were configured for the REPL.
    int
    Get the timeout for idle SSH connections.
    static String
    Generates a textual representation of cau-repl's version
    static File
    Get the REPL's work directory
    void
    setAuthenticator(org.apache.sshd.server.auth.password.PasswordAuthenticator authenticator)
    Sets a custom authenticator for the SSH service.
    static void
    setWorkDir(File workDir)
    Allows you to initialize the global work directory before creating a REPL instance.
    void
    Start listening for incoming SSH connections.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • VERSION

      public static final String VERSION
      cau-repl's version
      See Also:
    • USER_KEY

      public static final org.apache.sshd.common.AttributeRepository.AttributeKey<String> USER_KEY
      The user name used for login will be accessible from each SSH Session using this key.
    • DEFAULT_WORK_SUBDIR

      public static final String DEFAULT_WORK_SUBDIR
      The default name of the work subdirectory containing the REPL's persistent state.
      See Also:
    • THREAD_PREFIX

      public static final String THREAD_PREFIX
      Threads of cau-repl have a name that starts with this prefix
      See Also:
    • HAVE_GPL

      public static boolean HAVE_GPL
      Does this build of cau-repl contain GPL licensed code?
    • HAVE_MYCORE

      public static boolean HAVE_MYCORE
      Are we running in a JVM whith MyCoRe?
    • HAVE_MYCORE_MODS

      public static boolean HAVE_MYCORE_MODS
      Are we running in a JVM with MyCoRe's MODS module?
  • Constructor Details

    • REPL

      public REPL(String listenAddr, Integer port, Integer timeoutSecs, File workDir, ClassLoader groovyClassLoader) throws IOException
      Creates the REPL. You should only have one instance of this per VM.
      Parameters:
      listenAddr - IP address that the SSH service will bind to (default 127.0.0.1)
      port - Port that the SSH service will bind to (default 8512)
      timeoutSecs - Terminate idle SSH connections after this many seconds (default 12h)
      workDir - The directory that will contain the REPL's perisistent state. It will be created if it does not exists. (default cau-repl in the cwd)
      groovyClassLoader - The ClassLoader to use for the REPL (defaults to a new private ClassLoader)
      Throws:
      IOException - A file could not be accessed.
  • Method Details

    • start

      public void start() throws IOException
      Start listening for incoming SSH connections.
      Throws:
      IOException - The server could not be started.
    • getListenAddr

      public String getListenAddr()
      Gets the IP that the SSH service will bind to.
      Returns:
      The IP that the SSH service will bind to.
    • getPort

      public int getPort()
      Gets the port that the SSH service will listen on.
      Returns:
      The port that the SSH service will listen on.
    • getTimeoutSecs

      public int getTimeoutSecs()
      Get the timeout for idle SSH connections.
      Returns:
      The timeout for idle SSH connections.
    • getAuthenticator

      public org.apache.sshd.server.auth.password.PasswordAuthenticator getAuthenticator()
      Gets the authenticator in use for the SSH session.
      Returns:
      The authenticator in use for the SSH session.
    • setAuthenticator

      public void setAuthenticator(org.apache.sshd.server.auth.password.PasswordAuthenticator authenticator)
      Sets a custom authenticator for the SSH service. Must be called before start().
      Parameters:
      authenticator - The authenticator to use
    • addStartupScript

      public void addStartupScript(String path)
      Add a startup script to be executed in the REPL each time a user has connected. Must be called before start().
      Parameters:
      path - Location of the script
    • getStartupScripts

      public List<String> getStartupScripts()
      Get the startup scripts that were configured for the REPL.
      Returns:
      The startup scripts that were configured for the REPL.
    • addInternalStartupScript

      public void addInternalStartupScript(String path)
      Add a startup script from our .jar to be executed in the REPL each time a user has connected. Must be called before start().
      Parameters:
      path - Location of the script inside our .jar
    • getStartupCommands

      public List<String> getStartupCommands()
      Get the startup commands that were configured for the REPL.
      Returns:
      The startup commands that were configured for the REPL.
    • addStartupCommand

      public void addStartupCommand(String cmd)
      Adds a command to be executed inside the REPL each time a user has connected. Must be called before start().
      Parameters:
      cmd - The command to execute.
    • getSessionListeners

      public List<org.apache.sshd.common.session.SessionListener> getSessionListeners()
      Gets the session listeners that were configured for the SSH service.
      Returns:
      The session listeners that were configured for the SSH service.
    • addSessionListener

      public void addSessionListener(org.apache.sshd.common.session.SessionListener sessionListener)
      Respond to SSH events by installing your own listener. Must be called before start().
      Parameters:
      sessionListener - The listener to add
    • getWorkDir

      public static File getWorkDir()
      Get the REPL's work directory
      Returns:
      the REPL's work directory
    • getGroovyClassLoader

      public static ClassLoader getGroovyClassLoader()
      Gets the ClassLoader that will be used for the REPL.
      Returns:
      The ClassLoader that will be used for the REPL.
    • setWorkDir

      public static void setWorkDir(File workDir) throws IOException
      Allows you to initialize the global work directory before creating a REPL instance. This might be neccessary when you precompile Groovy sources). You can only set this directory once.
      Parameters:
      workDir - The work directory to use
      Throws:
      IOException - The directory could not be accessed.
    • discoverEnvironment

      public static void discoverEnvironment(ClassLoader classLoader)
      Update the various HAVE_* fields.
      Parameters:
      classLoader - The ClassLoader to use as a reference
    • getVersionString

      public static String getVersionString()
      Generates a textual representation of cau-repl's version
      Returns:
      cau-repl's version string.