Examples of SessionTracker


Examples of com.mozilla.bespin.SessionTracker

        java.io.File templateDir = new java.io.File(template);

        FileSystem filesys = new FileSystem(baseDir, templateDir);
        getCtx().getServletContext().setAttribute(KEY_FILESYSTEM, filesys);

        SessionTracker sessions = new SessionTracker();
        getCtx().getServletContext().setAttribute(KEY_SESSION_TRACKER, sessions);
    }
View Full Code Here

Examples of com.mozilla.bespin.SessionTracker

        SessionTracker sessions = new SessionTracker();
        getCtx().getServletContext().setAttribute(KEY_SESSION_TRACKER, sessions);
    }

    protected synchronized SessionTracker getSessionTracker() throws IOException {
        SessionTracker sessions = (SessionTracker) getCtx().getServletContext().getAttribute(KEY_SESSION_TRACKER);
        if (sessions == null) {
            createFileSystemAndSessionTracker();
            sessions = (SessionTracker) getCtx().getServletContext().getAttribute(KEY_SESSION_TRACKER);
        }
        return sessions;
View Full Code Here

Examples of com.mozilla.bespin.SessionTracker

    public void get() throws IOException {
        getCtx().popParam(); // get rid of the /at/
        java.io.File requestedFile = getFilesystem().getFileHandle(getUser(), getPath());
        EditMode editMode = EditMode.ReadWrite;

        SessionTracker tracker = getSessionTracker();

        synchronized (tracker) {
            List<EditSession> editSessions = tracker.getSessions(requestedFile);

            // cover our error conditions
            if (editMode == EditMode.ReadWrite) {
                // check for other editors
                for (EditSession session : editSessions) {
                    if (!session.getUser().equals(getUser())) {
                        if (session.getEditMode() == EditMode.ReadWrite) {
                            getCtx().getResp().sendError(409, "User \"" + session.getUser().username + "\" is already editing the requested file");
                            return;
                        }
                    }
                }
            } else if (editMode == EditMode.Read) {
                // check for an existing read/write session from this user
                for (EditSession session : editSessions) {
                    if (session.getUser().equals(getUser())) {
                        getCtx().getResp().sendError(400, "File already opened by this user in read/write mode; cannot open in read-only mode");
                        return;
                    }
                }
            }

            boolean openSession = true;

            // check for an existing edit session from the current user
            EditSession session = tracker.getSession(requestedFile, getUser());
            if (session != null) {
                if (session.getEditMode() == editMode) openSession = false;
                if ((session.getEditMode() == EditMode.Read) && (editMode == EditMode.ReadWrite)) {
                    tracker.closeSession(requestedFile, getUser());
                }
            }

            if (openSession) {
                tracker.openSession(requestedFile, getUser(), editMode);
            }

            try {
                String contents = getFilesystem().read(getUser(), getPath());
                print(contents);
View Full Code Here

Examples of com.mozilla.bespin.SessionTracker

    @RequiresLogin
    public void put() throws IOException {
        java.io.File file = getFilesystem().getFileHandle(getUser(), getPath());

        SessionTracker tracker = getSessionTracker();
        synchronized (tracker) {
            EditSession session = tracker.getSession(file, getUser());

            // check if the lastEdit parameter was sent
            String lastEdit = getCtx().getReq().getParameter("lastEdit");
            if (StringUtils.isNumeric(lastEdit) && StringUtils.isNotBlank(lastEdit)) {
                // verify that the user has a session open
View Full Code Here

Examples of com.mozilla.bespin.SessionTracker

    @RequiresLogin
    public void delete() throws IOException {
        java.io.File file = getFilesystem().getFileHandle(getUser(), getPath());

        SessionTracker tracker = getSessionTracker();
        synchronized (tracker) {
            // make sure no one else has a session open on the file
            List<EditSession> sessions = tracker.getSessions(file);
            for (EditSession session : sessions) {
                if ((session.getEditMode() == EditMode.ReadWrite) || (!session.getUser().equals(getUser()))) {
                    getCtx().getResp().sendError(409, "Someone else has the file open for read/write access, or you are in read/write mode; cannot delete");
                    return;
                }
            }

            getFilesystem().delete(getUser(), getPath());

            // close any edit sessions open on the file
            for (EditSession session : sessions) tracker.closeSession(file, session.getUser());
        }
    }
View Full Code Here

Examples of com.mozilla.bespin.SessionTracker

    @RequiresLogin
    public void close() throws IOException {
        java.io.File file = getFilesystem().getFileHandle(getUser(), getPath());

        SessionTracker tracker = getSessionTracker();
        tracker.closeSession(file, getUser());
    }
View Full Code Here

Examples of com.mozilla.bespin.SessionTracker

    }

    @RequiresLogin
    public void listopen() throws IOException {
        FileSystem filesys = getFilesystem();
        SessionTracker tracker = getSessionTracker();
        List<EditSession> sessions = tracker.getSessions(getUser());

        JSONObject data = new JSONObject();

        // determine the "project" for the open file and sort by it based on the file name
        for (EditSession session : sessions) {
View Full Code Here

Examples of nz.ac.massey.softwarec.group3.session.SessionTracker

     * Adds all game and user information to a JSON string gameJSON, which will be returned to the client.
     * @param game - The Game for which to get the data.
     * @return String gameJSON - JSON string representing the game.
     */
    public static String getGameData(final Game game) {
        final SessionTracker sessionTracker = SessionListener.getSessionTracker();
        final StringBuilder gameJSON = new StringBuilder();
        gameJSON.append("{\"game\" : ");
        gameJSON.append("{\"players\" : [");
        for (Player player : game.getPlayers()) {
            gameJSON.append("{\"email\" : \"").append(player.getPlayerEmail()).append("\",");
            gameJSON.append("\"name\" : \"").append(sessionTracker.getUserNameFromEmail(player.getPlayerEmail())).append("\",");
            gameJSON.append("\"location\" : ").append(player.getCurrentLocation().getStationNumber()).append(",");
            gameJSON.append("\"taxiTickets\" : ").append(player.getTaxiTokens()).append(",");
            gameJSON.append("\"busTickets\" : ").append(player.getBusTokens()).append(",");
            gameJSON.append("\"undergroundTickets\" : ").append(player.getUndergroundTokens()).append(",");
            gameJSON.append("\"mrXTickets\" : ").append(player.getMrXTokens()).append(",");
View Full Code Here

Examples of nz.ac.massey.softwarec.group3.session.SessionTracker

    /**
     * Gets information for lobby and adds to a JSON string lobbyJSON, which will be returned to the client.
     * @return String lobbyJSON - JSON string representing the lobby user data.
     */
    public static String getLobbyData() {
        final SessionTracker sessionTracker = SessionListener.getSessionTracker();
        final List<String> currentlyOnlineUsersEmails = sessionTracker.getListOfUsersWhoAreCurrentlyOnline();
        final StringBuilder lobbyJSON = new StringBuilder();
        lobbyJSON.append("{\"players\": [");
        for (String userEmail : currentlyOnlineUsersEmails) {
            lobbyJSON.append("{\"name\" : \"").append(sessionTracker.getUserNameFromEmail(userEmail)).append("\"},");
        }
        lobbyJSON.deleteCharAt(lobbyJSON.length()-1);
        lobbyJSON.append("] }");
        return lobbyJSON.toString();
    }
View Full Code Here

Examples of nz.ac.massey.softwarec.group3.session.SessionTracker

    /**
     * Gets all of the current game information and adds it to a JSON string gamesJSON, which will be returned to the client.
     * @return Sting gamesJSON - JSON string representing the lobby games data.
     */
    public static String getGamesData() {
        final SessionTracker sessionTracker = SessionListener.getSessionTracker();
        final List<Game> currentlyAvailableGames = sessionTracker.getGameTracker().getAvailableGames();
        final StringBuilder gamesJSON = new StringBuilder();
        gamesJSON.append("{\"games\": [");
        for (Game game : currentlyAvailableGames) {
            if (!game.isPlaying()) {
                gamesJSON.append("{\"players\": [");
                for (Player player : game.getPlayers()) {
                    gamesJSON.append("{\"name\": \"").append(sessionTracker.getUserNameFromEmail(player.getPlayerEmail())).append("\"},");
                }
                gamesJSON.deleteCharAt(gamesJSON.length()-1);
                gamesJSON.append("] , \"creatorName\": \"").append(game.getCreatorName()).append("\",");
                gamesJSON.append("\"creatorEmail\": \"").append(game.getCreatorEmail()).append("\",");
                gamesJSON.append("\"gameID\": \"").append(game.getGameID()).append("\"},");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.