Folks,
Fastpath dispatches live requests in a round robin system, waiting for each agent in turn to either accept or reject the chat request. I want to change it so that it broadcasts the request simultaneously to all agents, but I have some confusion as to how this should be handled in the code (see below). First question is if I send the offer to every AgentSession up front, and the offer is accepted twice, if there is a way to distinguish which agent the accepted belongs to?
Thanks,
BEA
public void dispatch(Offer offer) {
// The time when the request should timeout
long timeoutTime = System.currentTimeMillis() + info.getRequestTimeout();
final Request request = offer.getRequest();
boolean canBeInQueue = request instanceof UserRequest;
Map<String,List<String>> map = request.getMetaData();
String initialAgent = map.get("agent") == null || map.get("agent").isEmpty() ? null : map.get("agent").get(0);
String ignoreAgent = map.get("ignore") == null || map.get("ignore").isEmpty() ? null : map.get("ignore").get(0);
// Log debug trace
logger.debug("RR - Dispatching request: " + request + " in queue: " + queue.getAddress()); // Send the offer to the best agent. While the offer has not been accepted send it to the
// next best agent. If there aren't any agent available then skip this section and proceed
// to overflow the current request
if (!agentList.isEmpty()) {
for (long timeRemaining = timeoutTime - System.currentTimeMillis();
!offer.isAccepted() && timeRemaining > 0 && !offer.isCancelled();
timeRemaining = timeoutTime - System.currentTimeMillis()) { try {
AgentSession session = getBestNextAgent(initialAgent, ignoreAgent, offer);
if (session == null && agentList.isEmpty()) {
// Stop looking for an agent since there are no more agent available
break;
}
else if (session == null || offer.isRejector(session)) {
initialAgent = null;
Thread.sleep(1000);
}
else {
// Recheck for changed maxchat setting
Workgroup workgroup = request.getWorkgroup();
if (session.getCurrentChats(workgroup) < session.getMaxChats(workgroup)) {
// Set the timeout of the offer based on the remaining time of the
// initial request and the default offer timeout
timeRemaining = timeoutTime - System.currentTimeMillis();
offer.setTimeout(timeRemaining < info.getOfferTimeout() ?
timeRemaining : info.getOfferTimeout()); // Make the offer and wait for a resolution to the offer
if (!request.sendOffer(session, queue)) {
// Log debug trace
logger.debug("RR - Offer for request: " + offer.getRequest() +
" FAILED TO BE SENT to agent: " +
session.getJID());
continue;
}
// Log debug trace
logger.debug("RR - Offer for request: " + offer.getRequest() + " SENT to agent: " +
session.getJID()); offer.waitForResolution();
// If the offer was accepted, we send out the invites
// and reset the offer
if (offer.isAccepted()) {
// Get the first agent that accepted the offer
AgentSession selectedAgent = offer.getAcceptedSessions().get(0);
// Log debug trace
logger.debug("RR - Agent: " + selectedAgent.getJID() +
" ACCEPTED request: " +
request);
// Create the room and send the invitations
offer.invite(selectedAgent);
// Notify the agents that accepted the offer that the offer process
// has finished
for (AgentSession agent : offer.getAcceptedSessions()) {
agent.removeOffer(offer);
}
if (canBeInQueue) {
// Remove the user from the queue since his request has
// been accepted
queue.removeRequest((UserRequest) request);
}
}
}
else {
// Log debug trace
logger.debug("RR - Selected agent: " + session.getJID() +
" has reached max number of chats");
}
}
}
catch (Exception e) {
logger.error(e);
}
}
}
if (!offer.isAccepted() && !offer.isCancelled()) {
// Calculate the maximum time limit for an unattended request before cancelling it
long limit = request.getCreationTime().getTime() +
(info.getRequestTimeout() * (getOverflowTimes() + 1));
if (limit - System.currentTimeMillis() <= 0 || !canBeInQueue) {
// Log debug trace
logger.debug("RR - Cancelling request that maxed out overflow limit or cannot be queued: " + request);
// Cancel the request if it has overflowed 'n' times
request.cancel(Request.CancelType.AGENT_NOT_FOUND);
}
else {
// Overflow if request timed out and was not dispatched and max number of overflows
// has not been reached yet
overflow(offer);
// If there is no other queue to overflow then cancel the request
if (!offer.isAccepted() && !offer.isCancelled()) {
// Log debug trace
logger.debug("RR - Cancelling request that didn't overflow: " + request);
request.cancel(Request.CancelType.AGENT_NOT_FOUND);
}
}
}
}