/** * Construct a Logger using a Configuration supplied * by the caller. * @param config Configuration object * @throws IOException */ public Logger(Configuration config) throws IOException { super(config); lfmgr = new LogFileManager(config); bmgr = new LogBufferManager(config); }
/** * close the Log files and perform necessary cleanup tasks. */ public void close() throws IOException, InterruptedException { // prevent new threads from adding to the log synchronized(this) { isClosed = true; } lfmgr.close(); }
/** * calls <i> mark(key, false) </i> * @param key a log key as described by {@link #mark(long,boolean)} * @return log key of the new mark record. * @throws InvalidLogKeyException * @throws IOException * @throws InterruptedException * @see #mark(long, boolean) */ long mark(long key) throws InvalidLogKeyException, IOException, InterruptedException { return mark(key, false); }
/** * open Log files and perform necessart initialization. * * TODO: consider open(String name) to allow named configurations. * this would allow utility to open two loggers and copy * old records to new files. * */ public void open() throws InvalidFileSetException, IOException, LogConfigurationException, InvalidLogBufferException, InterruptedException { lfmgr.open(); try { bmgr.open(); } catch (ClassNotFoundException e) { String cnf = "LogBuffer Class not found: " + config.getBufferClassName(); LogConfigurationException lce = new LogConfigurationException(cnf, e); throw lce; } // read header information from each file lfmgr.init(bmgr); // indicate that Log is ready for use. synchronized(this) { isClosed = false; } }
lfm.read(buffer, bsn); } catch (IOException e) { String msg = "Error reading " + buffer.lf.file + " @ position [" + buffer.lf.position + "]"; if (mark == 0 || mark == lfm.getHighMark()) { record.type = LogRecordType.END_OF_LOG; listener.onRecord(record); lfm.read(buffer, nextBSN); } catch (IOException e) { listener.onError(new LogException(e.toString()));
lfmgr.read(buffer, buffer.bsn+1); } catch (IOException e) { LogFile lf = lr.buffer.lf;
/** * Registers a LogEventListener for log event notifications. * * @param eventListener object to be notified of logger events. */ public void setLogEventListener(LogEventListener eventListener) { lfmgr.setLogEventListener(eventListener); }
/** * Sets the LogFile marking mode. * * <p>passes call to LogFileManager * * @param autoMark true to indicate automatic marking. */ public void setAutoMark(boolean autoMark) throws InvalidLogKeyException, LogClosedException, LogFileOverflowException, IOException, InterruptedException { synchronized(this) { if (this.isClosed) throw new LogClosedException(); } lfmgr.setAutoMark(autoMark); }
/** * return an XML node containing statistics for the Logger, * the LogFile pool and the LogBuffer pool. * * <p>The getStats method for the LogBufferManager and LogFileManager * are called to include statistics for these contained objects. * * @return String contiining XML node. */ public String getStats() { String name = this.getClass().getName(); StringBuffer stats = new StringBuffer( "<Logger class='" + name + "'>" ); // TODO: append Logger specific stats stats.append(bmgr.getStats()); stats.append(lfmgr.getStats()); stats.append("\n</Logger>" + "\n"); return stats.toString(); }
/** * Sub-classes call this method to write log records with * a specific record type. * * @param type a record type defined in LogRecordType. * @param data record data to be logged. * @param sync boolean indicating whether call should * wait for data to be written to physical disk. * * @return a log key that can be used to reference * the record. */ protected long put(short type, byte[][] data, boolean sync) throws LogClosedException, LogRecordSizeException, LogFileOverflowException, InterruptedException, IOException { synchronized(this) { if (isClosed) throw new LogClosedException(); } // QUESTION: should we deal with exceptions here? long key = bmgr.put(type, data, sync); lfmgr.setCurrentKey(key); return key; }
/** * open Log files and perform necessart initialization. * * TODO: consider open(String name) to allow named configurations. * this would allow utility to open two loggers and copy * old records to new files. * */ public void open() throws InvalidFileSetException, IOException, LogConfigurationException, InvalidLogBufferException, InterruptedException { lfmgr.open(); try { bmgr.open(); } catch (ClassNotFoundException e) { String cnf = "LogBuffer Class not found: " + config.getBufferClassName(); LogConfigurationException lce = new LogConfigurationException(cnf, e); throw lce; } // read header information from each file lfmgr.init(bmgr); // indicate that Log is ready for use. synchronized(this) { isClosed = false; } }
lfm.read(buffer, bsn); } catch (IOException e) { String msg = "Error reading " + buffer.lf.file + " @ position [" + buffer.lf.position + "]"; if (mark == 0 || mark == lfm.getHighMark()) { record.type = LogRecordType.END_OF_LOG; listener.onRecord(record); lfm.read(buffer, nextBSN); } catch (IOException e) { listener.onError(new LogException(e.toString()));
lfmgr.read(buffer, buffer.bsn+1); } catch (IOException e) { LogFile lf = lr.buffer.lf;
/** * Registers a LogEventListener for log event notifications. * * @param eventListener object to be notified of logger events. */ public void setLogEventListener(LogEventListener eventListener) { lfmgr.setLogEventListener(eventListener); }
/** * Sets the LogFile marking mode. * * <p>passes call to LogFileManager * * @param autoMark true to indicate automatic marking. */ public void setAutoMark(boolean autoMark) throws InvalidLogKeyException, LogClosedException, LogFileOverflowException, IOException, InterruptedException { synchronized(this) { if (this.isClosed) throw new LogClosedException(); } lfmgr.setAutoMark(autoMark); }
/** * return an XML node containing statistics for the Logger, * the LogFile pool and the LogBuffer pool. * * <p>The getStats method for the LogBufferManager and LogFileManager * are called to include statistics for these contained objects. * * @return String contiining XML node. */ public String getStats() { String name = this.getClass().getName(); StringBuffer stats = new StringBuffer( "<Logger class='" + name + "'>" ); // TODO: append Logger specific stats stats.append(bmgr.getStats()); stats.append(lfmgr.getStats()); stats.append("\n</Logger>" + "\n"); return stats.toString(); }
/** * Sub-classes call this method to write log records with * a specific record type. * * @param type a record type defined in LogRecordType. * @param data record data to be logged. * @param sync boolean indicating whether call should * wait for data to be written to physical disk. * * @return a log key that can be used to reference * the record. */ protected long put(short type, byte[][] data, boolean sync) throws LogClosedException, LogRecordSizeException, LogFileOverflowException, InterruptedException, IOException { synchronized(this) { if (isClosed) throw new LogClosedException(); } // QUESTION: should we deal with exceptions here? long key = bmgr.put(type, data, sync); lfmgr.setCurrentKey(key); return key; }
/** * open Log files and perform necessart initialization. * * TODO: consider open(String name) to allow named configurations. * this would allow utility to open two loggers and copy * old records to new files. * */ public void open() throws InvalidFileSetException, IOException, LogConfigurationException, InvalidLogBufferException, InterruptedException { lfmgr.open(); try { bmgr.open(); } catch (ClassNotFoundException e) { String cnf = "LogBuffer Class not found: " + config.getBufferClassName(); LogConfigurationException lce = new LogConfigurationException(cnf, e); throw lce; } // read header information from each file lfmgr.init(bmgr); // indicate that Log is ready for use. synchronized(this) { isClosed = false; } }
/** * calls <i> mark(key, false) </i> * @param key a log key as described by {@link #mark(long,boolean)} * @return log key of the new mark record. * @throws InvalidLogKeyException * @throws IOException * @throws InterruptedException * @see #mark(long, boolean) */ long mark(long key) throws InvalidLogKeyException, IOException, InterruptedException { return mark(key, false); }
lfm.read(buffer, bsn); } catch (IOException e) { String msg = "Error reading " + buffer.lf.file + " @ position [" + buffer.lf.position + "]"; if (mark == 0 || mark == lfm.getHighMark()) { record.type = LogRecordType.END_OF_LOG; listener.onRecord(record); lfm.read(buffer, nextBSN); } catch (IOException e) { listener.onError(new LogException(e.toString()));