|
|||||||||
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 String[] |
commandHistory
A list of the last few commands issued in this session. |
static String |
CURRENT_COMMAND
The key used to index the current command in system environments. |
static 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 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 Vector |
loginStack
The list of users that are currently logged into this session. |
protected Object |
myThreadID
The thread ID of this session. |
protected SystemPrintStream |
out
The output stream of the remote connection. |
protected Object[] |
paramsArray
Used as temporary storage when parsing the parameters for a command. |
protected Vector |
paramsVector
Used as temporary storage when parsing the parameters for a command. |
protected 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 String |
PROMPT
The basic prompt displayed at the command line. |
protected 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 String |
userName
The user that is currently logged in with this session. |
static 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(String str)
Adds a new command to the history buffer. |
void |
broadcast(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(Exception ex)
Notifies this session that exception was thrown when executing a command. |
protected void |
execute(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. |
Hashtable |
getEnvironment()
Gets a reference to the current environment. |
PrintStream |
getErrStream()
Gets the stream this session uses for error notification and critical messages. |
String |
getFromEnvironment(String key)
Gets the value of the key from the current environment. |
String |
getHistoryNumber(int number)
Gets the command at the given index of the command history. |
String |
getNextCommand()
Gets the next command from this session's input stream. |
PrintStream |
getOutputStream()
Gets the stream this session uses for output. |
static Object[] |
getParams(String str)
Parses the command line into individual elements. |
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(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. |
String |
stepDownHistory()
Moves the current position in the history buffer down one and returns the command at that position. |
String |
stepUpHistory()
Moves the current position in the history buffer up one and returns the command at that position. |
boolean |
su(String userName,
String password)
Allows the current user to login as another user. |
void |
updatePrompt(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 Hashtable environment
protected boolean shutdown
protected String[] commandHistory
protected int lastCommand
protected int currentCommand
protected byte[] prompt
protected Server server
protected String userName
protected String password
protected Vector loginStack
protected Object myThreadID
protected Vector paramsVector
protected Object[] paramsArray
protected Object[] retArray
public static String CURRENT_DIRECTORY
public static String CURRENT_COMMAND
public static String PROMPT
public static 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 String getUserName()
protected abstract void login() throws 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(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 PrintStream getErrStream()
public PrintStream getOutputStream()
public final void forceEndSession()
public final void endSession()
public boolean su(String userName, 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(Exception ex)
ex
- the exception thrownpublic static Object[] getParams(String str)
str
- complete command lineString
command in the first element, and a String[]
of
the arguments to that command in the second elementpublic String getNextCommand() throws IOException
public Hashtable getEnvironment()
Hashtable
public String getFromEnvironment(String key)
key
- name of desired environment variablenull
if that key does not exist in the environmentpublic void addToHistory(String str)
str
- command to add to the historypublic String stepUpHistory()
public String stepDownHistory()
public String getHistoryNumber(int number)
number
- index into the history cache.public void printHistory(PrintStream out)
out
- stream used to print the historypublic boolean inCommand()
true
if the session is executing a shell commandpublic void updatePrompt(String withThis)
withThis
- the new directory namepublic void broadcast(String sendThis)
sendThis
- message to displayprotected void parseLogin()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |