Class CommandSessionImpl

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.nio.channels.Channel[] channels  
      static java.lang.String COMMANDS  
      static java.lang.String CONSTANTS  
      protected java.io.OutputStream err  
      protected java.io.InputStream in  
      protected java.io.OutputStream out  
      protected java.io.PrintStream perr  
      protected java.io.PrintStream pout  
      static java.lang.String SESSION_CLOSED  
      protected java.util.concurrent.ConcurrentMap<java.lang.String,​java.lang.Object> variables  
      static java.lang.String VARIABLES  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.ClassLoader classLoader()  
      void classLoader​(java.lang.ClassLoader classLoader)  
      void close()
      Close this command session.
      java.lang.Object convert​(java.lang.Class<?> desiredType, java.lang.Object in)
      Convert an object to another type.
      org.apache.felix.gogo.runtime.CommandSessionImpl.JobImpl createJob​(java.lang.CharSequence command)  
      java.nio.file.Path currentDir()  
      void currentDir​(java.nio.file.Path path)  
      static org.apache.felix.gogo.runtime.CommandSessionImpl.JobImpl currentJob()  
      java.lang.Object doConvert​(java.lang.Class<?> desiredType, java.lang.Object in)  
      java.lang.Object execute​(java.lang.CharSequence commandline)
      Execute a program in this session.
      java.lang.Object expr​(java.lang.CharSequence expr)  
      org.apache.felix.gogo.runtime.CommandSessionImpl.JobImpl foregroundJob()
      Get the current foreground job or null.
      java.lang.CharSequence format​(java.lang.Object result, int inspect)
      Convert an object to string form (CharSequence).
      java.lang.CharSequence format​(java.lang.Object target, int level, Converter escape)
      Convert an objet to a CharSequence object in the requested format.
      java.lang.Object get​(java.lang.String name)
      Get the value of a variable.
      java.io.PrintStream getConsole()
      Return the PrintStream for the console.
      java.io.InputStream getKeyboard()
      Return the input stream that is the first of the pipeline.
      java.util.concurrent.ConcurrentMap<java.lang.String,​java.lang.Object> getVariables()  
      java.lang.Object invoke​(java.lang.Object target, java.lang.String name, java.util.List<java.lang.Object> args)  
      java.util.List<Job> jobs()
      List jobs.
      CommandProcessor processor()  
      java.lang.Object put​(java.lang.String name, java.lang.Object value)
      Set the value of a variable.
      java.nio.file.Path redirect​(java.nio.file.Path path, int mode)  
      void setJobListener​(JobListener listener)
      Set the job listener for this session.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • in

        protected java.io.InputStream in
      • out

        protected java.io.OutputStream out
      • pout

        protected java.io.PrintStream pout
      • err

        protected java.io.OutputStream err
      • perr

        protected java.io.PrintStream perr
      • channels

        protected java.nio.channels.Channel[] channels
      • variables

        protected final java.util.concurrent.ConcurrentMap<java.lang.String,​java.lang.Object> variables
    • Method Detail

      • getVariables

        public java.util.concurrent.ConcurrentMap<java.lang.String,​java.lang.Object> getVariables()
      • currentDir

        public void currentDir​(java.nio.file.Path path)
        Specified by:
        currentDir in interface CommandSession
      • classLoader

        public void classLoader​(java.lang.ClassLoader classLoader)
        Specified by:
        classLoader in interface CommandSession
      • close

        public void close()
        Description copied from interface: CommandSession
        Close this command session. After the session is closed, it will throw IllegalStateException when it is used.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface CommandSession
      • execute

        public java.lang.Object execute​(java.lang.CharSequence commandline)
                                 throws java.lang.Exception
        Description copied from interface: CommandSession
        Execute a program in this session.
        Specified by:
        execute in interface CommandSession
        Returns:
        the result of the execution
        Throws:
        java.lang.Exception
      • getKeyboard

        public java.io.InputStream getKeyboard()
        Description copied from interface: CommandSession
        Return the input stream that is the first of the pipeline. This stream is sometimes necessary to communicate directly to the end user. For example, a "less" or "more" command needs direct input from the keyboard to control the paging.
        Specified by:
        getKeyboard in interface CommandSession
        Returns:
        InpuStream used closest to the user or null if input is from a file.
      • get

        public java.lang.Object get​(java.lang.String name)
        Description copied from interface: CommandSession
        Get the value of a variable.
        Specified by:
        get in interface CommandSession
        Returns:
      • put

        public java.lang.Object put​(java.lang.String name,
                                    java.lang.Object value)
        Description copied from interface: CommandSession
        Set the value of a variable.
        Specified by:
        put in interface CommandSession
        Parameters:
        name - Name of the variable.
        value - Value of the variable
      • getConsole

        public java.io.PrintStream getConsole()
        Description copied from interface: CommandSession
        Return the PrintStream for the console. This must always be the stream "closest" to the user. This stream can be used to post messages that bypass the piping. If the output is piped to a file, then the object returned must be null.
        Specified by:
        getConsole in interface CommandSession
        Returns:
      • format

        public java.lang.CharSequence format​(java.lang.Object target,
                                             int level,
                                             Converter escape)
                                      throws java.lang.Exception
        Description copied from interface: Converter
        Convert an objet to a CharSequence object in the requested format. The format can be INSPECT, LINE, or PART. Other values must throw IllegalArgumentException.
        Specified by:
        format in interface Converter
        Parameters:
        target - The object to be converted to a String
        level - One of INSPECT, LINE, or PART.
        escape - Use this object to format sub ordinate objects.
        Returns:
        A printed object of potentially multiple lines
        Throws:
        java.lang.Exception
      • convert

        public java.lang.Object convert​(java.lang.Class<?> desiredType,
                                        java.lang.Object in)
        Description copied from interface: CommandSession
        Convert an object to another type.
        Specified by:
        convert in interface CommandSession
        Specified by:
        convert in interface Converter
        Parameters:
        desiredType - The type that the returned object can be assigned to
        in - The object that must be converted
        Returns:
        An object that can be assigned to the desired type or null.
      • doConvert

        public java.lang.Object doConvert​(java.lang.Class<?> desiredType,
                                          java.lang.Object in)
      • format

        public java.lang.CharSequence format​(java.lang.Object result,
                                             int inspect)
        Description copied from interface: CommandSession
        Convert an object to string form (CharSequence). The level is defined in the Converter interface, it can be one of INSPECT, LINE, PART. This function always returns a non null value. As a last resort, toString is called on the Object.
        Specified by:
        format in interface CommandSession
        Returns:
      • expr

        public java.lang.Object expr​(java.lang.CharSequence expr)
      • invoke

        public java.lang.Object invoke​(java.lang.Object target,
                                       java.lang.String name,
                                       java.util.List<java.lang.Object> args)
                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • redirect

        public java.nio.file.Path redirect​(java.nio.file.Path path,
                                           int mode)
      • jobs

        public java.util.List<Job> jobs()
        Description copied from interface: CommandSession
        List jobs. Always return a non-null list.
        Specified by:
        jobs in interface CommandSession
      • currentJob

        public static org.apache.felix.gogo.runtime.CommandSessionImpl.JobImpl currentJob()
      • foregroundJob

        public org.apache.felix.gogo.runtime.CommandSessionImpl.JobImpl foregroundJob()
        Description copied from interface: CommandSession
        Get the current foreground job or null.
        Specified by:
        foregroundJob in interface CommandSession
      • createJob

        public org.apache.felix.gogo.runtime.CommandSessionImpl.JobImpl createJob​(java.lang.CharSequence command)