📄 requestqueue.java
字号:
}
public boolean isMember(Agent agent) {
if (agents.contains(agent)) {
return true;
}
for (Group group : getGroupObjects()) {
if (group.isUser(agent.getAgentJID())) {
return true;
}
}
return false;
}
public boolean hasGroup(Group group) {
return groups.contains(group.getName());
}
public void addGroup(Group group) {
if (!groups.contains(group.getName())) {
boolean added = insertGroup(group.getName());
if (added) {
groups.add(group.getName());
WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
AgentManager agentManager = workgroupManager.getAgentManager();
for (Agent agent : agentManager.getAgents(group)) {
agent.sendAgentAddedToAllAgents(this);
}
}
}
}
public void removeGroup(Group group) {
deleteGroup(group.getName());
if (groups.remove(group.getName())) {
for (Agent agent : agentManager.getAgents(group)) {
agent.sendAgentRemovedToAllAgents(this);
// Remove agent if necessary.
agentManager.removeAgentIfNecessary(agent);
}
}
}
// ##########################################################################
// Request Queue as agent group methods
// ##########################################################################
public int getMemberCount() {
int count = getMembers().size();
for (Group group : getGroups()) {
count += group.getMembers().size();
}
return count;
}
/**
* Adds an individual agent to the RequestQueue.
* @param agent the agent to add.
*/
public void addMember(Agent agent) {
if (!agents.contains(agent)) {
boolean added = addAgentToDb(agent.getID(), Boolean.FALSE);
if (added) {
agents.add(agent);
// Ask the new agent to notify the other agents of the queue of the new addition
agent.sendAgentAddedToAllAgents(this);
}
}
}
/**
* Removes an agent from the RequestQueue.
* @param agent the agent to remove.
*/
public void removeMember(Agent agent) {
deleteObject(agent.getID(), Boolean.FALSE);
agents.remove(agent);
// Remove agent if necessary
agentManager.removeAgentIfNecessary(agent);
// Ask the deleted agent to notify the other agents of the queue of the deletion
agent.sendAgentRemovedToAllAgents(this);
}
/**
* Returns members belong to this RequestQueue. Note, members does not include
* users belonging to Groups.
*
* @return a collection of queue members.
*/
public Collection<Agent> getMembers() {
final Set<Agent> agentList = new HashSet<Agent>(agents);
return Collections.unmodifiableCollection(agentList);
}
// #########################################################################
// Persistent accessor methods calls
// #########################################################################
public String getName() {
return name;
}
public void setName(String newName) {
// Handle empty string.
if (!ModelUtil.hasLength(newName)) {
return;
}
presenceAvailable = false;
try {
activeAgents.broadcastQueueStatus(this);
}
finally {
presenceAvailable = true;
}
this.name = newName;
JID workgroupJID = workgroup.getJID();
address = new JID(workgroupJID.getNode(), workgroupJID.getDomain(), this.name);
updateQueue();
activeAgents.broadcastQueueStatus(this);
}
public void setDescription(String description) {
this.description = description;
updateQueue();
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
}
public Date getModificationDate() {
return null;
}
public void setModificationDate(Date modificationDate) {
}
public String getDescription() {
return description;
}
public DbProperties getProperties() {
if (properties == null) {
properties = new JiveLiveProperties("jlaQueueProp", id);
}
return properties;
}
public RequestQueue.OverflowType getOverflowType() {
return overflowType;
}
public void setOverflowType(RequestQueue.OverflowType type) {
if (type != null) {
overflowType = type;
updateQueue();
}
}
public RequestQueue getBackupQueue() {
RequestQueue queue = null;
if (backupQueueID > 0) {
try {
queue = workgroup.getRequestQueue(backupQueueID);
}
catch (NotFoundException e) {
ComponentManagerFactory.getComponentManager().getLog().error(
"Backup queue with ID " + backupQueueID + " not found", e);
queue = null;
}
}
return queue;
}
public void setBackupQueue(RequestQueue queue) {
backupQueueID = queue.getID();
updateQueue();
}
private static final int AGENT_TYPE = 0;
private static final int GROUP_TYPE = 1;
private void loadQueue() {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_QUEUE);
pstmt.setLong(1, id);
rs = pstmt.executeQuery();
rs.next();
name = rs.getString(1);
address = new JID(workgroup.getJID().getNode(), workgroup.getJID().getDomain(), name);
description = rs.getString(2);
priority = rs.getInt(3);
maxChats = rs.getInt(4);
minChats = rs.getInt(5);
switch (rs.getInt(6)) {
case 1:
overflowType = OverflowType.OVERFLOW_RANDOM;
break;
case 2:
overflowType = OverflowType.OVERFLOW_BACKUP;
break;
default:
overflowType = OverflowType.OVERFLOW_NONE;
}
backupQueueID = rs.getLong(7);
}
catch (SQLException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
}
private void updateQueue() {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(UPDATE_QUEUE);
pstmt.setString(1, name);
pstmt.setString(2, description);
pstmt.setInt(3, priority);
pstmt.setInt(4, maxChats);
pstmt.setInt(5, minChats);
pstmt.setInt(6, overflowType.ordinal());
pstmt.setLong(7, backupQueueID);
pstmt.setLong(8, id);
pstmt.executeUpdate();
}
catch (SQLException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
private boolean deleteObject(long objectID, Object data) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_QUEUE);
if ((Boolean)data) {
pstmt.setInt(1, GROUP_TYPE);
}
else {
pstmt.setInt(1, AGENT_TYPE);
}
pstmt.setLong(2, objectID);
pstmt.setLong(3, id);
pstmt.executeUpdate();
return true;
}
catch (SQLException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return false;
}
private boolean addAgentToDb(long objectID, Object data) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(ADD_QUEUE_AGENT);
if ((Boolean)data) {
pstmt.setInt(1, GROUP_TYPE);
}
else {
pstmt.setInt(1, AGENT_TYPE);
}
pstmt.setLong(2, objectID);
pstmt.setLong(3, id);
pstmt.executeUpdate();
return true;
}
catch (SQLException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return false;
}
private boolean insertGroup(String groupName) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(ADD_QUEUE_GROUP);
pstmt.setLong(1, id);
pstmt.setString(2, groupName);
pstmt.executeUpdate();
return true;
}
catch (SQLException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return false;
}
private boolean deleteGroup(String groupName) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_QUEUE_GROUP);
pstmt.setLong(1, id);
pstmt.setString(2, groupName);
pstmt.executeUpdate();
return true;
}
catch (SQLException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return false;
}
private void loadGroups() {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_QUEUE_GROUPS);
pstmt.setLong(1, id);
rs = pstmt.executeQuery();
while (rs.next()) {
groups.add(rs.getString(1));
}
}
catch (Exception e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
}
private void loadAgents() {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_AGENTS);
pstmt.setLong(1, id);
pstmt.setInt(2, AGENT_TYPE);
rs = pstmt.executeQuery();
AgentManager agentManager = workgroup.getAgentManager();
while (rs.next()) {
try {
Agent agent = agentManager.getAgent(rs.getLong(1));
agents.add(agent);
}
catch (AgentNotFoundException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
}
}
catch (SQLException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
}
// Stats Implementation
public int getTotalChatCount() {
return totalChatCount;
}
public int getTotalRequestCount() {
return totalRequestCount;
}
public int getDroppedRequestCount() {
return totalDroppedRequests;
}
public JID getAddress() {
if (address == null) {
throw new IllegalStateException();
}
return address;
}
public long getID() {
return id;
}
public String getUsername() {
return address.getNode().toLowerCase();
}
public void shutdown() {
dispatcher.shutdown();
}
/**
* Defines the overflow types available for queues.
*
* @author Iain Shigeoka
*/
public static enum OverflowType {
/**
* Requests are not overflowed to other queues.
*/
OVERFLOW_NONE,
/**
* Requests that aren't handled are overflowed to a random available queue.
*/
OVERFLOW_RANDOM,
/**
* Requests that aren't handled are overflowed to the queue's backup queue.
*/
OVERFLOW_BACKUP
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -