|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--com.dalsemi.shell.server.Session
A session represents a single connection to the TINI system shell. When someone attempts to login, a server object spins off a session (an implementation of this class) to handle the communication. The session allows you to log into the system, then processes all system requests. Sessions are designed to be multi-threaded, allowing multiple simultaneous connections.
Inner Class Summary | |
protected class |
Session.Login
Encapsulates all of the information needed to log a user into the system. |
Field Summary | |
protected java.lang.String[] |
commandHistory
A list of the last few commands issued in this session. |
static java.lang.String |
CURRENT_COMMAND
The key used to index the current command in system environments. |
static java.lang.String |
CURRENT_DIRECTORY
The key used to index the current directory in system environments. |
protected int |
currentCommand
Marks the beginning of the commandHistory buffer. |
protected java.util.Hashtable |
environment
The environment associated with this session. |
protected SystemPrintStream |
err
The error stream of the remote connection. |
protected SystemInputStream |
in
The input stream of the remote connection. |
protected boolean |
inCommand
Specifies that a command is currently being processed by this session. |
protected int |
lastCommand
Marks the end of the commandHistory buffer. |
protected java.util.Vector |
loginStack
The list of users that are currently logged into this session. |
protected java.lang.Object |
myThreadID
The thread ID of this session. |
protected SystemPrintStream |
out
The output stream of the remote connection. |
protected java.lang.Object[] |
paramsArray
Used as temporary storage when parsing the parameters for a command. |
protected java.util.Vector |
paramsVector
Used as temporary storage when parsing the parameters for a command. |
protected java.lang.String |
password
The password for the user that is currently logged in. |
protected byte[] |
prompt
The text used as the command line prompt for this session. |
static java.lang.String |
PROMPT
The basic prompt displayed at the command line. |
protected java.lang.Object[] |
retArray
Used as temporary storage when parsing the parameters for a command. |
protected Server |
server
The server that created this session. |
protected boolean |
shutdown
Specifies that the session should attempt to close the connection after it has finished processing the current request. |
protected java.lang.String |
userName
The user that is currently logged in with this session. |
static java.lang.String |
welcomeMessage
The message shown to all users when they login to this session. |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY,
MIN_PRIORITY,
NORM_PRIORITY |
Constructor Summary | |
protected |
Session(SystemInputStream in,
SystemPrintStream out,
SystemPrintStream err,
Server server)
Intializes the session. |
Method Summary | |
void |
addToHistory(java.lang.String str)
Adds a new command to the history buffer. |
void |
broadcast(java.lang.String sendThis)
Displays a message in this session. |
protected abstract void |
currentCommandFinished()
Notifies this session that the current command has completed. |
void |
endSession()
Cleans up the resources used by this session. |
protected abstract void |
exceptionThrown(java.lang.Exception ex)
Notifies this session that exception was thrown when executing a command. |
protected void |
execute(java.lang.String commandStr)
Executes the given command in the current shell. |
void |
forceEndSession()
Notifies the server this session is ending and forces the session to terminate. |
java.util.Hashtable |
getEnvironment()
Gets a reference to the current environment. |
java.io.PrintStream |
getErrStream()
Gets the stream this session uses for error notification and critical messages. |
java.lang.String |
getFromEnvironment(java.lang.String key)
Gets the value of the key from the current environment. |
java.lang.String |
getHistoryNumber(int number)
Gets the command at the given index of the command history. |
java.lang.String |
getNextCommand()
Gets the next command from this session's input stream. |
java.io.PrintStream |
getOutputStream()
Gets the stream this session uses for output. |
static java.lang.Object[] |
getParams(java.lang.String str)
Parses the command line into individual elements. |
java.lang.String |
getUserName()
Returns the user name associated with this session. |
boolean |
inCommand()
Indicates whether this session is executing a shell command. |
protected abstract void |
login()
Logs a user into the system. |
protected void |
parseLogin()
Parses and executes the ".login" file for the current user. |
void |
printHistory(java.io.PrintStream out)
Prints the list of commands stored in the history buffer of this session. |
void |
run()
Starts the communication loop of the session. |
protected abstract void |
sessionEnding()
Cleans up any resources associated with this session when it terminates. |
java.lang.String |
stepDownHistory()
Moves the current position in the history buffer down one and returns the command at that position. |
java.lang.String |
stepUpHistory()
Moves the current position in the history buffer up one and returns the command at that position. |
boolean |
su(java.lang.String userName,
java.lang.String password)
Allows the current user to login as another user. |
void |
updatePrompt(java.lang.String withThis)
Notifies this session of a directory change. |
Methods inherited from class java.lang.Thread |
activeCount,
checkAccess,
countStackFrames,
currentThread,
destroy,
dumpStack,
enumerate,
getName,
getPriority,
getThreadGroup,
interrupt,
interrupted,
isAlive,
isDaemon,
isInterrupted,
join,
join,
join,
resume,
setDaemon,
setName,
setPriority,
sleep,
sleep,
start,
stop,
stop,
suspend,
toString,
yield |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
protected SystemInputStream in
protected SystemPrintStream out
protected SystemPrintStream err
protected boolean inCommand
protected java.util.Hashtable environment
protected boolean shutdown
protected java.lang.String[] commandHistory
protected int lastCommand
protected int currentCommand
protected byte[] prompt
protected Server server
protected java.lang.String userName
protected java.lang.String password
protected java.util.Vector loginStack
protected java.lang.Object myThreadID
protected java.util.Vector paramsVector
protected java.lang.Object[] paramsArray
protected java.lang.Object[] retArray
public static java.lang.String CURRENT_DIRECTORY
public static java.lang.String CURRENT_COMMAND
public static java.lang.String PROMPT
public static java.lang.String welcomeMessage
Constructor Detail |
protected Session(SystemInputStream in, SystemPrintStream out, SystemPrintStream err, Server server)
in
- stream this session should use to get data from userout
- stream this session should use to output to usererr
- stream this session should use to output errors to userserver
- the server in charge of this sessionMethod Detail |
public java.lang.String getUserName()
protected abstract void login() throws java.io.IOException
public final void run()
login()
method
is called. If the user is sucessfully logged into the system, commands are accepted
and processed until the session is terminated.protected void execute(java.lang.String commandStr)
commandStr
parameter can contain any number of elements. These elements will be separated
into String[]
for the command interpreter.commandStr
- full command line to executepublic java.io.PrintStream getErrStream()
public java.io.PrintStream getOutputStream()
public final void forceEndSession()
public final void endSession()
public boolean su(java.lang.String userName, java.lang.String password)
userName
- new user's namepassword
- new user's passwordtrue
if login was successful, false
otherwiseprotected abstract void currentCommandFinished()
protected abstract void sessionEnding()
protected abstract void exceptionThrown(java.lang.Exception ex)
ex
- the exception thrownpublic static java.lang.Object[] getParams(java.lang.String str)
str
- complete command lineString
command in the first element, and a String[]
of
the arguments to that command in the second elementpublic java.lang.String getNextCommand() throws java.io.IOException
public java.util.Hashtable getEnvironment()
Hashtable
public java.lang.String getFromEnvironment(java.lang.String key)
key
- name of desired environment variablenull
if that key does not exist in the environmentpublic void addToHistory(java.lang.String str)
str
- command to add to the historypublic java.lang.String stepUpHistory()
public java.lang.String stepDownHistory()
public java.lang.String getHistoryNumber(int number)
number
- index into the history cache.public void printHistory(java.io.PrintStream out)
out
- stream used to print the historypublic boolean inCommand()
true
if the session is executing a shell commandpublic void updatePrompt(java.lang.String withThis)
withThis
- the new directory namepublic void broadcast(java.lang.String sendThis)
sendThis
- message to displayprotected void parseLogin()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |