Commit 9d5d7c27 authored by Axel Brand's avatar Axel Brand Committed by daeva

Gojara Doc

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13680 b35dd754-fafc-0310-a699-88a17e54d16e
parent 804b8573
...@@ -16,16 +16,15 @@ import org.jivesoftware.database.DbConnectionManager; ...@@ -16,16 +16,15 @@ import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
/** /**
* @author Holger Bergunde, Axel-Frederik Brand * @author Holger Bergunde, Axel-Frederik Brand This class is used to store logs in the database. A log entry is
* This class is used to store logs in the database. A * representated by {@link LogEntry}
* log entry is representated by {@link LogEntry}
*/ */
public class DatabaseManager { public class DatabaseManager {
private static Logger Log = Logger.getLogger(DatabaseManager.class); private static Logger Log = Logger.getLogger(DatabaseManager.class);
private static volatile DatabaseManager _myself; private static volatile DatabaseManager _myself;
//Logging // Logging
private static final String COUNT_LOG_ENTRIES = "SELECT count(*) FROM ofGojaraStatistics"; private static final String COUNT_LOG_ENTRIES = "SELECT count(*) FROM ofGojaraStatistics";
private static final String COUNT_PACKAGES_ODLER = "SELECT count(*) FROM ofGojaraStatistics WHERE messageType like ? AND component = ? AND messageDate > ?"; private static final String COUNT_PACKAGES_ODLER = "SELECT count(*) FROM ofGojaraStatistics WHERE messageType like ? AND component = ? AND messageDate > ?";
private static final String GET_ALL_LOGS = "SELECT * FROM ofGojaraStatistics ORDER BY logID desc LIMIT 100"; private static final String GET_ALL_LOGS = "SELECT * FROM ofGojaraStatistics ORDER BY logID desc LIMIT 100";
...@@ -35,17 +34,18 @@ public class DatabaseManager { ...@@ -35,17 +34,18 @@ public class DatabaseManager {
private static final String CLEAN_OLD_DATA = "DELETE FROM ofGojaraStatistics WHERE messageDate < ?"; private static final String CLEAN_OLD_DATA = "DELETE FROM ofGojaraStatistics WHERE messageDate < ?";
private static final String GET_LOGS_DATE_LIMIT_COMPONENT = "SELECT * FROM ofGojaraStatistics WHERE messageDate > ? AND component = ? ORDER BY messageDate DESC LIMIT ?"; private static final String GET_LOGS_DATE_LIMIT_COMPONENT = "SELECT * FROM ofGojaraStatistics WHERE messageDate > ? AND component = ? ORDER BY messageDate DESC LIMIT ?";
private final int _dbCleanMinutes; private final int _dbCleanMinutes;
//Session // Session
private static final String ADD_SESSION_ENTRY = "INSERT INTO ofGojaraSessions(username, transport, lastActivity) VALUES (?,?,?)"; private static final String ADD_SESSION_ENTRY = "INSERT INTO ofGojaraSessions(username, transport, lastActivity) VALUES (?,?,?)";
private static final String UPDATE_SESSION_ENTRY = "UPDATE ofGojaraSessions SET lastActivity = ? WHERE username = ? AND transport = ?"; private static final String UPDATE_SESSION_ENTRY = "UPDATE ofGojaraSessions SET lastActivity = ? WHERE username = ? AND transport = ?";
private static final String GET_SESSION_ENTRIES_FOR_USERNAME = "SELECT * FROM ofGojaraSessions WHERE username = ? ORDER BY lastActivity DESC"; private static final String GET_SESSION_ENTRIES_FOR_USERNAME = "SELECT * FROM ofGojaraSessions WHERE username = ? ORDER BY lastActivity DESC";
private static final String DELETE_SESSION_ENTRY = "DELETE FROM ofGojaraSessions WHERE username = ? AND transport = ?"; private static final String DELETE_SESSION_ENTRY = "DELETE FROM ofGojaraSessions WHERE username = ? AND transport = ?";
private static final String GET_SESSION_COUNT = "SELECT count(*) FROM ofGojaraSessions"; private static final String GET_SESSION_COUNT = "SELECT count(*) FROM ofGojaraSessions";
private DatabaseManager() { private DatabaseManager() {
/* /*
* Load time from globals if it is set. It represents the minutes the * Load time from globals if it is set. It represents the minutes the log entries stay in database until they
* log entries stay in database until they will get deleted * will get deleted
*/ */
// TODO: Use PropertyEventListener to check if cleaner.minutes have // TODO: Use PropertyEventListener to check if cleaner.minutes have
// changed // changed
...@@ -125,8 +125,7 @@ public class DatabaseManager { ...@@ -125,8 +125,7 @@ public class DatabaseManager {
} }
/* /*
* Cleans log entries older than 60 minutes if * Cleans log entries older than 60 minutes if plugin.remoteroster.log.cleaner.minutes is not set
* plugin.remoteroster.log.cleaner.minutes is not set
*/ */
private void cleanOldLogEntries() { private void cleanOldLogEntries() {
Connection con = null; Connection con = null;
...@@ -149,16 +148,13 @@ public class DatabaseManager { ...@@ -149,16 +148,13 @@ public class DatabaseManager {
* Adds new log entry for specified component. * Adds new log entry for specified component.
* *
* @param component * @param component
* subdomain of the external component. e.g. * subdomain of the external component. e.g. icq.myjabberserver.com
* icq.myjabberserver.com
* @param type * @param type
* string representation of the class. normaly it is like * string representation of the class. normaly it is like {@link org.xmpp.packet}
* {@link org.xmpp.packet}
* @param from * @param from
* full qualified JID of user or component this packet was from * full qualified JID of user or component this packet was from
* @param to * @param to
* full qualified JID of user or component this packet was * full qualified JID of user or component this packet was adressed to
* adressed to
*/ */
public void addNewLogEntry(String component, String type, String from, String to) { public void addNewLogEntry(String component, String type, String from, String to) {
Connection con = null; Connection con = null;
...@@ -182,8 +178,7 @@ public class DatabaseManager { ...@@ -182,8 +178,7 @@ public class DatabaseManager {
} }
/** /**
* This method return the last 100 log entries. Every entry is one string * This method return the last 100 log entries. Every entry is one string and added to a ArrayList
* and added to a ArrayList
* *
* @return each log as string in a list * @return each log as string in a list
* */ * */
...@@ -203,8 +198,8 @@ public class DatabaseManager { ...@@ -203,8 +198,8 @@ public class DatabaseManager {
String type = rs.getString(3); String type = rs.getString(3);
String component = rs.getString(6); String component = rs.getString(6);
Timestamp date = rs.getTimestamp(2); Timestamp date = rs.getTimestamp(2);
String res = "From: " + from + " To: " + to + " Type: " + type + " Timestamp: " + date.toString() String res = "From: " + from + " To: " + to + " Type: " + type + " Timestamp: " + date.toString() + "Component: "
+ "Component: " + component; + component;
_result.add(res); _result.add(res);
} }
} }
...@@ -254,16 +249,14 @@ public class DatabaseManager { ...@@ -254,16 +249,14 @@ public class DatabaseManager {
} }
/** /**
* Counts the number of log entries in the databse that are older than * Counts the number of log entries in the databse that are older than specified value
* specified value
* *
* @param component * @param component
* subdomain of the component the packages were flown by * subdomain of the component the packages were flown by
* @param packetClass * @param packetClass
* the class the packet was instance of * the class the packet was instance of
* @param minutes * @param minutes
* the log entry should not be older than (timestamp should be * the log entry should not be older than (timestamp should be smaller than currentTime - minutes)
* smaller than currentTime - minutes)
* @return number of rows found in database or -1 if there was an error * @return number of rows found in database or -1 if there was an error
*/ */
public int getPacketCountOlderThan(String component, @SuppressWarnings("rawtypes") Class packetClass, int minutes) { public int getPacketCountOlderThan(String component, @SuppressWarnings("rawtypes") Class packetClass, int minutes) {
...@@ -289,8 +282,8 @@ public class DatabaseManager { ...@@ -289,8 +282,8 @@ public class DatabaseManager {
} }
/** /**
* Trys to update SessionEntry for given user/transport combination. If update does not * Trys to update SessionEntry for given user/transport combination. If update does not work due to no record being
* work due to no record being there, it inserts record. * there, it inserts record.
*/ */
public void insertOrUpdateSession(String transport, String user, long time) { public void insertOrUpdateSession(String transport, String user, long time) {
Connection con = null; Connection con = null;
...@@ -353,7 +346,7 @@ public class DatabaseManager { ...@@ -353,7 +346,7 @@ public class DatabaseManager {
String user = rs.getString(1); String user = rs.getString(1);
String transport = rs.getString(2); String transport = rs.getString(2);
long lastActivity = rs.getLong(3); long lastActivity = rs.getLong(3);
SessionEntry res = new SessionEntry(user,transport,lastActivity); SessionEntry res = new SessionEntry(user, transport, lastActivity);
result.add(res); result.add(res);
} }
...@@ -369,9 +362,8 @@ public class DatabaseManager { ...@@ -369,9 +362,8 @@ public class DatabaseManager {
public ArrayList<SessionEntry> getAllSessionEntries(String orderAttr, String order) { public ArrayList<SessionEntry> getAllSessionEntries(String orderAttr, String order) {
String allowedAttr = "username transport lastActivity"; String allowedAttr = "username transport lastActivity";
String allowedOrder = "ASC DESC"; String allowedOrder = "ASC DESC";
if ((orderAttr == null || order == null) if ((orderAttr == null || order == null) || (!allowedAttr.contains(orderAttr) || !allowedOrder.contains(order))) {
|| (!allowedAttr.contains(orderAttr) || !allowedOrder.contains(order))) { // Use default case if sorting attributes are not correct.
//Use default case if sorting attributes are not correct.
orderAttr = "username"; orderAttr = "username";
order = "DESC"; order = "DESC";
} }
...@@ -388,7 +380,7 @@ public class DatabaseManager { ...@@ -388,7 +380,7 @@ public class DatabaseManager {
String user = rs.getString(1); String user = rs.getString(1);
String transport = rs.getString(2); String transport = rs.getString(2);
long lastActivity = rs.getLong(3); long lastActivity = rs.getLong(3);
SessionEntry res = new SessionEntry(user,transport,lastActivity); SessionEntry res = new SessionEntry(user, transport, lastActivity);
result.add(res); result.add(res);
} }
pstmt.close(); pstmt.close();
......
...@@ -3,8 +3,9 @@ package org.jivesoftware.openfire.plugin.gojara.sessions; ...@@ -3,8 +3,9 @@ package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.Date; import java.util.Date;
/** /**
* @author axel.frederik.brand
* Class for storing Gateway Session Objects for Iteration for JSP * Class for storing Gateway Session Objects for Iteration for JSP
*
* @author axel.frederik.brand
*/ */
public class GatewaySession { public class GatewaySession {
private String username; private String username;
...@@ -34,5 +35,4 @@ public class GatewaySession { ...@@ -34,5 +35,4 @@ public class GatewaySession {
return "GatewaySession [username=" + username + ", transport=" + transport + ", lastActivity=" + lastActivity + "]"; return "GatewaySession [username=" + username + ", transport=" + transport + ", lastActivity=" + lastActivity + "]";
} }
} }
...@@ -2,7 +2,13 @@ package org.jivesoftware.openfire.plugin.gojara.sessions; ...@@ -2,7 +2,13 @@ package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.Comparator; import java.util.Comparator;
public class SortLastActivity implements Comparator<GatewaySession>{ /**
* Comparator to sort GatewaySessions
*
* @author axel.frederik.brand
*
*/
public class SortLastActivity implements Comparator<GatewaySession> {
public int compare(GatewaySession gws1, GatewaySession gws2) { public int compare(GatewaySession gws1, GatewaySession gws2) {
return gws1.getLastActivity().compareTo(gws2.getLastActivity()); return gws1.getLastActivity().compareTo(gws2.getLastActivity());
......
...@@ -2,7 +2,13 @@ package org.jivesoftware.openfire.plugin.gojara.sessions; ...@@ -2,7 +2,13 @@ package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.Comparator; import java.util.Comparator;
public class SortTransport implements Comparator<GatewaySession>{ /**
* Comparator to sort GatewaySessions
*
* @author axel.frederik.brand
*
*/
public class SortTransport implements Comparator<GatewaySession> {
public int compare(GatewaySession gws1, GatewaySession gws2) { public int compare(GatewaySession gws1, GatewaySession gws2) {
return gws1.getTransport().compareTo(gws2.getTransport()); return gws1.getTransport().compareTo(gws2.getTransport());
......
...@@ -2,7 +2,13 @@ package org.jivesoftware.openfire.plugin.gojara.sessions; ...@@ -2,7 +2,13 @@ package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.util.Comparator; import java.util.Comparator;
public class SortUserName implements Comparator<GatewaySession>{ /**
* Comparator to sort GatewaySessions
*
* @author axel.frederik.brand
*
*/
public class SortUserName implements Comparator<GatewaySession> {
public int compare(GatewaySession gw1, GatewaySession gw2) { public int compare(GatewaySession gw1, GatewaySession gw2) {
return gw1.getUsername().compareTo(gw2.getUsername()); return gw1.getUsername().compareTo(gw2.getUsername());
......
...@@ -13,8 +13,10 @@ import org.slf4j.LoggerFactory; ...@@ -13,8 +13,10 @@ import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
/** /**
* This is the central point for doing anything Gojara GatewaySession related, we can add component session, add
* gatewaysession etc
*
* @author axel.frederik.brand * @author axel.frederik.brand
* This is the central point for doing anything Gojara GatewaySession Related
*/ */
public class TransportSessionManager { public class TransportSessionManager {
private static TransportSessionManager myself; private static TransportSessionManager myself;
...@@ -38,11 +40,21 @@ public class TransportSessionManager { ...@@ -38,11 +40,21 @@ public class TransportSessionManager {
return myself; return myself;
} }
/**
* adds a subdomain to watched transports
*
* @param subdomain
*/
public void addTransport(String subdomain) { public void addTransport(String subdomain) {
transportSessions.put(subdomain, new ConcurrentHashMap<String, Date>()); transportSessions.put(subdomain, new ConcurrentHashMap<String, Date>());
Log.info("Added key to transportSessionMap: " + subdomain); Log.info("Added key to transportSessionMap: " + subdomain);
} }
/**
* removes subdomain from watched transports
*
* @param subdomain
*/
public void removeTransport(String subdomain) { public void removeTransport(String subdomain) {
Map<String, Date> disconnectedUsers = transportSessions.remove(subdomain); Map<String, Date> disconnectedUsers = transportSessions.remove(subdomain);
Log.info("Removed " + subdomain + "from TransportSessionMap " + disconnectedUsers.toString()); Log.info("Removed " + subdomain + "from TransportSessionMap " + disconnectedUsers.toString());
...@@ -52,11 +64,25 @@ public class TransportSessionManager { ...@@ -52,11 +64,25 @@ public class TransportSessionManager {
public boolean isTransportActive(String subdomain) { public boolean isTransportActive(String subdomain) {
return transportSessions.containsKey(subdomain) ? true : false; return transportSessions.containsKey(subdomain) ? true : false;
} }
/**
* register is seperate because a user may register to transport but not connect to it, e.g. with wrong credentials.
* we still want to keep track of those registrations so we know they happened and we can reset them
*
* @param transport
* @param user
*/
public void registerUserTo(String transport, String user) { public void registerUserTo(String transport, String user) {
//This ofc is not a session yet, so we just keep the registration in db to track eventual unsuccessful registers
db.insertOrUpdateSession(transport, user, 0); db.insertOrUpdateSession(transport, user, 0);
} }
/**
* Add the session of user that connected to gateway and update or create timestamp for session
*
* @param transport
* @param user
* @return
*/
public boolean connectUserTo(String transport, String user) { public boolean connectUserTo(String transport, String user) {
if (transportSessions.get(transport) != null) { if (transportSessions.get(transport) != null) {
long millis = System.currentTimeMillis(); long millis = System.currentTimeMillis();
...@@ -82,6 +108,14 @@ public class TransportSessionManager { ...@@ -82,6 +108,14 @@ public class TransportSessionManager {
return transportSessions.get(transport).containsKey(user); return transportSessions.get(transport).containsKey(user);
} }
/**
* Removing a registration will cause a unregister msg being sent to Spectrum2 for this specific User/Gateway
* combination Also it will be removed from our db.
*
* @param transport
* @param user
* @return
*/
public String removeRegistrationOfUser(String transport, String user) { public String removeRegistrationOfUser(String transport, String user) {
int result = db.removeSessionEntry(transport, user); int result = db.removeSessionEntry(transport, user);
if (result == 0) { if (result == 0) {
...@@ -97,14 +131,17 @@ public class TransportSessionManager { ...@@ -97,14 +131,17 @@ public class TransportSessionManager {
return transportSessions; return transportSessions;
} }
/** /**
* Puts all Sessions into an ArrayList of GatewaySession Objects, and sorts it according to specified sorting attributes. * Puts all Sessions into an ArrayList of GatewaySession Objects, and sorts it according to specified sorting
* @param sortby username, transport or LoginTime * attributes.
* @param sortorder ASC or DESC *
* @param sortby
* username, transport or LoginTime
* @param sortorder
* ASC or DESC
* @return Sorted/Unsorted ArrayList of GatewaySession Objects * @return Sorted/Unsorted ArrayList of GatewaySession Objects
*/ */
public ArrayList<GatewaySession> getSessionsSorted(String sortby, String sortorder){ public ArrayList<GatewaySession> getSessionsSorted(String sortby, String sortorder) {
ArrayList<GatewaySession> result = new ArrayList<GatewaySession>(); ArrayList<GatewaySession> result = new ArrayList<GatewaySession>();
for (String key : transportSessions.keySet()) { for (String key : transportSessions.keySet()) {
for (String user : transportSessions.get(key).keySet()) { for (String user : transportSessions.get(key).keySet()) {
...@@ -119,13 +156,12 @@ public class TransportSessionManager { ...@@ -119,13 +156,12 @@ public class TransportSessionManager {
} else if (sortby.equals("loginTime")) { } else if (sortby.equals("loginTime")) {
Collections.sort(result, new SortLastActivity()); Collections.sort(result, new SortLastActivity());
} }
if (sortorder.equals("DESC")){ if (sortorder.equals("DESC")) {
Collections.reverse(result); Collections.reverse(result);
} }
return result; return result;
} }
/** /**
* @return count of recognized active Sessions * @return count of recognized active Sessions
*/ */
...@@ -139,6 +175,7 @@ public class TransportSessionManager { ...@@ -139,6 +175,7 @@ public class TransportSessionManager {
/** /**
* Searches for Sessions with given Username and returns them as ArrList * Searches for Sessions with given Username and returns them as ArrList
*
* @param username * @param username
* @return * @return
*/ */
...@@ -153,8 +190,10 @@ public class TransportSessionManager { ...@@ -153,8 +190,10 @@ public class TransportSessionManager {
} }
return userconnections; return userconnections;
} }
/** /**
* Returns Registrations associated with Username * Returns Registrations associated with Username
*
* @param username * @param username
* @return ArrayList of SessionEntries * @return ArrayList of SessionEntries
*/ */
...@@ -163,8 +202,8 @@ public class TransportSessionManager { ...@@ -163,8 +202,8 @@ public class TransportSessionManager {
} }
/** /**
* Validation for correctness of attributes is done in DB Manager, returns default sorting: username ASC when not * Get all registrations sorted by attribute and order. Validation for correctness of attributes is done in DB
* correct * Manager, returns default sorting: username ASC when not valid
*/ */
public ArrayList<SessionEntry> getAllRegistrations(String orderAttr, String order) { public ArrayList<SessionEntry> getAllRegistrations(String orderAttr, String order) {
return db.getAllSessionEntries(orderAttr, order); return db.getAllSessionEntries(orderAttr, order);
......
...@@ -5,12 +5,14 @@ import java.util.Date; ...@@ -5,12 +5,14 @@ import java.util.Date;
import java.util.Map; import java.util.Map;
/** /**
* @author axel.frederik.brand * @author axel.frederik.brand Helper for some functions we call from gojara registration / session jsps
* Helper for generating specificly linked helper columns.
*/ */
public class JspHelper { public class JspHelper {
/** /**
* Create a link that leads to the same page, sorted by the attribute clicked on. The sorting Order depends on the
* current sorting order. If element is not the one currently sorted by, its always ASC, else DESC
*
* @param column * @param column
* @param sortParams * @param sortParams
* @return String with html in it * @return String with html in it
...@@ -57,7 +59,9 @@ public class JspHelper { ...@@ -57,7 +59,9 @@ public class JspHelper {
} }
/** /**
* Compares specified date to current date and returns String explaining how much Minutes / Hours / Days has passed since then * Compares specified date to current date and returns String explaining how much Minutes / Hours / Days has passed
* since then
*
* @param oldDate * @param oldDate
* @return * @return
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment