2004-08-16 02:57:36 +02:00
|
|
|
/**
|
2004-11-03 00:37:00 +01:00
|
|
|
* $RCSfile$
|
|
|
|
* $Revision$
|
|
|
|
* $Date$
|
|
|
|
*
|
|
|
|
* Copyright 2003-2004 Jive Software.
|
|
|
|
*
|
|
|
|
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2004-08-16 02:57:36 +02:00
|
|
|
|
|
|
|
package org.jivesoftware.smackx.workgroup.agent;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
/**
|
2004-08-17 18:18:19 +02:00
|
|
|
* A queue in a workgroup, which is a pool of agents that are routed a specific type of
|
2004-08-16 02:57:36 +02:00
|
|
|
* chat request.
|
2004-08-17 18:18:19 +02:00
|
|
|
*
|
|
|
|
* @author Matt Tucker
|
2004-08-16 02:57:36 +02:00
|
|
|
*/
|
|
|
|
public class WorkgroupQueue {
|
|
|
|
|
|
|
|
private String name;
|
|
|
|
private Status status = Status.CLOSED;
|
|
|
|
|
|
|
|
private int averageWaitTime = -1;
|
|
|
|
private Date oldestEntry = null;
|
|
|
|
private Set users = Collections.EMPTY_SET;
|
|
|
|
|
|
|
|
private Set agents = Collections.EMPTY_SET;
|
|
|
|
private int maxChats = 0;
|
|
|
|
private int currentChats = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new workgroup queue instance.
|
|
|
|
*
|
|
|
|
* @param name the name of the queue.
|
|
|
|
*/
|
|
|
|
WorkgroupQueue(String name) {
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-08-17 18:18:19 +02:00
|
|
|
* Returns the name of this queue.
|
2004-08-16 02:57:36 +02:00
|
|
|
*
|
2004-08-17 18:18:19 +02:00
|
|
|
* @return the name of this queue.
|
2004-08-16 02:57:36 +02:00
|
|
|
*/
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-08-17 18:18:19 +02:00
|
|
|
* Returns the status of this queue.
|
2004-08-16 02:57:36 +02:00
|
|
|
*
|
2004-08-17 18:18:19 +02:00
|
|
|
* @return the status of this queue.
|
2004-08-16 02:57:36 +02:00
|
|
|
*/
|
|
|
|
public Status getStatus() {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setStatus(Status status) {
|
|
|
|
this.status = status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-08-17 18:18:19 +02:00
|
|
|
* Returns the number of users in this queue that are waiting to be routed to
|
2004-08-16 02:57:36 +02:00
|
|
|
* an agent.
|
|
|
|
*
|
|
|
|
* @return the number of users waiting in the queue.
|
|
|
|
*/
|
|
|
|
public int getUserCount() {
|
|
|
|
if (users == null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return users.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-08-17 18:18:19 +02:00
|
|
|
* Returns an Iterator for the users in this queue that are waiting
|
|
|
|
* to be routed to an agent (QueueUser instances).
|
2004-08-16 02:57:36 +02:00
|
|
|
*
|
|
|
|
* @return an Iterator for the users waiting in the queue.
|
|
|
|
*/
|
|
|
|
public Iterator getUsers() {
|
|
|
|
if (users == null) {
|
|
|
|
return Collections.EMPTY_SET.iterator();
|
|
|
|
}
|
|
|
|
return Collections.unmodifiableSet(users).iterator();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setUsers(Set users) {
|
|
|
|
this.users = users;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-08-17 18:18:19 +02:00
|
|
|
* Returns the average amount of time users wait in this queue before being
|
2004-08-16 02:57:36 +02:00
|
|
|
* routed to an agent. If average wait time info isn't available, -1 will
|
|
|
|
* be returned.
|
|
|
|
*
|
2004-08-17 18:18:19 +02:00
|
|
|
* @return the average wait time in this queue.
|
2004-08-16 02:57:36 +02:00
|
|
|
*/
|
|
|
|
public int getAverageWaitTime() {
|
|
|
|
return averageWaitTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAverageWaitTime(int averageTime) {
|
|
|
|
this.averageWaitTime = averageTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-08-17 18:18:19 +02:00
|
|
|
* Returns the date of the oldest request waiting in this queue. If there
|
2004-08-16 02:57:36 +02:00
|
|
|
* are no requests waiting to be routed, this method will return <tt>null</tt>.
|
|
|
|
*
|
2004-08-17 18:18:19 +02:00
|
|
|
* @return the date of the oldest request in this queue.
|
2004-08-16 02:57:36 +02:00
|
|
|
*/
|
|
|
|
public Date getOldestEntry() {
|
|
|
|
return oldestEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setOldestEntry(Date oldestEntry) {
|
|
|
|
this.oldestEntry = oldestEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-08-17 18:18:19 +02:00
|
|
|
* Returns the count of the currently available agents in this queue.
|
2004-08-16 02:57:36 +02:00
|
|
|
*
|
2004-08-17 18:18:19 +02:00
|
|
|
* @return the number of active agents in this queue.
|
2004-08-16 02:57:36 +02:00
|
|
|
*/
|
|
|
|
public int getAgentCount() {
|
|
|
|
synchronized (agents) {
|
|
|
|
return agents.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-08-17 18:18:19 +02:00
|
|
|
* Returns an Iterator the currently active agents (Agent instances)
|
|
|
|
* in this queue.
|
2004-08-16 02:57:36 +02:00
|
|
|
*
|
2004-08-17 18:18:19 +02:00
|
|
|
* @return an Iterator for the active agents in this queue.
|
2004-08-16 02:57:36 +02:00
|
|
|
*/
|
|
|
|
public Iterator getAgents() {
|
|
|
|
return Collections.unmodifiableSet(agents).iterator();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAgents(Set agents) {
|
|
|
|
this.agents = agents;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-08-17 18:18:19 +02:00
|
|
|
* Returns the maximum number of simultaneous chats this queue can handle.
|
2004-08-16 02:57:36 +02:00
|
|
|
*
|
2004-08-17 18:18:19 +02:00
|
|
|
* @return the max number of chats this queue can handle.
|
2004-08-16 02:57:36 +02:00
|
|
|
*/
|
|
|
|
public int getMaxChats() {
|
|
|
|
return maxChats;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMaxChats(int maxChats) {
|
|
|
|
this.maxChats = maxChats;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-08-17 18:18:19 +02:00
|
|
|
* Returns the current number of active chat sessions in this queue.
|
2004-08-16 02:57:36 +02:00
|
|
|
*
|
2004-08-17 18:18:19 +02:00
|
|
|
* @return the current number of active chat sessions in this queue.
|
2004-08-16 02:57:36 +02:00
|
|
|
*/
|
|
|
|
public int getCurrentChats() {
|
|
|
|
return currentChats;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setCurrentChats(int currentChats) {
|
|
|
|
this.currentChats = currentChats;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-08-17 18:18:19 +02:00
|
|
|
* Represents the status of the queue. The possible values are:
|
2004-08-16 02:57:36 +02:00
|
|
|
*
|
|
|
|
* <ul>
|
2004-08-17 09:44:36 +02:00
|
|
|
* <li>WorkgroupQueue.Status.OPEN -- the queue is active and accepting
|
|
|
|
* new chat requests.
|
|
|
|
* <li>WorkgroupQueue.Status.ACTIVE -- the queue is active but NOT accepting
|
|
|
|
* new chat requests.
|
|
|
|
* <li>WorkgroupQueue.Status.CLOSED -- the queue is NOT active and NOT
|
|
|
|
* accepting new chat requests.
|
2004-08-16 02:57:36 +02:00
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
public static class Status {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The queue is active and accepting new chat requests.
|
|
|
|
*/
|
|
|
|
public static final Status OPEN = new Status("open");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The queue is active but NOT accepting new chat requests. This state might
|
|
|
|
* occur when the workgroup has closed because regular support hours have closed,
|
|
|
|
* but there are still several requests left in the queue.
|
|
|
|
*/
|
|
|
|
public static final Status ACTIVE = new Status("active");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The queue is NOT active and NOT accepting new chat requests.
|
|
|
|
*/
|
|
|
|
public static final Status CLOSED = new Status("closed");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a String into the corresponding status. Valid String values
|
|
|
|
* that can be converted to a status are: "open", "active", and "closed".
|
|
|
|
*
|
|
|
|
* @param type the String value to covert.
|
|
|
|
* @return the corresponding Type.
|
|
|
|
*/
|
|
|
|
public static Status fromString(String type) {
|
|
|
|
if (type == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
type = type.toLowerCase();
|
|
|
|
if (OPEN.toString().equals(type)) {
|
|
|
|
return OPEN;
|
|
|
|
}
|
|
|
|
else if (ACTIVE.toString().equals(type)) {
|
|
|
|
return ACTIVE;
|
|
|
|
}
|
|
|
|
else if (CLOSED.toString().equals(type)) {
|
|
|
|
return CLOSED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String value;
|
|
|
|
|
|
|
|
private Status(String value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String toString() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|