Changeset 871 for trunk/autoquest-htmlmonitor
- Timestamp:
- 10/12/12 15:08:45 (12 years ago)
- Location:
- trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlClientInfos.java
r870 r871 10 10 * @author Patrick Harms 11 11 */ 12 publicclass HtmlClientInfos {12 class HtmlClientInfos { 13 13 14 14 /** -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorComponent.java
r870 r871 10 10 * @author Patrick Harms 11 11 */ 12 publicinterface HtmlMonitorComponent {12 interface HtmlMonitorComponent { 13 13 14 14 /** -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorException.java
r870 r871 9 9 * @author Patrick Harms 10 10 */ 11 publicclass HtmlMonitorException extends Exception {11 class HtmlMonitorException extends Exception { 12 12 13 13 /** */ … … 21 21 * @param message the message of the exception 22 22 */ 23 publicHtmlMonitorException(String message) {23 HtmlMonitorException(String message) { 24 24 super(message); 25 25 } … … 33 33 * @param cause the root cause of the exception 34 34 */ 35 publicHtmlMonitorException(String message, Throwable cause) {35 HtmlMonitorException(String message, Throwable cause) { 36 36 super(message, cause); 37 37 } -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorLogManager.java
r857 r871 12 12 /** 13 13 * <p> 14 * TODO comment 14 * The log manager handles different {@link HtmlMonitorOutputWriter}s to perform the logging 15 * of recorded messages. It initializes a new writer if the first message for a specific 16 * client is received and it closes a writer if for a specific period of time no further message 17 * of the same client was received. The writers themselves consider log rotation. For handling 18 * messages, the {@link HtmlMonitorMessageListener} mechanism provided by the 19 * {@link HtmlMonitorServer} is used. 15 20 * </p> 16 21 * 17 22 * @author Patrick Harms 18 23 */ 19 publicclass HtmlMonitorLogManager implements HtmlMonitorComponent, HtmlMonitorMessageListener {24 class HtmlMonitorLogManager implements HtmlMonitorComponent, HtmlMonitorMessageListener { 20 25 21 26 /** 22 * 27 * the timeout after which a writer of an inactive client is closed 23 28 */ 24 29 private static final int SESSION_TIMEOUT = 100000; 25 30 26 31 /** 27 * 32 * the directory into which the log files shall be written 28 33 */ 29 34 private String logFileBaseDir; 30 35 31 36 /** 32 * 37 * the mapping of client ids to the respective writers. 33 38 */ 34 39 private Map<String, HtmlMonitorOutputWriter> writers; 35 40 36 41 /** 37 * 42 * a timer used to detect client timouts 38 43 */ 39 44 private Timer logFileMonitorTimer; … … 41 46 /** 42 47 * <p> 43 * TODO: comment48 * initializes the log manager with the directory into which the log files shall be stored 44 49 * </p> 45 50 * 46 * @param logFileBaseDir 51 * @param logFileBaseDir the directory into which the log files shall be stored 47 52 */ 48 53 HtmlMonitorLogManager(String logFileBaseDir) { … … 93 98 94 99 /* (non-Javadoc) 95 * @see de.ugoe.cs.autoquest.htmlmonitor.HtmlMonitoringListener#handleEvents(de.ugoe.cs.quest.htmlmonitor.HtmlClientInfos, de.ugoe.cs.quest.htmlmonitor.HtmlEvent[])100 * @see HtmlMonitoringListener#handleEvents(HtmlClientInfos, HtmlEvent[]) 96 101 */ 97 102 @Override … … 139 144 /** 140 145 * <p> 141 * TODO comment146 * internal timer task used for detecting session timeouts of clients 142 147 * </p> 143 148 * -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorMessageListener.java
r857 r871 3 3 /** 4 4 * <p> 5 * TODO comment 5 * a message listener to be registered with the {@link HtmlMonitorServer} for being called for 6 * new messages send by clients. 6 7 * </p> 7 8 * … … 12 13 /** 13 14 * <p> 14 * TODO: comment 15 * called for new messages received from a client. The client is described through the 16 * <code>clientInfos</code>. The events are several events that were recorded at client side. 15 17 * </p> 16 18 * 17 * @param clientInfos 18 * @param events 19 * @param clientInfos infos about the client that send the events 20 * @param events the received events 19 21 */ 20 22 void handleMessage(HtmlClientInfos clientInfos, HtmlEvent[] events); -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorOutputWriter.java
r857 r871 11 11 /** 12 12 * <p> 13 * comment 13 * dumps messages to a log file belonging to a specific client id. In the provided base log 14 * directory, it creates a subdirectory with the client id. In this directory it creates 15 * appropriate log files. The name of each finished log file starts with the "htmlmonitor_" 16 * followed by the client id and an index of the log file. An unfinished log file has no index yet. 17 * A log file is finished if 18 * <ul> 19 * <li>the client session is closed by a timeout</li> 20 * <li>the HTML monitor is normally shut down</li> 21 * <li>on startup an unfinished log file is detected.</li> 22 * <li>the {@link #MAXIMUM_LOG_FILE_SIZE} is reached</li> 23 * </ul> 14 24 * </p> 15 25 * … … 21 31 22 32 /** 33 * the maximum size of an individual log file 34 */ 35 private static final int MAXIMUM_LOG_FILE_SIZE = 10000000; 36 37 /** 38 * the default log base directory if none is provided through the constructor 39 */ 40 private static final String DEFAULT_LOG_FILE_BASE_DIR = "logs"; 41 42 /** 43 * the currently used log file base directory 44 */ 45 private File logFileBaseDir; 46 47 /** 48 * the is of the client of which all messages are logged through this writer 49 */ 50 private String clientId; 51 52 /** 53 * the log file into which all messages are currently written 54 */ 55 private File logFile; 56 57 /** 58 * an output writer to be used for writing into the log file 59 */ 60 private PrintWriter outputWriter; 61 62 /** 63 * the time stamp of the last action taken on this writer (such as logging a message) 64 */ 65 private long lastUpdate; 66 67 /** 68 * <p> 69 * initializes the writer with the log file base directory and the id of the client for which 70 * this writer logs the messages. 71 * </p> 23 72 * 24 */ 25 private static final int MAXIMUM_LOG_FILE_SIZE = 10000000; 26 27 /** 28 * 29 */ 30 private static final String DEFAULT_LOG_FILE_BASE_DIR = "logs"; 31 32 /** 33 * 34 */ 35 private File logFileBaseDir; 36 37 /** 38 * 39 */ 40 private String clientId; 41 42 /** 43 * 44 */ 45 private File logFile; 46 47 /** 48 * <p> 49 * Writer for logging events. 50 * </p> 51 */ 52 private PrintWriter outputWriter; 53 54 /** 55 * 56 */ 57 private long lastUpdate; 58 59 /** 60 * <p> 61 * 62 * </p> 63 * 64 * @param outputWriter 65 * writer for the logged information 73 * @param logFileBaseDir the log file base directory, or null if the default directory shall 74 * be taken 75 * @param clientId the ID of the client, for which this writer logs 66 76 */ 67 77 public HtmlMonitorOutputWriter(String logFileBaseDir, String clientId) { … … 117 127 /** 118 128 * <p> 119 * TODO: comment 129 * used to calculate a log file name. If the provided index is smaller 0, then no index 130 * is added to the file name. A filename is e.g. "htmlmonitor_12345_001.log". 120 131 * </p> 121 132 * 122 * @param logFileIndex2 123 * @return 133 * @param index the index of the log file or -1 one, if no index shall be added 134 * 135 * @return the file name as described 124 136 */ 125 137 private String getLogFileName(int index) { … … 144 156 145 157 /* (non-Javadoc) 146 * @see de.ugoe.cs.autoquest.htmlmonitor.HtmlMonitorMessageListener#handleMessage(de.ugoe.cs.quest.htmlmonitor.HtmlClientInfos, de.ugoe.cs.quest.htmlmonitor.HtmlEvent[])158 * @see HtmlMonitorMessageListener#handleMessage(HtmlClientInfos, HtmlEvent[]) 147 159 */ 148 160 @Override … … 170 182 /** 171 183 * <p> 172 * TODO: comment 184 * formats a received event and writes it to the log file. One event results in one line 185 * in the log file containing all infos of the event. 173 186 * </p> 174 187 * 175 * @param event 188 * @param event to be written to the log file 176 189 */ 177 190 private void dumpEvent(HtmlEvent event) { … … 219 232 /** 220 233 * <p> 221 * TODO: comment 234 * convenience method to dump a string with trailing and leading " as well as replaced 235 * backslashes, ", and newlines 222 236 * </p> 223 237 * … … 226 240 private void dumpString(String str) { 227 241 outputWriter.print('"'); 228 outputWriter.print(str.replaceAll("\\\\", "\\\\").replaceAll("\\\"", "\\\"")); 242 outputWriter.print 243 (str.replaceAll("\\\\", "\\\\").replaceAll("\\\"", "\\\"").replaceAll("\n", " ")); 229 244 outputWriter.print('"'); 230 245 } … … 232 247 /** 233 248 * <p> 234 * TODO: comment 235 * </p> 236 * 249 * checks, if the log file exeeded the {@link #MAXIMUM_LOG_FILE_SIZE}. If so, the current 250 * log file is closed, the next log file name is determined and this new file is opend for 251 * writing. 252 * </p> 237 253 */ 238 254 private synchronized void considerLogRotate() throws IOException { … … 246 262 /** 247 263 * <p> 248 * TODO: comment249 * </p>250 * 264 * renames the current log file to a new log file with the next available index. It further 265 * sets the current log file to the default name, i.e. without index. 266 * </p> 251 267 */ 252 268 private void rotateLogFile() { … … 269 285 /** 270 286 * <p> 271 * TODO: comment 272 * </p> 273 * 287 * instantiates a writer to be used for writing messages into the log file. 288 * </p> 274 289 */ 275 290 private void createLogWriter() throws IOException { … … 280 295 /** 281 296 * <p> 282 * TODO: comment 283 * </p> 284 * 297 * closed the current writer if it is open. 298 * </p> 285 299 */ 286 300 private void closeLogWriter() { … … 305 319 /** 306 320 * <p> 307 * TODO: comment321 * return the time stamp of the last activity that happened on this writer. 308 322 * </p> 309 323 * 310 * @return 324 * @return as described 311 325 */ 312 326 public long getLastUpdate() { -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServer.java
r857 r871 8 8 9 9 /** 10 * TODO: comment 10 * <p> 11 * this is the web server, that receives the client messages. It is initialized with a port on 12 * which it shall listen, as well as a message listener to forward the received messages to. 13 * Internally it starts a jetty web server with a single {@link HtmlMonitorServlet} to receive 14 * the messages. 15 * </p> 11 16 * 12 17 * @author Patrick Harms … … 15 20 16 21 /** 17 * 22 * the port to listen on 18 23 */ 19 24 private int port; 20 25 21 26 /** 22 * 27 * the jetty web server used for receiving messages 23 28 */ 24 29 private Server server; 25 30 26 31 /** 27 * 32 * the message listener to forward the messages to 28 33 */ 29 34 private HtmlMonitorMessageListener messageListener; … … 31 36 /** 32 37 * <p> 33 * TODO: comment 38 * initializes the server with the port to listen on and the message listener to forward 39 * the messages to. 34 40 * </p> 35 41 * 42 * @param port the port to listen on 43 * @param messageListener the message listener to forward the messages to 36 44 */ 37 45 HtmlMonitorServer(int port, HtmlMonitorMessageListener messageListener) { -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServlet.java
r857 r871 24 24 /** 25 25 * <p> 26 * TODO comment 26 * the servlet deployed in the web server that receives all client messages. The messages are 27 * parsed, validated, and forwarded to the provided message listener. If a message is not valid, 28 * it is discarded. If an event in a message is not valid, it is discarded. Messages are only 29 * received via the POST HTTP method. 27 30 * </p> 28 31 * 29 32 * @author Patrick Harms 30 33 */ 31 publicclass HtmlMonitorServlet extends DefaultServlet {34 class HtmlMonitorServlet extends DefaultServlet { 32 35 33 36 /** */ … … 35 38 36 39 /** 37 * 40 * the message listener to forward received messages to. 38 41 */ 39 42 private HtmlMonitorMessageListener messageListener; … … 41 44 /** 42 45 * <p> 43 * TODO: comment44 * </p> 45 * 46 * @param htmlMonitoringListener46 * initializes the servlet with the message listener to which all events shall be forwarded 47 * </p> 48 * 49 * @param messageListener the message listener that shall receive all client events 47 50 */ 48 51 HtmlMonitorServlet(HtmlMonitorMessageListener messageListener) { … … 76 79 /** 77 80 * <p> 78 * TODO: comment 79 * </p> 80 * 81 * @param object 81 * processes a received JSON object and validates it. If the message is ok, it is forwarded 82 * to the message listener 83 * </p> 84 * 85 * @param object the JSON object that contains a client message 82 86 */ 83 87 private void handleJSONObject(JSONObject object) { … … 111 115 /** 112 116 * <p> 113 * TODO: comment 114 * </p> 115 * 116 * @param object 117 * @return 117 * tries to extract the client infos out of the received JSON object. If this is not fully 118 * possible, an appropriate message is dumped and the whole message is discarded (the method 119 * return null). 120 * </p> 121 * 122 * @param message the message to parse the client infos from 123 * 124 * @return the client infos, if the message is valid in this respect, or null if not 118 125 */ 119 126 private HtmlClientInfos extractClientInfos(JSONObject message) { … … 150 157 /** 151 158 * <p> 152 * TODO: comment 153 * </p> 154 * 155 * @param object 156 * @param clientInfos 157 * @return 159 * tries to extract the events out of the received JSON object. If this is not fully 160 * possible, an appropriate message is dumped and the errorprone event is discarded. If no 161 * valid event is found, the whole message is discarded. 162 * </p> 163 * 164 * @param object the message to parse the events from 165 * @param clientInfos the infos about the client that send the events 166 * 167 * @return the valid events stored in the message, or null if there are none 158 168 */ 159 169 private HtmlEvent[] extractHtmlEvents(JSONObject object, HtmlClientInfos clientInfos) { … … 218 228 /** 219 229 * <p> 220 * TODO: comment 221 * </p> 222 * 223 * @param eventType 224 * @param coordinates 225 * @param key 226 * @param scrollPosition 227 * @return 230 * validates if for the given event type the parameter combination of coordinates, key, and 231 * scroll position is valid. As an example, an onclick event should usually not have an 232 * associated scroll position. 233 * </p> 234 * 235 * @param eventType the type of the event 236 * @param coordinates the coordinates of the event 237 * @param key the key of the event 238 * @param scrollPosition the scroll position of the event 239 * 240 * @return true, if the combination of the parameters is valid, false else 228 241 */ 229 242 private boolean checkEventParameterCombinations(String eventType, … … 279 292 /** 280 293 * <p> 281 * TODO: comment 282 * </p> 283 * 284 * @param object 285 * @param string 286 * @param class1 287 * @return 294 * converts a value in the provided object matching the provided key to the provided type. If 295 * there is no value with the key or if the value can not be transformed to the provided type, 296 * the method returns null. 297 * </p> 298 * 299 * @param object the object to read the value from 300 * @param key the key of the value 301 * @param clazz the type to which the value should be transformed 302 * 303 * @return the value or null if either the value does not exist or if it can not be transformed 304 * to the expected type 288 305 */ 289 306 @SuppressWarnings("unchecked") … … 381 398 /** 382 399 * <p> 383 * TODO: comment 384 * </p> 385 * 386 * @param object 400 * convenience method for dumping an object to std out. If the object is a JSON object, it is 401 * deeply analyzed and its internal structure is dumped as well. 402 * </p> 403 * 404 * @param object the object to dump 405 * @param indent the indentation to be used. 387 406 */ 388 407 private void dumpJSONObject(Object object, String indent) { -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/Runner.java
r857 r871 6 6 /** 7 7 * <p> 8 * TODO comment8 * implements the main method to start the {@link HtmlMonitor}. 9 9 * </p> 10 10 * … … 19 19 * </p> 20 20 * 21 * @param args 22 * TODO comment 21 * @param args command line arguments 23 22 */ 24 23 public static void main(String[] args) { -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/ShutdownHook.java
r857 r871 3 3 /** 4 4 * <p> 5 * TODO comment 5 * used to be able to shut down any {@link HtmlMonitorComponent} that must be stopped if the 6 * application stops. 6 7 * </p> 7 8 * … … 10 11 public class ShutdownHook implements Runnable { 11 12 12 /** */ 13 /** 14 * the components to be stopped on shutdown 15 */ 13 16 private HtmlMonitorComponent[] components; 14 17 15 18 /** 16 19 * <p> 17 * TODO: comment 20 * initializes the shutdown hook with the components to be shut down on shutdown of the whole 21 * application 18 22 * </p> 19 23 *
Note: See TracChangeset
for help on using the changeset viewer.