/** * Replays log from the active mark forward to the current position. * * @param listener an object that implements ReplayListener interface. * @throws LogConfigurationException most likely because the configured LogBuffer class cannot be * found. * @see #replay(ReplayListener, long) */ public void replay(ReplayListener listener) throws LogConfigurationException { try { bmgr.replay(listener, lfmgr.activeMark, false); } catch (InvalidLogKeyException e) { // should not happen -- use assert to catch during development assert false : "Unhandled InvalidLogKeyException" + e.toString(); } }
/** * 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. * * <p>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; } }
// FEATURE: 300792 public LogRecord get(LogRecord lr, long mark) throws InvalidLogKeyException, LogConfigurationException, LogException, InvalidLogBufferException { /* this code is similar to LogBufferManager.replay() -- potential for refactor */ int bsn = bmgr.bsnFromMark(mark); if (mark < 0 || (bsn == 0 && mark != 0)) throw new InvalidLogKeyException(Long.toHexString(mark)); if (lr == null) lr = new LogRecord((config.getBufferSize() * 1024) / 4); // default to 1/4 buffer size // allocate a LogBuffer that we can use to read the journal try { if (lr.buffer == null) lr.buffer = bmgr.getLogBuffer(-1); } catch (ClassNotFoundException e) { throw new LogConfigurationException(e); } LogBuffer buffer = lr.buffer; // read block containing requested mark try { bmgr.forceCurrentBuffer(); lfmgr.read(buffer, bsn); } catch (IOException e) { LogFile lf = buffer.lf; String msg = "Error reading " + lf.file + " @ position [" + lf.position + "]"; throw new LogException(msg, e); } if (buffer.bsn == -1) { lr.type = LogRecordType.END_OF_LOG; return lr; } // verify we have the desired block // if requested mark == 0 then we start with the oldest block available int markBSN = (mark == 0) ? buffer.bsn : bmgr.bsnFromMark(mark); if (markBSN != buffer.bsn) { InvalidLogBufferException lbe = new InvalidLogBufferException( "block read [" + buffer.bsn + "] not block requested: " + markBSN); throw lbe; } /* * position buffer to requested mark. * * Although the mark contains a buffer offset, we search forward * through the buffer to guarantee that we have the start * of a record. This protects against using marks that were * not generated by the current Logger. */ lr.get(buffer); // get first record in buffer if (mark > 0 && mark > bmgr.markFromBsn(markBSN, 0)) { while (lr.key < mark) { lr.get(buffer); } if (lr.key != mark) { String msg = "The requested mark [" + Long.toHexString(mark) + "] was not found in the log."; // BUG 300733 following line changed to throw an exception throw new InvalidLogKeyException(msg); } } return lr; }
/** * Allows sub-classes of Logger to replay control records. * * @param listener ReplayListener to receive the records * @param mark starting mark (log key) for the replay. * @param replayCtrlRecords boolean indicating whether to return CTRL records. * @throws InvalidLogKeyException If the <i> mark </i> parameter specifies an invalid log key (one * that does not exist in the current set of log files.) * @throws LogConfigurationException * @see org.objectweb.howl.log.LogBufferManager#replay(ReplayListener, long, boolean) */ protected void replay(ReplayListener listener, long mark, boolean replayCtrlRecords) throws InvalidLogKeyException, LogConfigurationException { bmgr.replay(listener, mark, replayCtrlRecords); }
/** * Replays log from a specified mark forward to the current mark. * * <p>Beginning with the record located at <i> mark </i> the Logger reads log records forward to * the end of the log. USER records are passed to the <i> listener </i> onRecord() method. When * the end of log has been reached, replay returns one final record with a type of END_OF_LOG to * inform <i> listener </i> that no further records will be returned. * * <p>If an error is encountered while reading the log, the <i> listener </i> onError method is * called. Replay terminates when any error occurs and when END_OF_LOG is encountered. * * @param listener an object that implements ReplayListener interface. * @param mark a log key to begin replay from. * <p>The <i> mark </i> should be a valid log key returned by the put() method. To replay the * entire log beginning with the oldest available record, <i> mark </i> should be set to zero * (0L). * @throws LogConfigurationException most likely because the configured LogBuffer class cannot be * found. * @throws InvalidLogKeyException if <i> mark </i> is not a valid log key. */ public void replay(ReplayListener listener, long mark) throws InvalidLogKeyException, LogConfigurationException { // replay only the user records. bmgr.replay(listener, mark, false); }