Package org.jivesoftware.xmpp.workgroup

Examples of org.jivesoftware.xmpp.workgroup.AgentSession


            for (long timeRemaining = timeoutTime - System.currentTimeMillis();
                 !offer.isAccepted() && timeRemaining > 0 && !offer.isCancelled();
                 timeRemaining = timeoutTime - System.currentTimeMillis()) {

                try {
                    AgentSession session = getBestNextAgent(initialAgent, ignoreAgent, offer);
                    if (session == null && agentList.isEmpty()) {
                        // Stop looking for an agent since there are no more agent available
                         break;
                    }
                    else if (session == null || offer.isRejector(session)) {
                        initialAgent = null;
                        Thread.sleep(1000);
                    }
                    else {
                        // Recheck for changed maxchat setting
                        Workgroup workgroup = request.getWorkgroup();
                        if (session.getCurrentChats(workgroup) < session.getMaxChats(workgroup)) {
                            // Set the timeout of the offer based on the remaining time of the
                            // initial request and the default offer timeout
                            timeRemaining = timeoutTime - System.currentTimeMillis();
                            offer.setTimeout(timeRemaining < info.getOfferTimeout() ?
                                    timeRemaining : info.getOfferTimeout());

                            // Make the offer and wait for a resolution to the offer
                            if (!request.sendOffer(session, queue)) {
                                // Log debug trace
                                Log.debug("RR - Offer for request: " + offer.getRequest() +
                                        " FAILED TO BE SENT to agent: " +
                                        session.getJID());
                                continue;
                            }
                            // Log debug trace
                            Log.debug("RR - Offer for request: " + offer.getRequest() + " SENT to agent: " +
                                    session.getJID());

                            offer.waitForResolution();
                            // If the offer was accepted, we send out the invites
                            // and reset the offer
                            if (offer.isAccepted()) {
                                // Get the first agent that accepted the offer
                                AgentSession selectedAgent = offer.getAcceptedSessions().get(0);
                                // Log debug trace
                                Log.debug("RR - Agent: " + selectedAgent.getJID() +
                                        " ACCEPTED request: " +
                                        request);
                                // Create the room and send the invitations
                                offer.invite(selectedAgent);
                                // Notify the agents that accepted the offer that the offer process
View Full Code Here


     * @param ignoreAgent agent that should not be considered as available.
     * @param offer the offer about to be sent to the best available agent.
     * @return the best agent.
     */
    private AgentSession getBestNextAgent(String initialAgent, String ignoreAgent, Offer offer) {
        AgentSession bestSession;

        // Look for specified agent in agent list
        if (initialAgent != null) {
            final AgentSessionList agentSessionList = queue.getAgentSessionList();
            for (AgentSession agentSession : agentSessionList.getAgentSessions()) {
                String sessionAgent = agentSession.getAgent().getAgentJID().toBareJID();
                boolean match = sessionAgent.startsWith(initialAgent.toLowerCase());
                Workgroup workgroup = offer.getRequest().getWorkgroup();
                if (agentSession.isAvailableToChat() &&
                        agentSession.getCurrentChats(workgroup) < agentSession.getMaxChats(workgroup) && match) {
                    bestSession = agentSession;
                    // Log debug trace
                    Log.debug("RR - Initial agent: " + bestSession.getJID() +
                            " will receive offer for request: " +
                            offer.getRequest());
                    return bestSession;
                }
            }
        }

        // Let's iterate through each agent and check availability
        final AgentSessionList agentSessionList = queue.getAgentSessionList();
        final List<AgentSession> possibleSessions = new ArrayList<AgentSession>();
        for (AgentSession agentSession : agentSessionList.getAgentSessions()) {
            String sessionAgent = agentSession.getAgent().getAgentJID().toBareJID();
            boolean ignore = ignoreAgent != null && sessionAgent.startsWith(ignoreAgent.toLowerCase());
            if (!ignore && validateAgent(agentSession, offer)) {
                possibleSessions.add(agentSession);
            }
        }

        // Select the best agent from the list of possible agents
        if (possibleSessions.size() > 0) {
            AgentSession s = agentSelector.bestAgentFrom(possibleSessions, offer);
            // Log debug trace
            Log.debug("RR - Agent SELECTED: " + s.getJID() +
                    " for receiving offer for request: " +
                    offer.getRequest());
            return s;
        }
        return null;
View Full Code Here

        IQ reply;
        Element iq = packet.getChildElement();

        // Verify that an agent is requesting this information.
        try {
            AgentSession agentSession = workgroup.getAgentManager().getAgentSession(packet.getFrom());
            if (agentSession != null) {
                String sessionID = iq.element("sessionID").getTextTrim();

                sendNotesPacket(packet, workgroup, sessionID);
            }
View Full Code Here

        IQ reply;
        Element iq = packet.getChildElement();

        try {
            // Verify that an agent is requesting this information.
            AgentSession agentSession = workgroup.getAgentManager().getAgentSession(packet.getFrom());
            if (agentSession != null) {
                String sessionID = iq.element("sessionID").getTextTrim();
                Element notes = iq.element("notes");
                String noteText = notes.getTextTrim();
                appendNote(sessionID, noteText);
View Full Code Here

    private void handleUserHistoryRequest(IQ packet, Workgroup workgroup) {
        IQ reply;
        Element iq = packet.getChildElement();

        try {
            AgentSession agentSession = workgroup.getAgentManager().getAgentSession(packet.getFrom());
            if (agentSession == null) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.not_authorized));
                workgroup.send(reply);
View Full Code Here

    }

    public void executeGet(IQ packet, Workgroup workgroup) {
        IQ reply = IQ.createResultIQ(packet);
        try {
            AgentSession agentSession = workgroup.getAgentManager().getAgentSession(packet.getFrom());
            if (agentSession == null) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.not_authorized));
                workgroup.send(reply);
View Full Code Here

        }
    }

    public void execute() {
        if (Type.user == type) {
            AgentSession agentSession = null;
            // Verify if the invitee user is an agent that is currently logged
            try {
                agentSession = WorkgroupManager.getInstance().getAgentManager().getAgent(invitee).getAgentSession();
            }
            catch (AgentNotFoundException e) {
                // Ignore
            }

            // Only Send muc invites to a particular user.
            if (true){
                // Invitee is not an agent so send a standard MUC room invitation
                sendMUCInvitiation();
                // Keep track when the invitation was sent to the user
                offerAccpeted = System.currentTimeMillis();
            }
            else {
                // Invite the agent to the room by sending an offer
                Workgroup workgroup = agentSession.getWorkgroups().iterator().next();
                RequestQueue requestQueue = workgroup.getRequestQueues().iterator().next();
                // Add the requested agent as the initial target agent to get the offer
                getMetaData().put("agent", Arrays.asList(invitee.toString()));
                getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
                // Dispatch the request
View Full Code Here

        }
    }

    public void execute() {
        if (Type.user == type) {
            AgentSession agentSession = null;
            // Verify if the invitee user is an agent that is currently logged
            try {
                agentSession = WorkgroupManager.getInstance().getAgentManager().getAgent(invitee).getAgentSession();
            }
            catch (AgentNotFoundException e) {
                // Ignore
            }

            // Only send muc invites to a particular user.
            if (true) {
                // Invitee is not an agent so send a standard MUC room invitation
                sendMUCInvitiation();
                // Keep track when the invitation was sent to the user
                offerAccepted = System.currentTimeMillis();
            }
            else {
                // Invite the agent to the room by sending an offer
                Workgroup workgroup = agentSession.getWorkgroups().iterator().next();
                RequestQueue requestQueue = workgroup.getRequestQueues().iterator().next();
                // Add the requested agent as the initial target agent to get the offer
                getMetaData().put("agent", Arrays.asList(invitee.toString()));
                getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
                // Dispatch the request
View Full Code Here

TOP

Related Classes of org.jivesoftware.xmpp.workgroup.AgentSession

Copyright © 2018 www.massapicom. 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.