Search in sources :

Example 1 with RequestQueue

use of org.jivesoftware.xmpp.workgroup.RequestQueue in project Openfire by igniterealtime.

the class MetaDataRouter method handleRequest.

@Override
public boolean handleRequest(Workgroup workgroup, UserRequest request) {
    boolean success = false;
    Map<String, List<String>> metaData = request.getMetaData();
    if (metaData != null) {
        // Route to queue with most matching meta-data
        RequestQueue bestQueue = routeNoOverflow(workgroup, metaData);
        if (bestQueue != null) {
            setRoutingQueue(bestQueue.getID());
            success = true;
        }
    }
    return success;
}
Also used : RequestQueue(org.jivesoftware.xmpp.workgroup.RequestQueue) List(java.util.List)

Example 2 with RequestQueue

use of org.jivesoftware.xmpp.workgroup.RequestQueue in project Openfire by igniterealtime.

the class MetaDataRouter method routeNoOverflow.

private RequestQueue routeNoOverflow(Workgroup workgroup, Map<String, List<String>> metaData) {
    RequestQueue bestQueue = null;
    int bestMatch = -1;
    int currentMatch;
    for (RequestQueue requestQueue : workgroup.getRequestQueues()) {
        // Skip queues that doesn't have agents at the moment
        if (!requestQueue.isOpened()) {
            continue;
        }
        int overflowValue = requestQueue.getOverflowType().ordinal();
        switch(overflowValue) {
            case // random - route to best that's available
            1:
                // (or none if no queues are available)
                if (requestQueue.getAgentSessionList().containsAvailableAgents()) {
                    currentMatch = calculateMatchScore(requestQueue, metaData);
                    if (currentMatch > bestMatch) {
                        bestQueue = requestQueue;
                        bestMatch = currentMatch;
                    }
                }
                break;
            case // backup - route to best or best's backup
            2:
                currentMatch = calculateMatchScore(requestQueue, metaData);
                if (currentMatch > bestMatch) {
                    if (!requestQueue.getAgentSessionList().containsAvailableAgents() && requestQueue.getBackupQueue() != null) {
                        // Route to backup queue if no agents available and
                        // backup queue set
                        bestQueue = requestQueue.getBackupQueue();
                    } else {
                        bestQueue = requestQueue;
                    }
                    bestMatch = currentMatch;
                }
                break;
            default:
                // none - route to best
                currentMatch = calculateMatchScore(requestQueue, metaData);
                if (currentMatch > bestMatch) {
                    bestQueue = requestQueue;
                    bestMatch = currentMatch;
                }
        }
    }
    return bestQueue;
}
Also used : RequestQueue(org.jivesoftware.xmpp.workgroup.RequestQueue)

Example 3 with RequestQueue

use of org.jivesoftware.xmpp.workgroup.RequestQueue in project Openfire by igniterealtime.

the class ChatHistoryUtils method getNumberOfChatsForWorkgroup.

/**
     * Returns the total number of chats that have occured within a workgroup.
     *
     * @param workgroupName the jid of the workgroup.
     * @return the total number of chats that have occured within a workgroup.
     */
public static int getNumberOfChatsForWorkgroup(String workgroupName) {
    Workgroup workgroup = null;
    try {
        workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    }
    int count = 0;
    for (RequestQueue requestQueue : workgroup.getRequestQueues()) {
        count += requestQueue.getTotalChatCount();
    }
    return count;
}
Also used : JID(org.xmpp.packet.JID) RequestQueue(org.jivesoftware.xmpp.workgroup.RequestQueue) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) SQLException(java.sql.SQLException)

Example 4 with RequestQueue

use of org.jivesoftware.xmpp.workgroup.RequestQueue in project Openfire by igniterealtime.

the class WorkgroupUtils method createWorkgroup.

/**
     * Create a new Workgroup.
     *
     * @param workgroupName the name of the workgroup.
     * @param description the description of the workgroup.
     * @param agents the agents, in a comma delimited string.
     * @return a map of errors (if any)
     */
public static Map<String, String> createWorkgroup(String workgroupName, String description, String agents) {
    Map<String, String> errors = new HashMap<String, String>();
    // Get a workgroup manager
    WorkgroupManager wgManager = WorkgroupManager.getInstance();
    if (wgManager == null) {
        errors.put("general_error", "The server is down");
        return errors;
    }
    String defaultQueueName = "Default Queue";
    // Validate
    if (workgroupName == null) {
        errors.put("wgName", "");
    } else {
        try {
            workgroupName = workgroupName.trim().toLowerCase();
            workgroupName = Stringprep.nodeprep(workgroupName);
        } catch (StringprepException se) {
            errors.put("wgName", "");
        }
    }
    // do a create if there were no errors
    RequestQueue queue = null;
    if (errors.size() == 0) {
        try {
            // Create new workgroup
            Workgroup workgroup = wgManager.createWorkgroup(workgroupName);
            workgroup.setDescription(description);
            // Create a default workgroup queue
            queue = workgroup.createRequestQueue(defaultQueueName);
            //workgroup.setMaxChats(maxChats);
            //workgroup.setMinChats(minChats);
            // Make the workgroup ready by default:
            workgroup.setStatus(Workgroup.Status.READY);
            // Create default messages and images for the new workgroup
            ChatSettingsCreator.getInstance().createDefaultSettings(workgroup.getJID());
            // Add generic web form
            FormManager formManager = FormManager.getInstance();
            formManager.createGenericForm(workgroup);
        } catch (UserAlreadyExistsException uaee) {
            errors.put("exists", "");
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
            errors.put("general", "");
        }
    }
    if (ModelUtil.hasLength(agents)) {
        addAgents(queue, agents);
    }
    return errors;
}
Also used : StringprepException(gnu.inet.encoding.StringprepException) HashMap(java.util.HashMap) FormManager(org.jivesoftware.openfire.fastpath.dataforms.FormManager) RequestQueue(org.jivesoftware.xmpp.workgroup.RequestQueue) UserAlreadyExistsException(org.jivesoftware.xmpp.workgroup.UserAlreadyExistsException) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager) StringprepException(gnu.inet.encoding.StringprepException) UserAlreadyExistsException(org.jivesoftware.xmpp.workgroup.UserAlreadyExistsException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 5 with RequestQueue

use of org.jivesoftware.xmpp.workgroup.RequestQueue in project Openfire by igniterealtime.

the class RoundRobinDispatcher method overflow.

/**
     * <p>Overflow the current request into another queue if possible.</p>
     * <p/>
     * <p>Future versions of the dispatcher may wish to overflow in
     * more sophisticated ways. Currently we do it according to overflow
     * rules: none (no overflow), backup (to a backup if it exists and is
     * available, or randomly.</p>
     *
     * @param offer the offer to place in the overflow queue.
     */
private void overflow(Offer offer) {
    RequestQueue backup = null;
    if (RequestQueue.OverflowType.OVERFLOW_BACKUP.equals(queue.getOverflowType())) {
        backup = queue.getBackupQueue();
        // Check that the backup queue has agents available otherwise discard it
        if (backup != null && !backup.getAgentSessionList().containsAvailableAgents()) {
            backup = null;
        }
    } else if (RequestQueue.OverflowType.OVERFLOW_RANDOM.equals(queue.getOverflowType())) {
        backup = getRandomQueue();
    }
    // and add the request in the backup queue
    if (backup != null) {
        offer.cancel();
        UserRequest request = (UserRequest) offer.getRequest();
        // Remove the request from the queue since it is going to be added to another
        // queue
        queue.removeRequest(request);
        // Log debug trace
        Log.debug("RR - Overflowing request: " + request + " to queue: " + backup.getAddress());
        backup.addRequest(request);
    }
}
Also used : RequestQueue(org.jivesoftware.xmpp.workgroup.RequestQueue) UserRequest(org.jivesoftware.xmpp.workgroup.request.UserRequest)

Aggregations

RequestQueue (org.jivesoftware.xmpp.workgroup.RequestQueue)8 Workgroup (org.jivesoftware.xmpp.workgroup.Workgroup)4 NotFoundException (org.jivesoftware.util.NotFoundException)3 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)2 AgentNotFoundException (org.jivesoftware.xmpp.workgroup.AgentNotFoundException)2 AgentSession (org.jivesoftware.xmpp.workgroup.AgentSession)2 StringprepException (gnu.inet.encoding.StringprepException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 FormManager (org.jivesoftware.openfire.fastpath.dataforms.FormManager)1 UserAlreadyExistsException (org.jivesoftware.xmpp.workgroup.UserAlreadyExistsException)1 WorkgroupManager (org.jivesoftware.xmpp.workgroup.WorkgroupManager)1 UserRequest (org.jivesoftware.xmpp.workgroup.request.UserRequest)1 WordMatchRouter (org.jivesoftware.xmpp.workgroup.spi.routers.WordMatchRouter)1 JID (org.xmpp.packet.JID)1