Package org.apache.felix.gogo.runtime
Class CommandSessionImpl
- java.lang.Object
-
- org.apache.felix.gogo.runtime.CommandSessionImpl
-
- All Implemented Interfaces:
java.lang.AutoCloseable,CommandSession,Converter
public class CommandSessionImpl extends java.lang.Object implements CommandSession, Converter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classCommandSessionImpl.JobImpl-
Nested classes/interfaces inherited from interface org.apache.felix.service.command.CommandSession
CommandSession.Utils
-
-
Field Summary
Fields Modifier and Type Field Description protected java.nio.channels.Channel[]channelsprivate java.lang.ClassLoaderclassLoaderprivate booleanclosedprivate static java.lang.StringCOLUMNstatic java.lang.StringCOMMANDSstatic java.lang.StringCONSTANTSprivate java.nio.file.PathcurrentDirprotected java.io.OutputStreamerrprivate java.util.concurrent.ExecutorServiceexecutorprotected java.io.InputStreaminprivate JobListenerjobListenerprivate java.util.List<CommandSessionImpl.JobImpl>jobsprotected java.io.OutputStreamoutprotected java.io.PrintStreamperrprotected java.io.PrintStreampoutprivate CommandProcessorImplprocessorstatic java.lang.StringSESSION_CLOSEDprotected java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object>variablesstatic java.lang.StringVARIABLES-
Fields inherited from interface org.apache.felix.service.command.CommandSession
OPTION_NO_GLOB
-
Fields inherited from interface org.apache.felix.service.command.Converter
CONVERTER_CLASSES, INSPECT, LINE, PART
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCommandSessionImpl(CommandProcessorImpl shell, java.io.InputStream in, java.io.OutputStream out, java.io.OutputStream err)protectedCommandSessionImpl(CommandProcessorImpl shell, CommandSessionImpl parent)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ClassLoaderclassLoader()voidclassLoader(java.lang.ClassLoader classLoader)voidclose()Close this command session.java.lang.Objectconvert(java.lang.Class<?> desiredType, java.lang.Object in)Convert an object to another type.CommandSessionImpl.JobImplcreateJob(java.lang.CharSequence command)java.nio.file.PathcurrentDir()voidcurrentDir(java.nio.file.Path path)static CommandSessionImpl.JobImplcurrentJob()java.lang.ObjectdoConvert(java.lang.Class<?> desiredType, java.lang.Object in)java.lang.Objectexecute(java.lang.CharSequence commandline)Execute a program in this session.java.lang.Objectexpr(java.lang.CharSequence expr)CommandSessionImpl.JobImplforegroundJob()Get the current foreground job or null.java.lang.CharSequenceformat(java.lang.Object result, int inspect)Convert an object to string form (CharSequence).java.lang.CharSequenceformat(java.lang.Object target, int level, Converter escape)Convert an objet to a CharSequence object in the requested format.java.lang.Objectget(java.lang.String name)Get the value of a variable.java.io.PrintStreamgetConsole()Return the PrintStream for the console.java.io.InputStreamgetKeyboard()Return the input stream that is the first of the pipeline.java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object>getVariables()(package private) java.lang.CharSequenceinspect(java.lang.Object b)java.lang.Objectinvoke(java.lang.Object target, java.lang.String name, java.util.List<java.lang.Object> args)java.util.List<Job>jobs()List jobs.CommandProcessorprocessor()java.lang.Objectput(java.lang.String name, java.lang.Object value)Set the value of a variable.java.nio.file.Pathredirect(java.nio.file.Path path, int mode)voidsetJobListener(JobListener listener)Set the job listener for this session.(package private) ThreadIOthreadIO()
-
-
-
Field Detail
-
SESSION_CLOSED
public static final java.lang.String SESSION_CLOSED
- See Also:
- Constant Field Values
-
VARIABLES
public static final java.lang.String VARIABLES
- See Also:
- Constant Field Values
-
COMMANDS
public static final java.lang.String COMMANDS
- See Also:
- Constant Field Values
-
CONSTANTS
public static final java.lang.String CONSTANTS
- See Also:
- Constant Field Values
-
COLUMN
private static final java.lang.String COLUMN
- See Also:
- Constant Field Values
-
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
-
processor
private final CommandProcessorImpl processor
-
variables
protected final java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> variables
-
closed
private volatile boolean closed
-
jobs
private final java.util.List<CommandSessionImpl.JobImpl> jobs
-
jobListener
private JobListener jobListener
-
executor
private final java.util.concurrent.ExecutorService executor
-
currentDir
private java.nio.file.Path currentDir
-
classLoader
private java.lang.ClassLoader classLoader
-
-
Constructor Detail
-
CommandSessionImpl
protected CommandSessionImpl(CommandProcessorImpl shell, CommandSessionImpl parent)
-
CommandSessionImpl
protected CommandSessionImpl(CommandProcessorImpl shell, java.io.InputStream in, java.io.OutputStream out, java.io.OutputStream err)
-
-
Method Detail
-
threadIO
ThreadIO threadIO()
-
processor
public CommandProcessor processor()
-
getVariables
public java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> getVariables()
-
currentDir
public java.nio.file.Path currentDir()
- Specified by:
currentDirin interfaceCommandSession
-
currentDir
public void currentDir(java.nio.file.Path path)
- Specified by:
currentDirin interfaceCommandSession
-
classLoader
public java.lang.ClassLoader classLoader()
- Specified by:
classLoaderin interfaceCommandSession
-
classLoader
public void classLoader(java.lang.ClassLoader classLoader)
- Specified by:
classLoaderin interfaceCommandSession
-
close
public void close()
Description copied from interface:CommandSessionClose this command session. After the session is closed, it will throw IllegalStateException when it is used.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceCommandSession
-
execute
public java.lang.Object execute(java.lang.CharSequence commandline) throws java.lang.ExceptionDescription copied from interface:CommandSessionExecute a program in this session.- Specified by:
executein interfaceCommandSession- Parameters:
commandline- the commandline- Returns:
- the result of the execution
- Throws:
java.lang.Exception- on exception
-
getKeyboard
public java.io.InputStream getKeyboard()
Description copied from interface:CommandSessionReturn 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:
getKeyboardin interfaceCommandSession- 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:CommandSessionGet the value of a variable.- Specified by:
getin interfaceCommandSession- Parameters:
name- the name- Returns:
- Object
-
put
public java.lang.Object put(java.lang.String name, java.lang.Object value)Description copied from interface:CommandSessionSet the value of a variable.- Specified by:
putin interfaceCommandSession- Parameters:
name- Name of the variable.value- Value of the variable- Returns:
- Object
-
getConsole
public java.io.PrintStream getConsole()
Description copied from interface:CommandSessionReturn 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:
getConsolein interfaceCommandSession- Returns:
- PrintStream the console print stream
-
format
public java.lang.CharSequence format(java.lang.Object target, int level, Converter escape) throws java.lang.ExceptionDescription copied from interface:ConverterConvert an objet to a CharSequence object in the requested format. The format can be INSPECT, LINE, or PART. Other values must throw IllegalArgumentException.
-
inspect
java.lang.CharSequence inspect(java.lang.Object b)
-
convert
public java.lang.Object convert(java.lang.Class<?> desiredType, java.lang.Object in)Description copied from interface:CommandSessionConvert an object to another type.- Specified by:
convertin interfaceCommandSession- Specified by:
convertin interfaceConverter- Parameters:
desiredType- the typein- the instance- Returns:
- Object
-
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:CommandSessionConvert 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:
formatin interfaceCommandSession- Parameters:
result- the targetinspect- the level- Returns:
- CharSequence
-
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:CommandSessionList jobs. Always return a non-null list.- Specified by:
jobsin interfaceCommandSession- Returns:
- List<Job>
-
currentJob
public static CommandSessionImpl.JobImpl currentJob()
-
foregroundJob
public CommandSessionImpl.JobImpl foregroundJob()
Description copied from interface:CommandSessionGet the current foreground job or null.- Specified by:
foregroundJobin interfaceCommandSession- Returns:
- Job
-
setJobListener
public void setJobListener(JobListener listener)
Description copied from interface:CommandSessionSet the job listener for this session.- Specified by:
setJobListenerin interfaceCommandSession- Parameters:
listener- the listener
-
createJob
public CommandSessionImpl.JobImpl createJob(java.lang.CharSequence command)
-
-