Class FlashJournalRM.WriterDaemon

  • All Implemented Interfaces:
    Guardable, Runnable
    Enclosing class:
    FlashJournalRM

    protected class FlashJournalRM.WriterDaemon
    extends Daemon
    The WriterDaemon takes the enqueued Buffer objects from the PreparerDaemon, and appends them to a JournalFile.
    • Field Detail

      • m_cSingleBlockWrites

        protected long m_cSingleBlockWrites
        The number of blocks written individually.
      • m_cMillisSingleBlockWrites

        protected long m_cMillisSingleBlockWrites
        The number of milliseconds total spent writing blocks individually.
      • m_cMultiBlockWrites

        protected long m_cMultiBlockWrites
        The number of blocks written in groups (as part of a multi-buffer write).
      • m_cMillisMultiBlockWrites

        protected long m_cMillisMultiBlockWrites
        The number of milliseconds total spent writing blocks in groups.
      • m_fPreferSingleBlockWrites

        protected boolean m_fPreferSingleBlockWrites
        Set to true if it becomes apparent that single block writes are preferable.
    • Constructor Detail

      • WriterDaemon

        public WriterDaemon()
        Construct a WriterDaemon.
    • Method Detail

      • stop

        public void stop()
        Request the daemon to stop. This method will only have an effect if the daemon sub-class respects the value returned from Daemon.isStopping().
        Overrides:
        stop in class Daemon
      • run

        public void run()
        The daemon's implementation method. Override this method to implement a daemon.

        An example implementation is:

        
           while (!isStopping())
               {
               // do some processing
               // ...
        
               synchronized (this)
                   {
                   // wait for notification of more work
                   wait();
                   }
               }
         

        Specified by:
        run in interface Runnable
        Specified by:
        run in class Daemon
      • setGuardPolicy

        protected void setGuardPolicy​(Guardian guardian,
                                      long cTimeoutMillis,
                                      float flPctRecover)
        Set the Guardian and policy to guard this Daemon with. The Daemon is registered with the specified Guardian each time the Daemon is started, and is released each time the Daemon is stopped.
        Overrides:
        setGuardPolicy in class Daemon
        Parameters:
        guardian - the Guardian that will be guarding this Daemon
        cTimeoutMillis - the timeout in ms for this Daemon, or 0 for the service guardian timeout
        flPctRecover - the recovery percentage for this Daemon
      • getDescription

        protected String getDescription()
        Format the Daemon attributes into a String for inclusion in the String returned from the Daemon.toString() method.
        Overrides:
        getDescription in class Daemon
        Returns:
        a String listing the attributes of the Daemon
      • isSingleBlockWritePreferred

        public boolean isSingleBlockWritePreferred()
        Determine if the next write should automatically use the "single buffer write" capability of NIO, instead of attempting to use the NIO scatter/gather capability.
        Returns:
        true iff the next write should not attempt to use NIO scatter/gather functionality
      • getBlockWriteCount

        public long getBlockWriteCount()
        Determine the total number of blocks written by this daemon.
        Returns:
        the total number of blocks written by this daemon
      • getSingleBlockWriteCount

        public long getSingleBlockWriteCount()
        Determine the number of blocks written by this daemon using the NIO "single buffer write" functionality.
        Returns:
        the number of NIO individual buffer writes
      • getMultiBlockWriteCount

        public long getMultiBlockWriteCount()
        Determine the number of blocks written by this daemon using the NIO "scatter/gather" functionality. This is not the number of writes, since each write involves multiple blocks being written, one in each buffer.
        Returns:
        the number of NIO scatter/gather buffer writes
      • getAvgBlockWriteMillis

        public int getAvgBlockWriteMillis()
        Determine the average number of milliseconds to write each block.
        Returns:
        the average number of milliseconds to write each block
      • getAvgSingleBlockWriteMillis

        public int getAvgSingleBlockWriteMillis()
        Determine the average number of milliseconds to write each block using the NIO "single buffer write" functionality.
        Returns:
        the average number of milliseconds for NIO individual buffer writes
      • getAvgMultiBlockWriteMillis

        public int getAvgMultiBlockWriteMillis()
        Determine the average number of milliseconds to write each block using the NIO "scatter/gather" functionality.
        Returns:
        the average number of milliseconds for NIO scatter/gather writes
      • enqueueBuffer

        public void enqueueBuffer​(FlashJournalRM.JournalFile jrnlfile,
                                  FlashJournalRM.Buffer buf,
                                  int cbBuffer)
        Notify the writer thread that a buffer needs to be written.
        Parameters:
        jrnlfile - the file to append to
        buf - the buffer to append
        cbBuffer - the number of bytes to append from the buffer
      • notifyFileFull

        public void notifyFileFull​(FlashJournalRM.JournalFile jrnlfile)
        Notify the writer thread that a file is done being written to.
        Parameters:
        jrnlfile - the file to append to