/** * 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); }
int requestBsn = bmgr.bsnFromMark(mark); int fsl = fileSet.length;
int bsn = bmgr.bsnFromMark(mark); if (mark < 0 || (bsn == 0 && mark != 0)) throw new InvalidLogKeyException(Long.toHexString(mark)); lr.buffer = bmgr.getLogBuffer(-1); } catch (ClassNotFoundException e) { throw new LogConfigurationException(e); bmgr.forceCurrentBuffer(); lfmgr.read(buffer, bsn); } catch (IOException e) { int markBSN = (mark == 0) ? buffer.bsn : bmgr.bsnFromMark(mark); if (markBSN != buffer.bsn) { InvalidLogBufferException lbe = new InvalidLogBufferException( if (mark > 0 && mark > bmgr.markFromBsn(markBSN,0)) { while(lr.key < mark) { lr.get(buffer);
lb = bmgr.getLogBuffer(-1); } catch (ClassNotFoundException e) { throw new LogConfigurationException("LogBuffer.class not found", e); if (fileSet[next].newFile) continue; fileSet[i].highMark = bmgr.markFromBsn(fileSet[next].firstBSN, 0); bmgr.init(this, bsn); initialKey = bmgr.markFromBsn(bsn + 1, 0); activeMark = bmgr.markFromBsn(1, 0); // BUG 304331
long waitForBuffer = parent.getWaitForBuffer(); long bufferWaits = parent.getWaitForBuffer() - waitForBuffer; int maxBuffers = config.getMaxBuffers(); int increment = freeBuffer.length / 2; fb[i] = getLogBuffer(i); bl[i] = fb[i]; } catch (ClassNotFoundException e) { waitForBuffer = parent.getWaitForBuffer(); if (buffer != null && buffer.shouldForce()) fqAdd(buffer);
/** * 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); }
/** * 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; }
throw new IllegalArgumentException("BSN must be >= zero"); long mark = bmgr.markFromBsn(bsn, 0);
/** * 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(); }
/** * 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; } }
for (short i=0; i< bufferPoolSize; ++i) freeBuffer[i] = getLogBuffer(i);
/** * 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(); bmgr.close(); }
int bsn = bmgr.bsnFromMark(mark); if (mark < 0 || (bsn == 0 && mark != 0)) throw new InvalidLogKeyException(Long.toHexString(mark)); lr.buffer = bmgr.getLogBuffer(-1); } catch (ClassNotFoundException e) { throw new LogConfigurationException(e); bmgr.forceCurrentBuffer(); lfmgr.read(buffer, bsn); } catch (IOException e) { int markBSN = (mark == 0) ? buffer.bsn : bmgr.bsnFromMark(mark); if (markBSN != buffer.bsn) { InvalidLogBufferException lbe = new InvalidLogBufferException( if (mark > 0 && mark > bmgr.markFromBsn(markBSN,0)) { while(lr.key < mark) { lr.get(buffer);
lb = bmgr.getLogBuffer(-1); } catch (ClassNotFoundException e) { throw new LogConfigurationException("LogBuffer.class not found", e); if (fileSet[next].newFile) continue; fileSet[i].highMark = bmgr.markFromBsn(fileSet[next].firstBSN, 0); bmgr.init(this, bsn); initialKey = bmgr.markFromBsn(bsn + 1, 0); activeMark = bmgr.markFromBsn(1, 0); // BUG 304331
long waitForBuffer = parent.getWaitForBuffer(); long bufferWaits = parent.getWaitForBuffer() - waitForBuffer; int maxBuffers = config.getMaxBuffers(); int increment = freeBuffer.length / 2; fb[i] = getLogBuffer(i); bl[i] = fb[i]; } catch (ClassNotFoundException e) { waitForBuffer = parent.getWaitForBuffer(); if (buffer != null && buffer.shouldForce()) fqAdd(buffer);
/** * 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); }
/** * 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; }
throw new IllegalArgumentException("BSN must be >= zero"); long mark = bmgr.markFromBsn(bsn, 0);
/** * 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(); }