📄 chathistoryutils.java
字号:
* Returns an iterator of all sessionID's in the system.
*
* @return an iterator of sessionID's.
*/
public static Iterator<String> getSessionIDs() {
final List<String> sessionList = new ArrayList<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(ALL_SESSIONS);
rs = pstmt.executeQuery();
while (rs.next()) {
sessionList.add(rs.getString(1));
}
}
catch (Exception ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return sessionList.iterator();
}
/**
* Returns the number of canceled requests.
*
* @param workgroupName the workgroup to search
* @param startDate the time to begin the search from.
* @param endDate the time to end the search.
* @return the total number of requests
*/
public static int getNumberOfRequestsNeverPickedUp(String workgroupName, Date startDate, Date endDate) {
Workgroup workgroup = null;
try {
workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
}
catch (Exception ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
if (workgroup == null) {
return 0;
}
int count = 0;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(WORKGROUP_STATE_REQUEST_COUNT);
pstmt.setLong(1, workgroup.getID());
// Set the state the ignored requests.
pstmt.setInt(2, 1);
pstmt.setString(3, StringUtils.dateToMillis(startDate));
pstmt.setString(4, StringUtils.dateToMillis(endDate));
rs = pstmt.executeQuery();
if (rs.next()) {
count = rs.getInt(1);
}
}
catch (Exception ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return count;
}
/**
* Returns the total number of chats that have occured within a workgroup.
*
* @param workgroupName the jid of the workgroup.
* @return the total number of chats that have occured within a workgroup.
*/
public static int getNumberOfChatsForWorkgroup(String workgroupName) {
Workgroup workgroup = null;
try {
workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
}
catch (Exception ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
int count = 0;
for (RequestQueue requestQueue : workgroup.getRequestQueues()){
count += requestQueue.getTotalChatCount();
}
return count;
}
/**
* Returns the average wait time in the system.
*
* @return the average wait time.
*/
public static String getAverageWaitTimeForServer() {
int totalRequests = getTotalRequestCountForSystem();
long totalWaitTime = getTotalWaitTimeForServer();
if (totalRequests == 0 ) {
return "0 sec.";
}
long averageWaitTime = totalWaitTime / totalRequests;
return getDateFromLong(averageWaitTime);
}
/**
* Returns the average wait time for a specified workgroup between two dates.
*
* @param workgroupName the Live Assistant Workgroup.
* @param startDate the startDate.
* @param endTime the end date.
* @return the average wait time for this workgroup.
*/
public static long getAverageWaitTimeForWorkgroup(String workgroupName, Date startDate, Date endTime) {
int totalRequests = getNumberOfRequestsForWorkgroup(workgroupName, startDate, endTime);
long waitTime = getTotalWaitTimeForWorkgroup(workgroupName, startDate, endTime);
if (totalRequests == 0) {
return 0;
}
return waitTime / totalRequests;
}
/**
* Returns the total number of chats.
*
* @return the total number of chats.
*/
public static int getTotalChatsInSystem() {
int count = 0;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(ALL_CHATS_COUNT);
rs = pstmt.executeQuery();
rs.next();
count = rs.getInt(1);
}
catch (SQLException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return count;
}
/**
* Retruns the total number of requests.
*
* @return the total number of requests.
*/
public static int getTotalRequestCountForSystem() {
int count = 0;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(ALL_REQUESTS_COUNT);
rs = pstmt.executeQuery();
rs.next();
count = rs.getInt(1);
}
catch (SQLException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return count;
}
/**
* Returns the total waitTime for all incoming requests.
*
* @return the total wait time.
*/
public static long getTotalWaitTimeForServer() {
int totalWaitTime = 0;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(TOTAL_WAIT_TIME);
rs = pstmt.executeQuery();
rs.next();
totalWaitTime = rs.getInt(1);
}
catch (SQLException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return totalWaitTime;
}
/**
* Returns the number of canceled requests.
*
* @param workgroupName the workgroup to search
* @param startDate the time to begin the search from.
* @param endDate the time to end the search.
* @return the total number of requests
*/
public static long getTotalWaitTimeForWorkgroup(String workgroupName, Date startDate, Date endDate) {
Workgroup workgroup = null;
try {
workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
}
catch (Exception ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
if (workgroup == null) {
return 0;
}
int waitTime = 0;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(WORKGROUP_WAIT_TIME);
pstmt.setLong(1, workgroup.getID());
// Set the state the ignored requests.
pstmt.setInt(2, 1);
pstmt.setString(2, StringUtils.dateToMillis(startDate));
pstmt.setString(3, StringUtils.dateToMillis(endDate));
rs = pstmt.executeQuery();
rs.next();
waitTime = rs.getInt(1);
}
catch (Exception ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return waitTime;
}
/**
* Returns a formatted string to display minutes and seconds.
*
* @param time the number of milliseconds.
* @return a formatted string.
*/
public static String getDateFromLong(long time) {
int aTime;
int minutes;
int seconds;
String displayString;
if (time > 0) {
aTime = (int) (time) / 1000;
minutes = aTime / 60;
seconds = aTime % 60;
if (minutes != 0) {
displayString = minutes + " min, " + seconds + " sec.";
}
else {
displayString = seconds + " seconds";
}
}
else {
return "0 seconds";
}
return displayString;
}
/**
* Returns a <code>Workgroup</code> based on it's full jid.
* @param workgroupJID the full jid of the workgroup (ex. demo@workgroup.jivesoftware.com)
* @return the Workgroup
*/
public static Workgroup getWorkgroup(String workgroupJID) {
Workgroup workgroup = null;
try {
workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupJID));
}
catch (UserNotFoundException e) {
ComponentManagerFactory.getComponentManager().getLog().error("Error retrieving Workgroup", e);
}
return workgroup;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -