Class NTransaction

  • All Implemented Interfaces:
    NTransactionMBean, Transaction, TransactionMBean

    public final class NTransaction
    extends AbstractTransaction
    implements NTransactionMBean
    The NTransaction class implements a transactional storage. For efficiency it uses a file for its transaction journal, the final storage is provided through the Repository interface on filesystem or database.

    Be Careful, the configuration properties don't work for the transaction component: these properties are saved in the transaction repository so they can not be used to configure it.

    See Also:
    Transaction, Repository, FileRepository
    • Field Detail

      • LogMemoryCapacity

        static int LogMemoryCapacity
        Global in memory log initial capacity, by default 4096. This value can be adjusted for a particular server by setting NTLogMemoryCapacity specific property.

        This property can be set only at first launching.

      • MaxLogMemorySize

        static int MaxLogMemorySize
        Maximum size of memory log, by default 2048Kb. This value can be adjusted (Kb) for a particular server by setting NTLogMemorySize specific property.

        This property can be set only at first launching.

      • MaxLogFileSize

        static int MaxLogFileSize
        Size of disk log in Mb, by default 16Mb. This value can be adjusted (Mb) for a particular server by setting NTLogFileSize specific property.

        This property can be set only at first launching.

      • syncOnWrite

        boolean syncOnWrite
        If true every write in the log file is synced to disk, by default false. This value can be adjusted for a particular server by setting Transaction.SyncOnWrite specific property.

        This property can be set only at first launching.

      • LogThresholdOperation

        static int LogThresholdOperation
        Number of pooled operation, by default 1000. This value can be adjusted for a particular server by setting NTLogThresholdOperation specific property.

        This property can be set only at first launching.

      • timer

        private Timer timer
      • repositoryImpl

        String repositoryImpl
        The Repository classname implementation. This value can be set for a particular server by setting the NTRepositoryImpl specific property. By default its value is "fr.dyade.aaa.util.FileRepository".

        This property can be set only at first launching.

    • Constructor Detail

      • NTransaction

        public NTransaction()
    • Method Detail

      • getLogMemoryCapacity

        public final int getLogMemoryCapacity()
        Returns the initial capacity of global in memory log (by default 4096).
        Specified by:
        getLogMemoryCapacity in interface NTransactionMBean
        Returns:
        The initial capacity of global in memory log.
      • getMaxLogMemorySize

        public final int getMaxLogMemorySize()
        Returns the maximum size of memory log in Kb, by default 2048Kb.
        Specified by:
        getMaxLogMemorySize in interface NTransactionMBean
        Returns:
        The maximum size of memory log in Kb.
      • setMaxLogMemorySize

        public final void setMaxLogMemorySize​(int size)
        Sets the maximum size of memory log in Kb.
        Specified by:
        setMaxLogMemorySize in interface NTransactionMBean
        Parameters:
        size - The maximum size of memory log in Kb.
      • getLogMemorySize

        public final int getLogMemorySize()
        Returns the size of memory log in bytes.
        Specified by:
        getLogMemorySize in interface NTransactionMBean
        Returns:
        The size of memory log in bytes.
      • getMaxLogFileSize

        public final int getMaxLogFileSize()
        Returns the maximum size of disk log in Mb, by default 16Mb.
        Specified by:
        getMaxLogFileSize in interface NTransactionMBean
        Returns:
        The maximum size of disk log in Mb.
      • setMaxLogFileSize

        public final void setMaxLogFileSize​(int size)
        Sets the maximum size of disk log in Mb.
        Specified by:
        setMaxLogFileSize in interface NTransactionMBean
        Parameters:
        size - The maximum size of disk log in Mb.
      • getLogFileSize

        public final int getLogFileSize()
        Returns the size of disk log in Kb.
        Specified by:
        getLogFileSize in interface NTransactionMBean
        Returns:
        The size of disk log in Kb.
      • isSyncOnWrite

        public boolean isSyncOnWrite()
        Description copied from interface: NTransactionMBean
        Returns true if every write in the log file is synced to disk.
        Specified by:
        isSyncOnWrite in interface NTransactionMBean
        Returns:
        the syncOnWrite
      • getLogThresholdOperation

        public final int getLogThresholdOperation()
        Returns the pool size for operation objects, by default 1000.
        Specified by:
        getLogThresholdOperation in interface NTransactionMBean
        Returns:
        The pool size for operation objects.
      • getGarbageCount

        public final int getGarbageCount()
        Returns the number of garbage operation since starting up.
        Specified by:
        getGarbageCount in interface NTransactionMBean
        Returns:
        The number of garbage operation.
      • getGarbageDelay

        public final int getGarbageDelay()
        Returns the maximum time between two garbages, 0 if disable.
        Specified by:
        getGarbageDelay in interface NTransactionMBean
        Returns:
        The maximum time between two garbages.
      • setGarbageDelay

        public final void setGarbageDelay​(int timeout)
        Sets the maximum time between two garbages, 0 to disable the asynchronous garbage mechanism.
        Specified by:
        setGarbageDelay in interface NTransactionMBean
        Parameters:
        timeout - The maximum time between two garbages.
      • isGarbageRunning

        public final boolean isGarbageRunning()
        Returns the status of the garbage thread.
        Specified by:
        isGarbageRunning in interface NTransactionMBean
        Returns:
        The status of the garbage thread.
      • garbageAsync

        public void garbageAsync​(boolean async)
        Sets asynchronous garbage.
        Specified by:
        garbageAsync in interface NTransactionMBean
        Parameters:
        async - If true activates the asynchronous garbage, deactivates otherwise.
      • getGarbageTime

        public long getGarbageTime()
        Returns the cumulated time of garbage operations since starting up.
        Specified by:
        getGarbageTime in interface NTransactionMBean
        Returns:
        The cumulated time of garbage operations since starting up.
      • getGarbageRatio

        public int getGarbageRatio()
        Returns the ratio of garbage operations since starting up.
        Specified by:
        getGarbageRatio in interface NTransactionMBean
        Returns:
        The ratio of garbage operations since starting up.
      • getRepositoryImpl

        public String getRepositoryImpl()
        Returns the Repository classname implementation.
        Specified by:
        getRepositoryImpl in interface NTransactionMBean
        Returns:
        The Repository classname implementation.
      • getNbSavedObjects

        public int getNbSavedObjects()
        Returns the number of save operation to repository.
        Specified by:
        getNbSavedObjects in interface NTransactionMBean
        Returns:
        The number of save operation to repository.
      • getNbDeletedObjects

        public int getNbDeletedObjects()
        Returns the number of delete operation on repository.
        Specified by:
        getNbDeletedObjects in interface NTransactionMBean
        Returns:
        The number of delete operation on repository.
      • getNbBadDeletedObjects

        public int getNbBadDeletedObjects()
        Returns the number of useless delete operation on repository.
        Specified by:
        getNbBadDeletedObjects in interface NTransactionMBean
        Returns:
        The number of useless delete operation on repository.
      • getNbLoadedObjects

        public int getNbLoadedObjects()
        Returns the number of load operation from repository.
        Specified by:
        getNbLoadedObjects in interface NTransactionMBean
        Returns:
        The number of load operation from repository.
      • getPersistenceDir

        public String getPersistenceDir()
        Returns the path of persistence directory.
        Returns:
        The path of persistence directory.
      • setPhase

        protected final void setPhase​(int newPhase)
        Description copied from class: AbstractTransaction
        Changes the transaction state.
        Specified by:
        setPhase in class AbstractTransaction
        Parameters:
        newPhase - the new transaction state.
      • getList

        public String[] getList​(String prefix)
        Returns an array of strings naming the persistent objects denoted by a name that satisfy the specified prefix. Each string is an object name.
        Specified by:
        getList in interface Transaction
        Parameters:
        prefix - the prefix
        Returns:
        An array of strings naming the persistent objects denoted by a name that satisfy the specified prefix. The array will be empty if no names match.
      • saveInLog

        protected final void saveInLog​(byte[] buf,
                                       String dirName,
                                       String name,
                                       Hashtable log,
                                       boolean copy,
                                       boolean first)
                                throws IOException
        Save an object state already serialized. The byte array in parameter may be modified so we must duplicate it.
        Specified by:
        saveInLog in class AbstractTransaction
        Parameters:
        buf - the byte array containing the state of the object.
        dirName - the directory name of the object.
        name - the name of the object.
        log - the log to use.
        copy - the byte array can be modified, copy it.
        first - the object is a new one.
        Throws:
        IOException - an error occurs.
      • loadByteArray

        public byte[] loadByteArray​(String dirName,
                                    String name)
                             throws IOException
        Description copied from interface: Transaction
        Load the specified byte array.
        Specified by:
        loadByteArray in interface Transaction
        Parameters:
        dirName - the directory name of the object.
        name - the name of the object.
        Returns:
        the loaded byte array.
        Throws:
        IOException - an error occurs.
      • delete

        public final void delete​(String dirName,
                                 String name)
        Description copied from interface: Transaction
        Deletes the specified object.
        Specified by:
        delete in interface Transaction
        Parameters:
        dirName - the directory name of the object.
        name - the name of the object.
      • commit

        public final void commit​(boolean release)
                          throws IOException
        Description copied from interface: Transaction
        Commit the current transaction.
        Specified by:
        commit in interface Transaction
        Parameters:
        release - if true releases the transaction at the end of the commit.
        Throws:
        IOException - an error occurs.
      • garbage

        public final void garbage()
        Garbage the log file. It waits all transactions termination, then the log file is garbaged and all operations are reported to disk.
        Specified by:
        garbage in interface NTransactionMBean
      • stop

        public void stop()
        Stops the transaction module. It waits all transactions termination, then the module is kept in a FREE 'ready to use' state. The log file is garbaged, all operations are reported to disk.
        Specified by:
        stop in interface Transaction
      • close

        public void close()
        Close the transaction module. It waits all transactions termination, the module will be initialized anew before reusing it. The log file is garbaged then closed.
        Specified by:
        close in interface Transaction
      • toString

        public String toString()
        Returns a string representation for this object.
        Overrides:
        toString in class Object
        Returns:
        A string representation of this object.
      • backup

        public String backup​(String path)
                      throws Exception
        Backups the content of Transaction module. Produces a generic Backup/Restore file containing all living objects. Currently not implemented, throws an UnsupportedOperationException.
        Specified by:
        backup in interface Transaction
        Specified by:
        backup in interface TransactionMBean
        Parameters:
        path - Directory path to store the backup.
        Returns:
        the name of created backup file.
        Throws:
        Exception - An error occurs during backup.