org.crsh.console
Class ProcessHandler

java.lang.Object
  extended by org.crsh.console.Plugin
      extended by org.crsh.console.ProcessHandler
All Implemented Interfaces:
Appendable, InteractionContext, ShellProcessContext, Screenable, ScreenContext

 class ProcessHandler
extends Plugin
implements ShellProcessContext

A process execution state machine.

Author:
Julien Viet

Nested Class Summary
(package private)  class ProcessHandler.Reader
          A thread reading a line.
 
Field Summary
(package private)  Console console
          .
(package private)  AtomicReference<ProcessHandler.Reader> editor
          Weather or not a thread is reading a line callback.
(package private)  ShellProcess process
          .
 
Constructor Summary
ProcessHandler(Console console, ShellProcess process)
           
 
Method Summary
 Screenable append(char c)
           
 Screenable append(CharSequence s)
           
 Screenable append(CharSequence csq, int start, int end)
           
 Screenable append(Style style)
           
 Screenable cls()
           
 void end(ShellResponse response)
          This method is invoked when the process ends.
 void flush()
          Flush the stream.
 int getHeight()
          Returns the screen height in chars.
 String getProperty(String propertyName)
          Returns a generic property, usually this property is resolved by the shell client.
 int getWidth()
          Returns the screen width in chars.
 String readLine(String msg, boolean echo)
          Display a message and read a line on the console, this method call can be blocking until the user provides a value.
 boolean releaseAlternateBuffer()
          Release control of the alternate buffer.
 boolean takeAlternateBuffer()
          Take control of the alternate buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

console

final Console console
.


process

final ShellProcess process
.


editor

final AtomicReference<ProcessHandler.Reader> editor
Weather or not a thread is reading a line callback.

Constructor Detail

ProcessHandler

ProcessHandler(Console console,
               ShellProcess process)
Method Detail

takeAlternateBuffer

public boolean takeAlternateBuffer()
                            throws IOException
Description copied from interface: InteractionContext
Take control of the alternate buffer. When the alternate buffer is already used nothing happens. The buffer switch should occur when then ScreenContext.flush() method is invoked.

Specified by:
takeAlternateBuffer in interface InteractionContext
Returns:
true if the alternate buffer is shown
Throws:
IOException

releaseAlternateBuffer

public boolean releaseAlternateBuffer()
                               throws IOException
Description copied from interface: InteractionContext
Release control of the alternate buffer. When the normal buffer is already used nothing happens. The buffer switch should occur when then ScreenContext.flush() method is invoked.

Specified by:
releaseAlternateBuffer in interface InteractionContext
Returns:
true if the usual buffer is shown
Throws:
IOException

getProperty

public String getProperty(String propertyName)
Description copied from interface: InteractionContext
Returns a generic property, usually this property is resolved by the shell client.

Specified by:
getProperty in interface InteractionContext
Parameters:
propertyName - the property name
Returns:
the property value

readLine

public String readLine(String msg,
                       boolean echo)
                throws IOException,
                       InterruptedException
Description copied from interface: InteractionContext
Display a message and read a line on the console, this method call can be blocking until the user provides a value. If no line can be read then null is returned.

Specified by:
readLine in interface InteractionContext
Parameters:
msg - the message to display before reading a line
echo - wether or not the line read should be echoed when typing
Returns:
the line read
Throws:
IOException - any io exception
InterruptedException - the thread was interrupted while waiting for the user value

getWidth

public int getWidth()
Description copied from interface: ScreenContext
Returns the screen width in chars. When the value is not positive it means the value could not be determined.

Specified by:
getWidth in interface ScreenContext
Returns:
the term width

getHeight

public int getHeight()
Description copied from interface: ScreenContext
Returns the screen height in chars. When the value is not positive it means the value could not be determined.

Specified by:
getHeight in interface ScreenContext
Returns:
the term height

append

public Screenable append(CharSequence s)
                  throws IOException
Specified by:
append in interface Appendable
Throws:
IOException

append

public Screenable append(char c)
                  throws IOException
Specified by:
append in interface Appendable
Throws:
IOException

append

public Screenable append(CharSequence csq,
                         int start,
                         int end)
                  throws IOException
Specified by:
append in interface Appendable
Throws:
IOException

append

public Screenable append(Style style)
                  throws IOException
Specified by:
append in interface Screenable
Throws:
IOException

cls

public Screenable cls()
               throws IOException
Specified by:
cls in interface Screenable
Throws:
IOException

flush

public void flush()
           throws IOException
Description copied from interface: ScreenContext
Flush the stream.

Specified by:
flush in interface ScreenContext
Throws:
IOException - any io exception

end

public void end(ShellResponse response)
Description copied from interface: ShellProcessContext
This method is invoked when the process ends.

Specified by:
end in interface ShellProcessContext
Parameters:
response - the shell response


Copyright © 2015 eXo Platform SAS. All Rights Reserved.