001/** 002 * 003 * Copyright 2003-2007 Jive Software. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.jivesoftware.smackx.workgroup.agent; 019 020import java.util.*; 021 022import org.jivesoftware.smackx.workgroup.QueueUser; 023 024/** 025 * A queue in a workgroup, which is a pool of agents that are routed a specific type of 026 * chat request. 027 */ 028public class WorkgroupQueue { 029 030 private String name; 031 private Status status = Status.CLOSED; 032 033 private int averageWaitTime = -1; 034 private Date oldestEntry = null; 035 private Set<QueueUser> users = Collections.emptySet(); 036 037 private int maxChats = 0; 038 private int currentChats = 0; 039 040 /** 041 * Creates a new workgroup queue instance. 042 * 043 * @param name the name of the queue. 044 */ 045 WorkgroupQueue(String name) { 046 this.name = name; 047 } 048 049 /** 050 * Returns the name of the queue. 051 * 052 * @return the name of the queue. 053 */ 054 public String getName() { 055 return name; 056 } 057 058 /** 059 * Returns the status of the queue. 060 * 061 * @return the status of the queue. 062 */ 063 public Status getStatus() { 064 return status; 065 } 066 067 void setStatus(Status status) { 068 this.status = status; 069 } 070 071 /** 072 * Returns the number of users waiting in the queue waiting to be routed to 073 * an agent. 074 * 075 * @return the number of users waiting in the queue. 076 */ 077 public int getUserCount() { 078 if (users == null) { 079 return 0; 080 } 081 return users.size(); 082 } 083 084 /** 085 * Returns an Iterator for the users in the queue waiting to be routed to 086 * an agent (QueueUser instances). 087 * 088 * @return an Iterator for the users waiting in the queue. 089 */ 090 public Iterator<QueueUser> getUsers() { 091 if (users == null) { 092 return new HashSet<QueueUser>().iterator(); 093 } 094 return Collections.unmodifiableSet(users).iterator(); 095 } 096 097 void setUsers(Set<QueueUser> users) { 098 this.users = users; 099 } 100 101 /** 102 * Returns the average amount of time users wait in the queue before being 103 * routed to an agent. If average wait time info isn't available, -1 will 104 * be returned. 105 * 106 * @return the average wait time 107 */ 108 public int getAverageWaitTime() { 109 return averageWaitTime; 110 } 111 112 void setAverageWaitTime(int averageTime) { 113 this.averageWaitTime = averageTime; 114 } 115 116 /** 117 * Returns the date of the oldest request waiting in the queue. If there 118 * are no requests waiting to be routed, this method will return <tt>null</tt>. 119 * 120 * @return the date of the oldest request in the queue. 121 */ 122 public Date getOldestEntry() { 123 return oldestEntry; 124 } 125 126 void setOldestEntry(Date oldestEntry) { 127 this.oldestEntry = oldestEntry; 128 } 129 130 /** 131 * Returns the maximum number of simultaneous chats the queue can handle. 132 * 133 * @return the max number of chats the queue can handle. 134 */ 135 public int getMaxChats() { 136 return maxChats; 137 } 138 139 void setMaxChats(int maxChats) { 140 this.maxChats = maxChats; 141 } 142 143 /** 144 * Returns the current number of active chat sessions in the queue. 145 * 146 * @return the current number of active chat sessions in the queue. 147 */ 148 public int getCurrentChats() { 149 return currentChats; 150 } 151 152 void setCurrentChats(int currentChats) { 153 this.currentChats = currentChats; 154 } 155 156 /** 157 * A class to represent the status of the workgroup. The possible values are: 158 * 159 * <ul> 160 * <li>WorkgroupQueue.Status.OPEN -- the queue is active and accepting new chat requests. 161 * <li>WorkgroupQueue.Status.ACTIVE -- the queue is active but NOT accepting new chat 162 * requests. 163 * <li>WorkgroupQueue.Status.CLOSED -- the queue is NOT active and NOT accepting new 164 * chat requests. 165 * </ul> 166 */ 167 public static class Status { 168 169 /** 170 * The queue is active and accepting new chat requests. 171 */ 172 public static final Status OPEN = new Status("open"); 173 174 /** 175 * The queue is active but NOT accepting new chat requests. This state might 176 * occur when the workgroup has closed because regular support hours have closed, 177 * but there are still several requests left in the queue. 178 */ 179 public static final Status ACTIVE = new Status("active"); 180 181 /** 182 * The queue is NOT active and NOT accepting new chat requests. 183 */ 184 public static final Status CLOSED = new Status("closed"); 185 186 /** 187 * Converts a String into the corresponding status. Valid String values 188 * that can be converted to a status are: "open", "active", and "closed". 189 * 190 * @param type the String value to covert. 191 * @return the corresponding Type. 192 */ 193 public static Status fromString(String type) { 194 if (type == null) { 195 return null; 196 } 197 type = type.toLowerCase(Locale.US); 198 if (OPEN.toString().equals(type)) { 199 return OPEN; 200 } 201 else if (ACTIVE.toString().equals(type)) { 202 return ACTIVE; 203 } 204 else if (CLOSED.toString().equals(type)) { 205 return CLOSED; 206 } 207 else { 208 return null; 209 } 210 } 211 212 private String value; 213 214 private Status(String value) { 215 this.value = value; 216 } 217 218 public String toString() { 219 return value; 220 } 221 } 222}