|
From: <tr...@us...> - 2003-09-03 03:25:40
|
Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/journal/simple
In directory sc8-pr-cvs1:/tmp/cvs-serv10506/core/src/com/babeldoc/core/journal/simple
Modified Files:
SimpleJournal.java
Log Message:
LARGE, EXTENSIVE UPDATE.
1. All journal classes are now IConfigurable
2. J2ee journal classes using IConfigurable and are consistent
3. Somewhat of a cleanup around the journal code.
Index: SimpleJournal.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/journal/simple/SimpleJournal.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** SimpleJournal.java 18 Aug 2003 19:18:07 -0000 1.9
--- SimpleJournal.java 3 Sep 2003 03:25:31 -0000 1.10
***************
*** 69,73 ****
import com.babeldoc.core.LogService;
import com.babeldoc.core.VariableProcessor;
! import com.babeldoc.core.config.ConfigService;
import com.babeldoc.core.journal.*;
import com.babeldoc.core.journal.query.JournalQuery;
--- 69,75 ----
import com.babeldoc.core.LogService;
import com.babeldoc.core.VariableProcessor;
! import com.babeldoc.core.option.IConfigInfo;
! import com.babeldoc.core.option.ConfigOption;
! import com.babeldoc.core.option.IConfigOptionType;
import com.babeldoc.core.journal.*;
import com.babeldoc.core.journal.query.JournalQuery;
***************
*** 81,84 ****
--- 83,87 ----
import java.util.ArrayList;
import java.util.Date;
+ import java.util.Collection;
import org.apache.commons.lang.NumberUtils;
***************
*** 127,130 ****
--- 130,136 ----
public static final String JOURNAL_DUMMY = "dummy";
+ /** constants: default max log size */
+ public static final int DEFAULT_LOGSIZE = 1024 * 1024;
+
/** constants: configuration name */
public static final String NULL = "null";
***************
*** 137,170 ****
/** Configuration stuff */
! private static FileWriter logWriter;
! private static CSVWriter logPrinter;
! private static String logFile;
! private static int logMaxSize = 1024 * 1024;
/** Locals */
! private static String trackerDir;
private static long lastTicketVal;
- /**
- * get the configuration service
- */
- static {
- try {
- logFile = VariableProcessor.expandString(ConfigService.getString(
- CONFIG_NAME, JOURNAL_LOGFILE));
- logWriter = new FileWriter(logFile, true);
- logPrinter = new CSVWriter(logWriter);
- trackerDir = VariableProcessor.expandString(ConfigService.getString(
- CONFIG_NAME, JOURNAL_DIR));
-
- if (!trackerDir.endsWith(File.separator)) {
- trackerDir += File.separator;
- }
- logMaxSize = NumberUtils.stringToInt(ConfigService.getString(CONFIG_NAME, JOURNAL_MAXSIZE));
- } catch (Exception confx) {
- System.out.println(confx);
- }
- }
/**
--- 143,157 ----
/** Configuration stuff */
! private FileWriter logWriter;
! private CSVWriter logPrinter;
! private String logFile;
! private int logMaxSize;
/** Locals */
! private String trackerDir;
private static long lastTicketVal;
+ private IConfigInfo info;
/**
***************
*** 182,186 ****
try {
! CSVReader csvReader = new CSVReader(new FileReader(logFile));
String[] values;
String tickval = Long.toString(((JournalTicket) parent).getValue());
--- 169,173 ----
try {
! CSVReader csvReader = new CSVReader(new FileReader(getLogFile()));
String[] values;
String tickval = Long.toString(((JournalTicket) parent).getValue());
***************
*** 215,219 ****
try {
! CSVReader csvReader = new CSVReader(new FileReader(logFile));
String[] values;
--- 202,206 ----
try {
! CSVReader csvReader = new CSVReader(new FileReader(getLogFile()));
String[] values;
***************
*** 327,331 ****
try {
! BufferedReader reader = new BufferedReader(new FileReader(logFile));
CSVReader csvReader = new CSVReader(reader);
String[] values = null;
--- 314,318 ----
try {
! BufferedReader reader = new BufferedReader(new FileReader(getLogFile()));
CSVReader csvReader = new CSVReader(reader);
String[] values = null;
***************
*** 476,498 ****
if (operation.equals(JournalOperation.updateStatus)) {
! logPrinter.put(ticket.getId());
! logPrinter.put(Integer.toString(index));
! logPrinter.put(operation.toString());
! logPrinter.put(Long.toString(new Date().getTime()));
! logPrinter.put(otherStr);
! logPrinter.put(pstageName);
! logPrinter.put(addnl);
} else {
! logPrinter.put(ticket.getId());
! logPrinter.put(Integer.toString(index));
! logPrinter.put(operation.toString());
! logPrinter.put(Long.toString(new Date().getTime()));
! logPrinter.put(otherStr);
! logPrinter.put(pstageName);
! logPrinter.put(NULL);
}
! logPrinter.nl();
try {
! logWriter.flush();
} catch (IOException e) {
throw new JournalException("", e);
--- 463,485 ----
if (operation.equals(JournalOperation.updateStatus)) {
! getLogPrinter().put(ticket.getId());
! getLogPrinter().put(Integer.toString(index));
! getLogPrinter().put(operation.toString());
! getLogPrinter().put(Long.toString(new Date().getTime()));
! getLogPrinter().put(otherStr);
! getLogPrinter().put(pstageName);
! getLogPrinter().put(addnl);
} else {
! getLogPrinter().put(ticket.getId());
! getLogPrinter().put(Integer.toString(index));
! getLogPrinter().put(operation.toString());
! getLogPrinter().put(Long.toString(new Date().getTime()));
! getLogPrinter().put(otherStr);
! getLogPrinter().put(pstageName);
! getLogPrinter().put(NULL);
}
! getLogPrinter().nl();
try {
! getLogWriter().flush();
} catch (IOException e) {
throw new JournalException("", e);
***************
*** 507,522 ****
*/
protected void rollLogFile() throws IOException {
! File log = new File(logFile);
! if (log.length() > SimpleJournal.logMaxSize) {
! logWriter.close();
! String fileName = logFile + "." + new Date().toString();
com.babeldoc.core.LogService.getInstance().logInfo(I18n.get("013001",
fileName));
log.renameTo(new File(fileName));
! logWriter = new FileWriter(logFile, true);
! logPrinter = new CSVWriter(logWriter);
}
}
--- 494,509 ----
*/
protected void rollLogFile() throws IOException {
! File log = new File(getLogFile());
! if (log.length() > getLogMaxSize()) {
! getLogWriter().close();
! String fileName = getLogFile() + "." + new Date().toString();
com.babeldoc.core.LogService.getInstance().logInfo(I18n.get("013001",
fileName));
log.renameTo(new File(fileName));
! logWriter = new FileWriter(getLogFile(), true);
! logPrinter = new CSVWriter(getLogWriter());
}
}
***************
*** 529,534 ****
* @return the log director for the ticket
*/
! private static File getLogDirectory(IJournalTicket ticket) {
! String dir = trackerDir + ticket.getId();
File logDirectory = new File(dir);
--- 516,521 ----
* @return the log director for the ticket
*/
! private File getLogDirectory(IJournalTicket ticket) {
! String dir = getTrackerDir() + ticket.getId();
File logDirectory = new File(dir);
***************
*** 546,551 ****
long val = new Date().getTime();
! if (val == lastTicketVal) {
! val = lastTicketVal + 1;
}
--- 533,538 ----
long val = new Date().getTime();
! if (val == getLastTicketVal()) {
! val = getLastTicketVal() + 1;
}
***************
*** 563,568 ****
* @return the file for the settings
*/
! private static File makeTicketDocumentAttrFile(IJournalTicket ticket, int step) {
! return new File(trackerDir + ticket.getId() + File.separator +
Integer.toString(step) + ATTR_SUFFIX);
}
--- 550,555 ----
* @return the file for the settings
*/
! private File makeTicketDocumentAttrFile(IJournalTicket ticket, int step) {
! return new File(getTrackerDir() + ticket.getId() + File.separator +
Integer.toString(step) + ATTR_SUFFIX);
}
***************
*** 576,581 ****
* @return the file for the settings
*/
! private static File makeTicketDocumentFile(IJournalTicket ticket, int step) {
! return new File(trackerDir + ticket.getId() + File.separator +
Integer.toString(step) + DELTA_SUFFIX);
}
--- 563,568 ----
* @return the file for the settings
*/
! private File makeTicketDocumentFile(IJournalTicket ticket, int step) {
! return new File(getTrackerDir() + ticket.getId() + File.separator +
Integer.toString(step) + DELTA_SUFFIX);
}
***************
*** 636,639 ****
--- 623,754 ----
return i;
+ }
+
+ /**
+ * Get the configuration iformation for this class
+ *
+ * @return IConfigInfo object
+ */
+ public IConfigInfo getInfo() {
+ if(this.info==null) {
+ info = new JournalConfigInfo() {
+ /**
+ * This method returns type specific options
+ *
+ * @return comments
+ */
+ public Collection getTypeSpecificOptions() {
+ Collection options = new ArrayList();
+
+ options.add(new ConfigOption(SimpleJournal.JOURNAL_LOGFILE, IConfigOptionType.FILENAME, null, true,
+ "The journal log file. Each operation is logged to this file."));
+ options.add(new ConfigOption(SimpleJournal.JOURNAL_DIR, IConfigOptionType.DIRECTORY, null, true,
+ "The journal data directory. Each store operation gets placed in a directory."));
+ options.add(new ConfigOption(SimpleJournal.JOURNAL_MAXSIZE, IConfigOptionType.INTEGER,
+ Integer.toString(SimpleJournal.DEFAULT_LOGSIZE), false,
+ "The maximum size that the log can grow to before it is rolled."));
+
+ return options;
+ }
+
+ /**
+ * Return description of this worker
+ *
+ * @return description
+ */
+ public String getDescription() {
+ return "The Simple Journal stores its configuration information in directories and a log file.";
+ }
+
+ /**
+ * return the name
+ *
+ * @return
+ */
+ public String getName() {
+ return "simple";
+ }
+ };
+ }
+ return info;
+ }
+
+ /**
+ * Setup the log printer
+ *
+ * @return
+ */
+ protected CSVWriter getLogPrinter() {
+ if(logPrinter==null) {
+ logPrinter = new CSVWriter(getLogWriter());
+ }
+ return logPrinter;
+ }
+
+ /**
+ * Get the log writer
+ *
+ * @return
+ */
+ protected FileWriter getLogWriter() {
+ if(logWriter==null) {
+ try {
+ logWriter = new FileWriter(getLogFile(), true);
+ } catch (IOException e) {
+ LogService.getInstance().logError(e);
+ }
+ }
+ return logWriter;
+ }
+
+ /**
+ * Get the log file configuration
+ *
+ * @return
+ */
+ protected String getLogFile() {
+ if(logFile==null) {
+ logFile = getInfo().getStrValue(JOURNAL_LOGFILE);
+ logFile = VariableProcessor.expandString(logFile);
+
+ // System.out.println("Setting logFile = "+logFile);
+ }
+ return logFile;
+ }
+
+ /**
+ * Get the maximum size of the log file before it is rolled.
+ *
+ * @return
+ */
+ protected int getLogMaxSize() {
+ if(logMaxSize==0) {
+ logMaxSize = NumberUtils.stringToInt(getInfo().getStrValue(JOURNAL_MAXSIZE), DEFAULT_LOGSIZE);
+
+ // System.out.println("Setting logMaxSize="+logMaxSize);
+ }
+ return logMaxSize;
+ }
+
+ /**
+ * Get the tracker dir
+ *
+ * @return
+ */
+ protected String getTrackerDir() {
+ if(trackerDir==null) {
+ trackerDir = VariableProcessor.expandString(getInfo().getStrValue(JOURNAL_DIR));
+
+ if (!trackerDir.endsWith(File.separator)) {
+ trackerDir += File.separator;
+ }
+
+ // System.out.println("Setting trackerDir="+trackerDir);
+ }
+ return trackerDir;
+ }
+
+ protected static long getLastTicketVal() {
+ return lastTicketVal;
}
}
|