Search in sources :

Example 1 with WordMatchRouter

use of org.jivesoftware.xmpp.workgroup.spi.routers.WordMatchRouter in project Openfire by igniterealtime.

the class RoutingManager method getBestQueue.

/**
     * Returns the best {@link RequestQueue} in the specified {@link Workgroup} that could
     * handle the specified {@link UserRequest}.
     *
     * @param workgroup the workgroup where a queue will be searched.
     * @param request the user request to be handled.
     * @return the best RequestQueue in the specified Workgroup.
     */
public RequestQueue getBestQueue(Workgroup workgroup, UserRequest request) {
    WordMatchRouter router = new WordMatchRouter();
    for (RoutingRule rule : getRoutingRules(workgroup)) {
        String query = rule.getQuery();
        boolean handled = router.checkForHits(request.getMetaData(), query);
        if (handled) {
            // Retrieve queue and route to it.
            try {
                return workgroup.getRequestQueue(rule.getQueueID());
            } catch (NotFoundException e) {
                Log.error(e.getMessage(), e);
            }
        }
    }
    List<RequestQueue> availableRequestQueues = new ArrayList<RequestQueue>();
    // Route to best queue based on availability.
    for (RequestQueue requestQueue : workgroup.getRequestQueues()) {
        // Skip queues that do not have agents at the moment
        if (requestQueue != null && requestQueue.isOpened()) {
            availableRequestQueues.add(requestQueue);
        }
    }
    Collections.sort(availableRequestQueues, queueComparator);
    return availableRequestQueues.get(0);
}
Also used : WordMatchRouter(org.jivesoftware.xmpp.workgroup.spi.routers.WordMatchRouter) RequestQueue(org.jivesoftware.xmpp.workgroup.RequestQueue) ArrayList(java.util.ArrayList) NotFoundException(org.jivesoftware.util.NotFoundException)

Aggregations

ArrayList (java.util.ArrayList)1 NotFoundException (org.jivesoftware.util.NotFoundException)1 RequestQueue (org.jivesoftware.xmpp.workgroup.RequestQueue)1 WordMatchRouter (org.jivesoftware.xmpp.workgroup.spi.routers.WordMatchRouter)1