|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object SK.gnome.dwarf.GenericService SK.gnome.dwarf.GenericServer SK.gnome.dwarf.thread.ThreadServer SK.gnome.dwarf.main.Console
This class provides management console.
The console is a human interface through which the end-user can invoke arbitrary
commands to manage the application services. Custom commands can be created by the developer
and plugged-in to the application. All such commands must extend the abstract Command
class and may be added to any Server
implementation.
Commands contained by the Console
service itself are globally accessible, while
those plugged-in to the other servers are accessible only by choosing the particular server
as the current working service. See the CSCmd
class for
more information.
The user commands are passed in to the execute(Subject, String, Writer)
method,
which maps them to the corresponding command services, found in the application.
This class implements one concrete way how to obtain a command string from the end-user -
an interactive command prompt, which can be enabled or disabled via the setPrompt(boolean)
method. Other ways can be freely developed and used, too.
Field Summary | |
protected boolean |
prompt
Whether to enable the interactive command prompt. |
protected int |
timeout
The command prompt inactivity timeout in seconds. |
Fields inherited from class SK.gnome.dwarf.thread.ThreadServer |
daemon, thread |
Fields inherited from class SK.gnome.dwarf.GenericService |
initParameters, parent |
Fields inherited from interface SK.gnome.dwarf.Service |
INITIALIZED, LOG_DEBUG, LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_TRACE, LOG_WARN, LOG_XFER, SHUTDOWN, STARTED, STOPPED |
Constructor Summary | |
Console(java.lang.String name)
Creates a new Console. |
Method Summary | |
protected boolean |
enableThread()
Enables or disables the service thread. |
void |
execute(javax.security.auth.Subject subject,
java.lang.String command,
java.io.Writer out)
Executes the particular console command. |
Service |
getServiceByPath(javax.security.auth.Subject subject,
java.lang.String path)
Returns the target service according to the given path and subject. |
Service |
getWorkingService(javax.security.auth.Subject subject)
Returns the current working service of the given subject. |
void |
changeWorkingService(javax.security.auth.Subject subject,
java.lang.String path)
Changes the current working service of the given subject. |
void |
init(Server parent)
Initializes the service. |
protected void |
loop()
Handles the command prompt input. |
static java.lang.String[] |
parseCommandString(java.lang.String cmd)
Parses the command string. |
void |
setPrompt(boolean enable)
Enables or disables the interactive command prompt. |
void |
setTimeout(int timeout)
Sets the command prompt inactivity timeout. |
void |
start()
Starts the service. |
Methods inherited from class SK.gnome.dwarf.thread.ThreadServer |
finish, run, setDaemon, shutdown, stop |
Methods inherited from class SK.gnome.dwarf.GenericServer |
addService, addService, getAuthenticator, getLogger, getParameters, getService, getServices, getServices, removeService, report |
Methods inherited from class SK.gnome.dwarf.GenericService |
getAuthFacility, getFullName, getInitParameter, getInitParameterNames, getLogFacility, getName, getPrincipal, getShutdownTimeout, getState, log, log, login, logout, setAuthFacility, setInitParameters, setLogFacility, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface SK.gnome.dwarf.Service |
getFullName, getName, getState, log, log, login, logout |
Field Detail |
protected boolean prompt
Default value: true
protected int timeout
Zero means that the command prompt will wait for the user input indefinitelly.
Default value: Constants.DEFAULT_CONSOLE_TIMEOUT
Constructor Detail |
public Console(java.lang.String name)
Method Detail |
public void setPrompt(boolean enable)
enable
- true if the command prompt should be enabledpublic void setTimeout(int timeout)
The command prompt will be deactivated and the console logging will be resumed automatically after the specified time of user inactivity. The command prompt may be activated again by pressing the Enter key.
Zero value means that the command prompt will wait for the user input indefinitelly.
timeout
- the timeout in secondspublic void init(Server parent) throws ServiceException
It throws an IllegalServiceClassException
if the parent server is not
an instance of the MainServer
class. If the command prompt is enabled,
it initializes and starts a new thread for reading user commands from the standard
System.in stream.
init
in interface Service
init
in class GenericServer
ServiceException
public void start() throws ServiceException
ThreadServer
If the ThreadServer.enableThread()
method returns true, it creates and starts a new
thread. The thread's name corresponds to the service name and the thread's Runnable
target is the service itself since the this class implements the Runnable interface.
The reference to the thread object is stored in the ThreadServer.thread
field.
It throws an IllegalStateException if the ThreadServer.thread
field is not null and
its isAlive() method returns true.
start
in interface Service
start
in class ThreadServer
ServiceException
public void execute(javax.security.auth.Subject subject, java.lang.String command, java.io.Writer out)
It parses the command string provided in the command argument. The actual parsing
is performed in the parseCommandString(String)
static method. The first array element
returned by the parsing method is the name of the command. The command name must be the same
as the name of the Command
service, plugged-in to the application. The rest of the
array elements are the command arguments. The particular command instance is obtained either
from the Console
itself, or from the current working service, associated with the given
subject. Then the command's Command.execute(Subject, Service, String[], Writer)
method is invoked and the command output is redirected to the out stream.
If a security manager is installed, the ServicePermission "executeCommand.cmd_name" is checked first in the context of the subject argument. The subject should represent an indentity of the user executing the command, therefore particular commands can be enabled or disabled for particular users by granting the appropriate subject-based permissions to them. In the case of invoking this method from a HTTP servlet, for example, the subject should represent a currently authenticated remote user.
Thread-safety note: This method implementation is not synchronized therefore the
particular command's Command.execute(Subject, Service, String[], Writer)
method must
be thread-safe it will be accessed simultaneously.
subject
- the subject executing the commandcommand
- the command stringout
- the output streampublic Service getWorkingService(javax.security.auth.Subject subject)
public void changeWorkingService(javax.security.auth.Subject subject, java.lang.String path) throws CommandException
subject
- the subjectpath
- the path to the service
CommandException
public Service getServiceByPath(javax.security.auth.Subject subject, java.lang.String path)
The target service is searched relative to the subject's current working directory. The "." and ".." strings may be used in the path argument to reference the current and the parent directory. The "/" path separator must be used to separate the names of the nested services in the path.
subject
- the subjectpath
- the path string
public static java.lang.String[] parseCommandString(java.lang.String cmd)
The command string is a set of string elements, separated by the white space characters. If a command element must contain white space characters, it must be surrounded by double quotes. The first element is the name of the command, the rest is regarded as the command arguments.
cmd
- the command string
protected boolean enableThread()
Returns true if the command prompt is enabled.
enableThread
in class ThreadServer
protected void loop()
If the command prompt is enabled, it reads the user input from the command prompt
(i.e. from the System.in stream), parses the command line and executes the command
provided by the user via the execute(Subject, String, Writer)
method.
The command prompt is activated by pressing the Enter key in the system console. If the command prompt is active, logging to the system console is suspended to prevent mixing the command output with the log messages generated by the application. By typing exit the command prompt is deactivated and console logging is resumed.
The subject passed in to the execute(Subject, String, Writer)
method contains
a ServicePrincipal
object representing the console service itself and an instance
of the UserPrincipal
with the name of the local user executing the application.
loop
in class ThreadServer
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |