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);
}
Aggregations