GrewpEdit.scm

Authors: Tim Hickey and Kenroy Granville License: LGPL, Website: http://groupscheme.sourceforge.net/ Purpose: GrewpEdit is a program which demonstrates the groupscheme library. It provides a mechanism for users to meet, chat, and jointly edit files. This document describes the implementation of the GrewpEdit tool. It provides pointers to the code and screenshots to help explain the system.

The NetworkPanel

Source Code:

The initial screen is the startpane. This asks the user to either start a new GREWP locally, or join a GREWP. A GREWP is specified by a triple: (host, port, session-name) and it provides a GroupServer service for the members of the GREWP.

Actions

The GrewpPanel

The GroupServer allows users to create/join echo-groups. Members of an echo-group can send messages (as Scheme terms) to the group, those messages are serialized and echoed back to all members of the group (self included).

Once the user joins a GREWP (possibly one they create locally) They see a window containing a single "grewp+chat" tabs

The Grewp tab shows all users connected to the GREWP, it shows all documents being editted by members of the GREWP, it also provides a standard chat window which allows the user to talk to the entire GREWP. It also has a button which allows the user to select a color that will be used to highlight all of his/her contributions The user can create a new shared document (by clicking on "new") or can join an editing session for another document (by selecting on the document and clicking "open"). In either case, a Document tab is added to the window.

The DocumentPanel

The Document tab has three components:

  1. A shared document
  2. A chat area for discussing the document
  3. A GREWP awareness list, that shows all users currently
connected to the editing session for this document

It also has a File menu with the standard New/Open/Save/Save-as/Close menuitems. When all members of a document stop editing it, the document is removed from the Grewp and is no longer accessible. Each user's chat contributions are highlighted in the user's color Likewise, their location in the file is noted by highlighting the area just before their position in their color. The Document tab also supports a KillRing where all deletions larger than size 1 are stored in a list. The user can cycle through the list looking at all deletions (and can cut/paste parts of any deletion back into the edit window). There is currently no "undo" button, but the KillRing partly fills that role.

Server Architecture

The GroupServer creates a SocketServer that listens to the specified port and spawns a new thread for each Socket that connects to it. If the Socket joins a group, by sending the initial strings join USERNAME GROUPNAME SESSIONNAME then the server will add the socket to a peergroup for the group and will broadcast every string it receives on the socket to all members of the group. When the socket is closed by the client it is removed from the peer group. Thus, the server has one thread and one socket for each user that joins.

Socket Architecture of clients

Each user initially joins the "grewp+chat" echo-group. This group provides a mechanism for users to communicate with each other, either through chatting or at the program level through sending messages and adding listeners to the grewp+chat group.

Each time a document is created, the server creates a new echo-group for the document (the name of the group is the name of the document) and all who want to edit the document will join the group. The server also creates a GroupTextAreaServer (GTAS) to serialize all of the client editing commands and transform them so there are no conflcts, after which is sends the modified commands to all members of the group.

Thus if there are D documents being edited, then there are D+1 groups (the grewp+chat is the additional group). If there are U GrewpEdit clients that have been started (and one of them was started as a server), then there will be U+1 user names and the total number of GroupClient connections will be

Thread Architecture:

Threads are used in a number of places.

The GroupClients each add two threads. These are obects that manage the connection to the GroupServer and are created for the grewp+chat as well as for each shared document that is joined. In the latter case, the filename is used as the group name. One thread listens for strings coming in on the socket and copies each full line read into a queue. The second thread, processes the full lines by converting them to Scheme terms and applying any listeners that the user has added.

Each GroupTextAreaServer (GTAS) creates a new GroupClient to communicate with all of the GroupTextAreaClients (GTACs). The filename is used as the name of the group. Currently, all GTAS are created on the GREWP server. An alternative would be to have each user create a GTAS on their machine when they create a new shared document, but in this case, if the originator of a GREWP should lose their connection, then noone else can continue editing the document.

The GroupTextAreaClients (GTACs) also add an additional thread. When the user inserts or deletes string from the shared editor the operations are not carried out immediately, but rather are queued and a separate thread then sends the operations to the GroupTextAreaServer (the GTAS, which runs on the GREWP host) The GTAS serializes the requests and transforms the operations so that they are consistent with each other. The transformed operations are then broadcast back to the group. The GTACs then carry out the transformed operations. Thus, the GTAC implements a "Full Duplex" model where there will be a small delay between typing a character and the character appearing on the screen. The higher the network latency, the longer the delay. In practice, the delay is minimal for a metropolitan network.

Thread Examples

The rules are as follows: These actions generate threads on the client and server as follows: Client Server Action Threads Threads 13 13 Start GrewpEdit 0 4 Create GREWP server 2 1 Connect to GREWP server 3 4 Create shared doc -3 -4 Last close of shared doc 3 1 Connect to shared doc -3 -1 Close shared doc 15+3D Client editing D documents 17+3C+U*(1+A) Server managing C documents and U users where A is the average number of documents each user is editing Explanations:

Message Structure

In this section we discuss the types of messages that are sent among the members of each group. There are two types of groups: the grewp+chat group that all members of the GREWP belong to, and the document groups that correspond to a single collaboratively edittable document.

grewp+edit messages

(rollcall) sent by client to registrar on server, who sends back user-update and file-update messages. The clients use these messages to update their GREWP awareness features
(user-update (U1 U2 ... Un)) sent by registrar on server
(file-update (U1 U2 ... Un)) sent by registrar on server
(groupchatpanel NAME CHAT-TEXT RGBCOLORLIST) sent by client NAME after having typed CHAT-TEXT into his/her chat area
(GROUPSERVER newuser ID NAME) sent when a new user connects to the GREWP
(GROUPSERVER userleft ID NAME NUMLEFT) sent when a user leave the GREWP
(create-GTAS ID FILENAME) sent to registrar when user wants to have a GTAS started on the server
(GTAS-created (IP PORT USERNAME) FILENAME) sent by registrar when GTAS has been started on the server
(chat-txt USERNAME TEXT) sent by all members of the GREWP when a new user requests the chat text with a 'chat-update message

document-group messages

(get-contents) sent by a new GTAC to GTAS, who sends back the 'contents message below
(contents TEXT HISTORYSIZE) sent by GTAS to GTACs The clients use these messages to update their GREWP awareness features
(user-update (U1 U2 ... Un)) sent by registrar on server
(file-update (U1 U2 ... Un)) sent by registrar on server
(groupchatpanel NAME CHAT-TEXT RGBCOLORLIST) sent by client NAME after having typed CHAT-TEXT into his/her chat area
(file-update (U1 U2 ... Un)) sent by registrar on server
(GROUPSERVER (newuser ID NAME)) sent by GroupServer when new user connects...
(GROUPSERVER userleft ID NAME NUMLEFT ) ...
(chat-txt ".......") sent by all users to a new user upon receipt of a 'chat-update message
(chat-update NAME) sent by a new user (with given name) as a request to get current chat-txt
(contents TEXT) sent by GTAS in response to a get-contents message from a new user
TEXT is inserted into the shared textarea
(delete OFFSET ID COLORRGBLIST STRING HISTORYSIZE ) sent by GTAC to GTAS when the user tries to delete some text from the shared textarea
(insert OFFSET ID COLORRGBLIST STRING HISTORYSIZE ) sent by GTAC to GTAS when the user tries to insert some text into the shared textarea
(groupchatchannel NAME TEXT COLORRGBLIST ) sent by GroupChat component when user submit a chat request
(logger delete OFFSET STRING LEN ID COLORRGBLIST HISTORYSIZE ) sent by GTAS to GTACs, it provides the official, possibly transformed, operation to be applied by all GTACs to the shared textarea
(reset-colors) sent by new user as a request for all users in the group to send their current highlight colors
(set-color ID COLORRGBLIST OFFSET ) sent by GTACs in response to a reset-color request. Gives the color and offset for the current user