use of org.jivesoftware.xmpp.workgroup.RequestQueue 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);
}
use of org.jivesoftware.xmpp.workgroup.RequestQueue in project Openfire by igniterealtime.
the class InvitationRequest method execute.
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
requestQueue.getDispatcher().injectRequest(this);
}
} else if (Type.queue == type) {
// Send offer to the best again available in the requested queue
Workgroup targetWorkgroup = WorkgroupManager.getInstance().getWorkgroup(invitee.getNode());
if (targetWorkgroup == null) {
// No workgroup was found for the specified invitee. Send a Message with the error
sendErrorMessage("Specified workgroup was not found.");
return;
}
try {
RequestQueue requestQueue = targetWorkgroup.getRequestQueue(invitee.getResource());
getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
// Dispatch the request
requestQueue.getDispatcher().injectRequest(this);
} catch (NotFoundException e) {
// No queue was found for the specified invitee. Send a Message with the error
sendErrorMessage("Specified queue was not found.");
}
} else if (Type.workgroup == type) {
// Select the best queue based on the original request
Workgroup targetWorkgroup = WorkgroupManager.getInstance().getWorkgroup(invitee.getNode());
if (targetWorkgroup != null) {
RequestQueue requestQueue = RoutingManager.getInstance().getBestQueue(targetWorkgroup, userRequest);
getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
// Send offer to the best again available in the requested queue
requestQueue.getDispatcher().injectRequest(this);
} else {
// No workgroup was found for the specified invitee. Send a Message with the error
sendErrorMessage("Specified workgroup was not found.");
}
}
}
use of org.jivesoftware.xmpp.workgroup.RequestQueue in project Openfire by igniterealtime.
the class TransferRequest method execute.
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
requestQueue.getDispatcher().injectRequest(this);
}
} else if (Type.queue == type) {
// Send offer to the best again available in the requested queue
Workgroup targetWorkgroup = WorkgroupManager.getInstance().getWorkgroup(invitee.getNode());
if (targetWorkgroup == null) {
// No workgroup was found for the specified invitee. Send a Message with the error
sendErrorMessage("Specified workgroup was not found.");
return;
}
try {
RequestQueue requestQueue = targetWorkgroup.getRequestQueue(invitee.getResource());
getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
// Dispatch the request
requestQueue.getDispatcher().injectRequest(this);
} catch (NotFoundException e) {
// No queue was found for the specified invitee. Send a Message with the error
sendErrorMessage("Specified queue was not found.");
}
} else if (Type.workgroup == type) {
// Select the best queue based on the original request
Workgroup targetWorkgroup = WorkgroupManager.getInstance().getWorkgroup(invitee.getNode());
if (targetWorkgroup != null) {
RequestQueue requestQueue = RoutingManager.getInstance().getBestQueue(targetWorkgroup, userRequest);
getMetaData().put("ignore", Arrays.asList(inviter.toBareJID()));
// Send offer to the best again available in the requested queue
requestQueue.getDispatcher().injectRequest(this);
} else {
// No workgroup was found for the specified invitee. Send a Message with the error
sendErrorMessage("Specified workgroup was not found.");
}
}
}
Aggregations