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