Shuyi Chen | d7955ce | 2013-05-22 14:51:55 -0700 | [diff] [blame] | 1 | /**
|
| 2 | * $Revision$
|
| 3 | * $Date$
|
| 4 | *
|
| 5 | * Copyright 2003-2007 Jive Software.
|
| 6 | *
|
| 7 | * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 | * you may not use this file except in compliance with the License.
|
| 9 | * You may obtain a copy of the License at
|
| 10 | *
|
| 11 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 12 | *
|
| 13 | * Unless required by applicable law or agreed to in writing, software
|
| 14 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 | * See the License for the specific language governing permissions and
|
| 17 | * limitations under the License.
|
| 18 | */
|
| 19 |
|
| 20 | package org.jivesoftware.smackx.workgroup.agent;
|
| 21 |
|
| 22 | import java.util.*;
|
| 23 |
|
| 24 | import org.jivesoftware.smackx.workgroup.QueueUser;
|
| 25 |
|
| 26 | /**
|
| 27 | * A queue in a workgroup, which is a pool of agents that are routed a specific type of
|
| 28 | * chat request.
|
| 29 | */
|
| 30 | public class WorkgroupQueue {
|
| 31 |
|
| 32 | private String name;
|
| 33 | private Status status = Status.CLOSED;
|
| 34 |
|
| 35 | private int averageWaitTime = -1;
|
| 36 | private Date oldestEntry = null;
|
| 37 | private Set<QueueUser> users = Collections.emptySet();
|
| 38 |
|
| 39 | private int maxChats = 0;
|
| 40 | private int currentChats = 0;
|
| 41 |
|
| 42 | /**
|
| 43 | * Creates a new workgroup queue instance.
|
| 44 | *
|
| 45 | * @param name the name of the queue.
|
| 46 | */
|
| 47 | WorkgroupQueue(String name) {
|
| 48 | this.name = name;
|
| 49 | }
|
| 50 |
|
| 51 | /**
|
| 52 | * Returns the name of the queue.
|
| 53 | *
|
| 54 | * @return the name of the queue.
|
| 55 | */
|
| 56 | public String getName() {
|
| 57 | return name;
|
| 58 | }
|
| 59 |
|
| 60 | /**
|
| 61 | * Returns the status of the queue.
|
| 62 | *
|
| 63 | * @return the status of the queue.
|
| 64 | */
|
| 65 | public Status getStatus() {
|
| 66 | return status;
|
| 67 | }
|
| 68 |
|
| 69 | void setStatus(Status status) {
|
| 70 | this.status = status;
|
| 71 | }
|
| 72 |
|
| 73 | /**
|
| 74 | * Returns the number of users waiting in the queue waiting to be routed to
|
| 75 | * an agent.
|
| 76 | *
|
| 77 | * @return the number of users waiting in the queue.
|
| 78 | */
|
| 79 | public int getUserCount() {
|
| 80 | if (users == null) {
|
| 81 | return 0;
|
| 82 | }
|
| 83 | return users.size();
|
| 84 | }
|
| 85 |
|
| 86 | /**
|
| 87 | * Returns an Iterator for the users in the queue waiting to be routed to
|
| 88 | * an agent (QueueUser instances).
|
| 89 | *
|
| 90 | * @return an Iterator for the users waiting in the queue.
|
| 91 | */
|
| 92 | public Iterator<QueueUser> getUsers() {
|
| 93 | if (users == null) {
|
| 94 | return new HashSet<QueueUser>().iterator();
|
| 95 | }
|
| 96 | return Collections.unmodifiableSet(users).iterator();
|
| 97 | }
|
| 98 |
|
| 99 | void setUsers(Set<QueueUser> users) {
|
| 100 | this.users = users;
|
| 101 | }
|
| 102 |
|
| 103 | /**
|
| 104 | * Returns the average amount of time users wait in the queue before being
|
| 105 | * routed to an agent. If average wait time info isn't available, -1 will
|
| 106 | * be returned.
|
| 107 | *
|
| 108 | * @return the average wait time
|
| 109 | */
|
| 110 | public int getAverageWaitTime() {
|
| 111 | return averageWaitTime;
|
| 112 | }
|
| 113 |
|
| 114 | void setAverageWaitTime(int averageTime) {
|
| 115 | this.averageWaitTime = averageTime;
|
| 116 | }
|
| 117 |
|
| 118 | /**
|
| 119 | * Returns the date of the oldest request waiting in the queue. If there
|
| 120 | * are no requests waiting to be routed, this method will return <tt>null</tt>.
|
| 121 | *
|
| 122 | * @return the date of the oldest request in the queue.
|
| 123 | */
|
| 124 | public Date getOldestEntry() {
|
| 125 | return oldestEntry;
|
| 126 | }
|
| 127 |
|
| 128 | void setOldestEntry(Date oldestEntry) {
|
| 129 | this.oldestEntry = oldestEntry;
|
| 130 | }
|
| 131 |
|
| 132 | /**
|
| 133 | * Returns the maximum number of simultaneous chats the queue can handle.
|
| 134 | *
|
| 135 | * @return the max number of chats the queue can handle.
|
| 136 | */
|
| 137 | public int getMaxChats() {
|
| 138 | return maxChats;
|
| 139 | }
|
| 140 |
|
| 141 | void setMaxChats(int maxChats) {
|
| 142 | this.maxChats = maxChats;
|
| 143 | }
|
| 144 |
|
| 145 | /**
|
| 146 | * Returns the current number of active chat sessions in the queue.
|
| 147 | *
|
| 148 | * @return the current number of active chat sessions in the queue.
|
| 149 | */
|
| 150 | public int getCurrentChats() {
|
| 151 | return currentChats;
|
| 152 | }
|
| 153 |
|
| 154 | void setCurrentChats(int currentChats) {
|
| 155 | this.currentChats = currentChats;
|
| 156 | }
|
| 157 |
|
| 158 | /**
|
| 159 | * A class to represent the status of the workgroup. The possible values are:
|
| 160 | *
|
| 161 | * <ul>
|
| 162 | * <li>WorkgroupQueue.Status.OPEN -- the queue is active and accepting new chat requests.
|
| 163 | * <li>WorkgroupQueue.Status.ACTIVE -- the queue is active but NOT accepting new chat
|
| 164 | * requests.
|
| 165 | * <li>WorkgroupQueue.Status.CLOSED -- the queue is NOT active and NOT accepting new
|
| 166 | * chat requests.
|
| 167 | * </ul>
|
| 168 | */
|
| 169 | public static class Status {
|
| 170 |
|
| 171 | /**
|
| 172 | * The queue is active and accepting new chat requests.
|
| 173 | */
|
| 174 | public static final Status OPEN = new Status("open");
|
| 175 |
|
| 176 | /**
|
| 177 | * The queue is active but NOT accepting new chat requests. This state might
|
| 178 | * occur when the workgroup has closed because regular support hours have closed,
|
| 179 | * but there are still several requests left in the queue.
|
| 180 | */
|
| 181 | public static final Status ACTIVE = new Status("active");
|
| 182 |
|
| 183 | /**
|
| 184 | * The queue is NOT active and NOT accepting new chat requests.
|
| 185 | */
|
| 186 | public static final Status CLOSED = new Status("closed");
|
| 187 |
|
| 188 | /**
|
| 189 | * Converts a String into the corresponding status. Valid String values
|
| 190 | * that can be converted to a status are: "open", "active", and "closed".
|
| 191 | *
|
| 192 | * @param type the String value to covert.
|
| 193 | * @return the corresponding Type.
|
| 194 | */
|
| 195 | public static Status fromString(String type) {
|
| 196 | if (type == null) {
|
| 197 | return null;
|
| 198 | }
|
| 199 | type = type.toLowerCase();
|
| 200 | if (OPEN.toString().equals(type)) {
|
| 201 | return OPEN;
|
| 202 | }
|
| 203 | else if (ACTIVE.toString().equals(type)) {
|
| 204 | return ACTIVE;
|
| 205 | }
|
| 206 | else if (CLOSED.toString().equals(type)) {
|
| 207 | return CLOSED;
|
| 208 | }
|
| 209 | else {
|
| 210 | return null;
|
| 211 | }
|
| 212 | }
|
| 213 |
|
| 214 | private String value;
|
| 215 |
|
| 216 | private Status(String value) {
|
| 217 | this.value = value;
|
| 218 | }
|
| 219 |
|
| 220 | public String toString() {
|
| 221 | return value;
|
| 222 | }
|
| 223 | }
|
| 224 | } |