org.hprog.code
Class CodeSession

java.lang.Object
  |
  +--org.hprog.code.CodeSession

public class CodeSession
extends java.lang.Object

Shared sessions


Field Summary
 java.lang.String desc
          Description of this session
 java.lang.String lang
          Language used in this session
 
Method Summary
 boolean addUser(java.lang.String handle, CodeProtocol prot)
          Add a user/connection pair to this session
 void close()
          Delete this session, closing all connections associated with it
 boolean createFile(java.lang.String handle, java.lang.String fname)
          Request the creation of a new file, with an access check
 void eval(java.lang.String exp)
          Evaluate an expression in the interpreter.
static CodeSession get(java.lang.String name, java.lang.String lang, java.lang.String desc)
          Get a session by name
 java.lang.String getEditor()
          Get the current editor's handle
 java.util.Map getFiles()
          Get map from shared filenames to their String contents
 CodeProtocol getUser(java.lang.String handle)
          Get the connection associated with a user
 java.util.Map getUsers()
          Get map from user handles to their connections
 boolean hasEditor()
          Is there currently an editor in this session?
 boolean insertText(java.lang.String handle, java.lang.String fname, int pos, java.lang.String text)
          Request insertion of text into a shared source file
 void interrupt()
          Interrupt current interpreter execution
 boolean isAdmin(java.lang.String handle)
          Check if a user is an operator
 boolean isEditor(java.lang.String handle)
          Is a user the editor or an operator?
 void load()
          Load all source files into the interpreter
 boolean makeAdmin(java.lang.String handle, java.lang.String name)
          Try to make a user an operator, with an access check
 boolean makeEditor(java.lang.String handle, java.lang.String name)
          Try to make a user the editor, with an access check
 boolean removeText(java.lang.String handle, java.lang.String fname, int pos, int len)
          Request deletion of text from a shared source file
 void removeUser(java.lang.String handle)
          Remove a user from the session
 void sendByte(byte b)
          Send a byte to every client for this session
 void sendChat(java.lang.String s)
          Send a line of chat to all clients
 boolean sendInterpIn(java.lang.String handle, java.lang.String s)
          Send a notification of a running query to all clients but the editor's
 void sendInterpOut(java.lang.String s)
          Send shared interpreter output to all clients
 void sendLoading()
          Notify all clients that source files are being loaded in the shared interpreter
 void setAdmin(java.lang.String editor)
          Make a user an operator
 boolean setCaret(java.lang.String handle, java.lang.String fname, int pos, int len)
          Request a change in a shared source file's caret position
 void setEditor(java.lang.String editor)
          Make a user the editor
 java.util.Iterator userIterator()
          Get an iterator for the set of user/CodeProtocol key/value pairs in this session
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lang

public java.lang.String lang
Language used in this session


desc

public java.lang.String desc
Description of this session

Method Detail

userIterator

public java.util.Iterator userIterator()
Get an iterator for the set of user/CodeProtocol key/value pairs in this session


get

public static CodeSession get(java.lang.String name,
                              java.lang.String lang,
                              java.lang.String desc)
Get a session by name

Parameters:
name - session name
lang - language code (only used if the session must be created)
desc - session description (only used if the session must be created)
Returns:
the requested session

close

public void close()
Delete this session, closing all connections associated with it


addUser

public boolean addUser(java.lang.String handle,
                       CodeProtocol prot)
Add a user/connection pair to this session

Parameters:
handle - handle of user to add
prot - his connection
Returns:
whether the user was added successfully

removeUser

public void removeUser(java.lang.String handle)
Remove a user from the session

Parameters:
handle - handle of user to remove

getUsers

public java.util.Map getUsers()
Get map from user handles to their connections


getFiles

public java.util.Map getFiles()
Get map from shared filenames to their String contents


getUser

public CodeProtocol getUser(java.lang.String handle)
Get the connection associated with a user

Parameters:
handle - handle of target user
Returns:
the associated connection, or null if the handle is not found

sendByte

public void sendByte(byte b)
Send a byte to every client for this session

Parameters:
b - byte to send

sendChat

public void sendChat(java.lang.String s)
Send a line of chat to all clients

Parameters:
s - text to send

sendLoading

public void sendLoading()
Notify all clients that source files are being loaded in the shared interpreter


sendInterpIn

public boolean sendInterpIn(java.lang.String handle,
                            java.lang.String s)
Send a notification of a running query to all clients but the editor's

Parameters:
handle - handle of user that sent the query
s - query he sent
Returns:
whether or not the send suceeded. Will fail if handle is not editor.

sendInterpOut

public void sendInterpOut(java.lang.String s)
Send shared interpreter output to all clients

Parameters:
s - output text

setAdmin

public void setAdmin(java.lang.String editor)
Make a user an operator

Parameters:
editor - handle of user to make operator

setEditor

public void setEditor(java.lang.String editor)
Make a user the editor

Parameters:
editor - handle of user to make editor

makeEditor

public boolean makeEditor(java.lang.String handle,
                          java.lang.String name)
Try to make a user the editor, with an access check

Parameters:
handle - handle of user requesting to make another user editor
name - handle of requested new editor
Returns:
whether the request was granted

makeAdmin

public boolean makeAdmin(java.lang.String handle,
                         java.lang.String name)
Try to make a user an operator, with an access check

Parameters:
handle - handle of user requesting to make another user operator
name - handle of requested new operator
Returns:
whether the request was granted

isAdmin

public boolean isAdmin(java.lang.String handle)
Check if a user is an operator

Parameters:
handle - user to check
Returns:
whether the user is an operator

getEditor

public java.lang.String getEditor()
Get the current editor's handle


hasEditor

public boolean hasEditor()
Is there currently an editor in this session?


isEditor

public boolean isEditor(java.lang.String handle)
Is a user the editor or an operator?


createFile

public boolean createFile(java.lang.String handle,
                          java.lang.String fname)
Request the creation of a new file, with an access check

Parameters:
handle - handle of user requesting the creation
fname - name of new file
Returns:
whether the request was granted

insertText

public boolean insertText(java.lang.String handle,
                          java.lang.String fname,
                          int pos,
                          java.lang.String text)
Request insertion of text into a shared source file

Parameters:
handle - handle of requesting user
fname - name of file
pos - index of position in file into which to insert
text - text to insert
Returns:
whether the request was granted

removeText

public boolean removeText(java.lang.String handle,
                          java.lang.String fname,
                          int pos,
                          int len)
Request deletion of text from a shared source file

Parameters:
handle - handle of requesting user
fname - file name
pos - beginning of region in file to delete
len - number of characters to delete
Returns:
whether the request was granted

setCaret

public boolean setCaret(java.lang.String handle,
                        java.lang.String fname,
                        int pos,
                        int len)
Request a change in a shared source file's caret position

Parameters:
handle - handle of user requesting change
fname - name of file
pos - beginning of selection area
len - length of selection area

eval

public void eval(java.lang.String exp)
Evaluate an expression in the interpreter. Interpreter output will be sent to all clients when execution completes.

Parameters:
exp - expression to evaluate

interrupt

public void interrupt()
Interrupt current interpreter execution


load

public void load()
Load all source files into the interpreter