1 package net.logAnalyzer.handlers; 2 3 import net.logAnalyzer.analysis.LAAnalyzer; 4 import net.logAnalyzer.converters.LAConverter; 5 import net.logAnalyzer.converters.UnknownOrLiteralConverterException; 6 7 /*** 8 * This interface defines the log file handlers methods. A log file handler is 9 * used to apply filters and analyzers on a log file. Filters dans analyzers can 10 * be added before and/or after log file parsing. 11 * 12 * @author Karim REFEYTON 13 * @version 0.1 14 */ 15 public interface LALogHandler extends Runnable { 16 17 /*** 18 * Returns log analyzers added to the handler with 19 * {@link #setAnalyzers(LAAnalyzer[])}. 20 * 21 * @return Log analyzers. 22 */ 23 public LAAnalyzer[] getAnalyzers(); 24 25 /*** 26 * Adds new analyzers to the log handler. 27 * 28 * @param newAnalyzers 29 * Analyzers to add. 30 */ 31 public void setAnalyzers(LAAnalyzer[] newAnalyzers); 32 33 /*** 34 * Returns the converter at the specified index. 35 * 36 * @param index 37 * Converter index. 38 * @return Converter or <tt>null</tt> if unknown. 39 */ 40 public LAConverter getConverter(int index); 41 42 /*** 43 * Returns the converter identified by the specified literal (for example, 44 * "%m" generally returns the messageLabel converter). 45 * 46 * @param literal 47 * Converter literal as %m" or %"p" or "%H{CLIENTIP}". 48 * @return Converter or <tt>null</tt> if unknown. 49 * @throws UnknownOrLiteralConverterException 50 * If the literal does not identify a non literal column. 51 */ 52 public LAConverter getConverter(String literal) 53 throws UnknownOrLiteralConverterException; 54 55 /*** 56 * Returns pattern converters. 57 * 58 * @return Pattern converters. 59 */ 60 public LAConverter[] getConverters(); 61 62 /*** 63 * Returns the index of the identified by the specified literal. 64 * 65 * @param literal 66 * Converter literal as %m" or %"p" or "%H{CLIENTIP}". 67 * @return Index of the converter. 68 * @throws UnknownOrLiteralConverterException 69 * If the literal does not identify a non literal column. 70 */ 71 public int getConverterIndex(String literal) 72 throws UnknownOrLiteralConverterException; 73 74 /*** 75 * Returns the last exception thrown by the parsing process. 76 * 77 * @return Last exception or <tt>null</tt> parsing was succesfull. 78 */ 79 public Exception getLastException(); 80 81 /*** 82 * Returns the number of records to parse; <tt>0</tt> for no limitation. 83 * 84 * @return maxRecords Number of records. 85 */ 86 public int getMaxRecords(); 87 88 /*** 89 * Number of records to parse; <tt>0</tt> for no limitation. 90 * 91 * @param maxRecords 92 * Number of records. 93 */ 94 public void setMaxRecords(int maxRecords); 95 96 /*** 97 * Returns the current messageLabel converter used to extend messageLabel 98 * text with unparsed lines. 99 * 100 * @return Message converter. 101 * @see LAMessage#extendsMessage(String) 102 */ 103 public LAConverter getMessageConverter(); 104 105 /*** 106 * Returns the done percentage of the parsed file. If the handler is not 107 * parsing, returns <tt>0</tt>. 108 * 109 * @return Done percentage. 110 */ 111 public int getPercentDone(); 112 113 /*** 114 * Returns the messageLabel at the specified position. 115 * 116 * @param index 117 * Physical index of the messageLabel in the log file. 118 * @return Message. 119 */ 120 public LAMessage getMessage(int index); 121 122 /*** 123 * Returns the messages between specified positions. Uses 124 * {@link #getMessage(int)}to read messageLabel from the log file. 125 * 126 * @param start 127 * start physicial index (included in the result). 128 * @param end 129 * end physical index (included in the result). 130 * @return messages. 131 */ 132 public LAMessage[] getMessages(int start, int end); 133 134 /*** 135 * Returns the real number of messages in the log, not only in cache in case 136 * of a load on demand parsed log. 137 * 138 * @return physical number of messages. 139 */ 140 public int getSize(); 141 142 /*** 143 * Returns <tt>true</tt> if the handler is currently parsing the log. 144 * 145 * @return <tt>true</tt> if parsing; <tt>false</tt> otherwise. 146 */ 147 public boolean isParsing(); 148 149 /*** 150 * Adds a listener. 151 * 152 * @param listener 153 * Lister to add. 154 */ 155 public void addLogHandlerListener(LALogHandlerListener listener); 156 157 /*** 158 * Fires a start parsing event. 159 */ 160 public void fireStartParsing(); 161 162 /*** 163 * Fires an end parsing event. 164 */ 165 public void fireEndParsing(); 166 167 /*** 168 * Parses the log content of the 169 * {@link net.logAnalyzer.utils.FilesSetReader}. Calls, in order : 170 * <p> 171 * Because a {@link LALogHandler} is a {@link Runnable}, for a threaded 172 * parsing you must start it in a new {@link Thread} : 173 * 174 * <pre> 175 * handler.addLogHandlerListener(myLALogHandlerListener); 176 * Thread handlerThread = new Thread(handler); 177 * handlerThread.start(); 178 * </pre> 179 * 180 * </p> 181 * 182 * @see AbstractLogHandler 183 * @throws ParsingException 184 * If can't parse messageLabel. 185 */ 186 public void parse() throws ParsingException; 187 188 /*** 189 * Removes a listener. 190 * 191 * @param listener 192 * Lister to remove. 193 */ 194 public void removeLogHandlerListener(LALogHandlerListener listener); 195 }