⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 agentsession.java

📁 openfire 服务器源码下载
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            // Clear the offer associated with this agent session
            removeOffer(offer);
        }
        catch (Exception e) {
            ComponentManagerFactory.getComponentManager().getLog().error(e);
        }
    }

    public Agent getAgent() {
        return agent;
    }

    /**
     * Returns the <code>Workgroup</code> where this session is working.
     *
     * @return the <code>Workgroup</code> where this session is working.
     */
    public Collection<Workgroup> getWorkgroups() {
        return workgroups;
    }

    public int getMaxChats(Workgroup workgroup) {
        int max = maxChats;
        // Get the upper and lower limits
        int upper = workgroup.getMaxChats();
        int lower = workgroup.getMinChats();
        // Ensure that max chats is in the limits
        if (max == -1) {
            max = upper;
        }
        if (max < lower) {
            max = lower;
        }
        if (max > upper) {
            max = upper;
        }
        return max;
    }

    private void setMaxChats(int max) {
        maxChats = max;
    }

    // Sessions NEVER set min chats
    public void setMinChats(int min) {
    }

    /**
     * Returns a collection with the JID of the users that this agent is having a chat with.
     *
     * @param workgroup workgroup to get is chats.
     * @return a collection with the JID of the users that this agent is having a chat with.
     */
    public Collection<JID> getUsersJID(Workgroup workgroup) {
        Collection<ChatInfo> chats = getChats(workgroup);
        Collection<JID> jids = new ArrayList<JID>(chats.size());
        for (ChatInfo info : chats) {
            jids.add(info.getUserJID());
        }
        return jids;
    }

    public boolean equals(Object o) {
        boolean match = false;
        if (o instanceof AgentSession) {
            match = ((AgentSession)o).getJID().equals(address);
        }
        return match;
    }

    public JID getJID() {
        return address;
    }

    public long getID() {
        return id;
    }

    public String getUsername() {
        return address.getNode();
    }

    /**
     * Returns true if the agent has requested to receive other agents' information. Until the
     * agent requests to receive other agents' information he won't receive individual presence
     * updates of other agents.
     *
     * @return true if the agent has requested to receive other agents' information.
     */
    boolean hasRequestedAgentInfo() {
        return requestedAgentInfo;
    }

    /**
     * Returns true if the agent's presence is available and his status is nor DND (do not disturb)
     * neither XA (extended away). These are the possible statuses and their meanings:<ul>
     * <li>chat - Indicates the agent is available to chat (is idle and ready to handle more
     * conversations).</li>
     * <li>away - The agent is busy (possibly with other chats). The agent may still be able to
     * handle other chats but an offer rejection is likely..</li>
     * <li>xa - The agent is physically away from their terminal and should not have a chat routed
     * to them.</li>
     * <li>dnd - The agent is busy and should not be disturbed. However, special case, or extreme
     * urgency chats may still be offered to the agent although offer rejection or offer timeouts
     * are highly likely.</li>
     * </ul>
     *
     * @return true if the agent's presence is available and his status is nor DND neither XA.
     */
    public boolean isAvailableToChat() {
        return (presence.getType() == null && presence.getShow() != Presence.Show.dnd &&
            presence.getShow() != Presence.Show.xa && presence.getShow() != Presence.Show.away);
    }

    /**
     * Adds information of a new chat that this agent is having with a user.
     *
     * @param workgroup workgroup where the chat has started.
     * @param sessionID the id of the session that identifies the chat.
     * @param request   the initial request made by the user.
     * @param date      the date when the agent joined the chat.
     */
    public void addChatInfo(Workgroup workgroup, String sessionID, UserRequest request, Date date) {
        Queue<ChatInfo> queue = chatInfos.get(workgroup);
        // Check if the agent has started a chat in a workgroup that he never joined (e.g. transfers)
        if (queue == null) {
            synchronized (workgroup) {
                queue = chatInfos.get(workgroup);
                if (queue == null) {
                    queue = new ConcurrentLinkedQueue<ChatInfo>();
                    chatInfos.put(workgroup, queue);
                }
            }
        }
        queue.add(new ChatInfo(sessionID, request, date));
        // Update all agents with a new agent-status packet with the current-chats updated.
        sendStatusToAllAgents(workgroup);
    }

    /**
     * Removes information about a chat since the agent left the conversation.
     *
     * @param workgroup workgroup where the chat existed.
     * @param sessionID the id of the session that identifies the chat.
     */
    public void removeChatInfo(Workgroup workgroup, String sessionID) {
        Queue<ChatInfo> chats = chatInfos.get(workgroup);
        for (ChatInfo chatInfo : chats) {
            if (sessionID.equals(chatInfo.getSessionID())) {
                // Update last chat ended date
                lastChatTime = new Date();

                chats.remove(chatInfo);
                // Update all agents with a new agent-status packet with the current-chats updated.
                sendStatusToAllAgents(workgroup);
                break;
            }
        }
    }

    /**
     * Returns a list with the actual chats info that the agent is having at the moment. The
     * returned collection is a snapshot of the chats so it will not be updated if a chat finished
     * or a new one has started.
     *
     * @param workgroup workgroup to get its chats.
     * @return a list with the actual chats info that the agent is having at the moment.
     */
    public Collection<ChatInfo> getChatsInfo(Workgroup workgroup) {
        return Collections.unmodifiableCollection(getChats(workgroup));
    }

    private Collection<ChatInfo> getChats(Workgroup workgroup) {
        Queue<ChatInfo> chats = chatInfos.get(workgroup);
        if (chats != null) {
            return chats;
        }
        return Collections.emptyList();
    }

    /**
     * This agent is not longer related to this offer. The agent may have been selected to answer
     * the user's request or the offer has been assigned to another agent or the request was
     * cancelled.
     *
     * @param offer the offer that is not longer related to this agent.
     */
    public void removeOffer(Offer offer) {
        if (offer.equals(this.offer)) {
            this.offer = null;
        }
        else {
            ComponentManagerFactory.getComponentManager().getLog().debug("Offer not removed. " +
                "To remove: " +
                offer +
                " existing " +
                this.offer);
        }
    }

    /**
     * Returns true if the agent has received an offer and the server is still waiting for an
     * answer.
     *
     * @return true if the agent has received an offer and the server is still waiting for an
     *         answer.
     */
    public boolean isWaitingOfferAnswer() {
        return offer != null;
    }

    /**
     * Represents information about a Chat where this Agent is participating.
     *
     * @author Gaston Dombiak
     */
    public static class ChatInfo implements Comparable {

        private String sessionID;
        private String userID;
        private JID userJID;
        private Date date;
        private Workgroup workgroup;

        // Add extra metadata
        private String email;
        private String username;
        private String question;

        public ChatInfo(String sessionID, UserRequest request, Date date) {
            this.sessionID = sessionID;
            this.userID = request.getUserID();
            this.userJID = request.getUserJID();
            this.workgroup = request.getWorkgroup();
            this.date = date;

            Map metadata = request.getMetaData();

            if (metadata.containsKey("email")) {
                email = listToString((List)metadata.get("email"));
            }

            if (metadata.containsKey("username")) {
                username = listToString((List)metadata.get("username"));
            }

            if (metadata.containsKey("question")) {
                question = listToString((List)metadata.get("question"));
            }
        }

        /**
         * Returns the sessionID associated to this chat. Each chat will have a unique sessionID
         * that could be used for retrieving the whole transcript of the conversation.
         *
         * @return the sessionID associated to this chat.
         */
        public String getSessionID() {
            return sessionID;
        }

        /**
         * Returns the user unique identification of the user that made the initial request and
         * for which this chat was generated. If the user joined using an anonymous connection
         * then the userID will be the value of the ID attribute of the USER element. Otherwise,
         * the userID will be the bare JID of the user that made the request.
         *
         * @return the user unique identification of the user that made the initial request.
         */
        public String getUserID() {
            return userID;
        }

        /**
         * Returns the JID of the user that made the initial request and for which this chat
         * was generated.
         *
         * @return the JID of the user that made the initial request and for which this chat
         *         was generated.
         */
        public JID getUserJID() {
            return userJID;
        }

        /**
         * Returns the date when this agent joined the chat.
         *
         * @return the date when this agent joined the chat.
         */
        public Date getDate() {
            return date;
        }

        /**
         * Returns the email address of the user the agent is chatting with.
         *
         * @return the email address of the user the agent is chatting with.
         */
        public String getEmail() {
            return email;
        }

        /**
         * Return the username of the user the agent is chatting with.
         *
         * @return the username of the user the agent is chatting with.
         */
        public String getUsername() {
            return username;
        }

        /**
         * Return the question the user asked, if any.
         *
         * @return the question the user asked, if any.
         */
        public String getQuestion() {
            return question;
        }

        /**
         * Returns the packets sent to the room together with the date when the packet was sent.
         * The returned map will include both Presences and Messages.
         *
         * @return the packets sent to the room together with the date when the packet was sent.
         */
        public Map<Packet, java.util.Date> getPackets() {
            return workgroup.getTranscript(getSessionID());
        }

        public int compareTo(Object o) {
            ChatInfo otherInfo = (ChatInfo)o;
            return date.compareTo(otherInfo.getDate());
        }
    }

    /**
     * Returns a list as a comma delimited string.
     *
     * @param list the list of strings.
     * @return a comma delimited list of strings.
     */
    private static String listToString(List list) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            String entry = (String)list.get(i);
            builder.append(entry);
            if (i != (list.size() - 1)) {
                builder.append(",");
            }
        }
        return builder.toString();
    }

    /**
     * Return the time the last chat ended.
     *
     * @return the time.
     */
    public Date getTimeLastChatEnded() {
        return lastChatTime;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -