User: pkendall
  Date: 01/05/24 20:26:31

  Modified:    src/main/org/jbossmq/filepersistence TxLog.java
  Log:
  tidy up and sync the file after changes.
  
  Revision  Changes    Path
  1.2       +45 -41    jbossmq/src/main/org/jbossmq/filepersistence/TxLog.java
  
  Index: TxLog.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbossmq/src/main/org/jbossmq/filepersistence/TxLog.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TxLog.java        2001/05/15 07:18:01     1.1
  +++ TxLog.java        2001/05/25 03:26:31     1.2
  @@ -19,7 +19,7 @@
    * It is used to rollback transactions when the system restarts.
    *
    * @author: Paul Kendall ([EMAIL PROTECTED])
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class TxLog {
   
  @@ -27,7 +27,7 @@
        // Attributes
        /////////////////////////////////////////////////////////////////////
        private RandomAccessFile transactionLog;
  -  private TreeSet transactions = new TreeSet();
  +     private TreeSet transactions = new TreeSet();
        private long nextTransactionId = Long.MIN_VALUE;
   
        /////////////////////////////////////////////////////////////////////
  @@ -54,29 +54,31 @@
   
        synchronized public Long createTx() throws JMSException {
                Long id = new Long(nextTransactionId++);
  -    transactions.add(id);
  +             transactions.add(id);
                try {
  -      transactionLog.writeLong(nextTransactionId);
  -      transactionLog.writeInt(transactions.size());
  -      for(Iterator iter = transactions.iterator() ; iter.hasNext() ;) {
  -        transactionLog.writeLong(((Long)iter.next()).longValue());
  -      }
  -      transactionLog.seek(0);
  +                     transactionLog.writeLong(nextTransactionId);
  +                     transactionLog.writeInt(transactions.size());
  +                     for(Iterator iter = transactions.iterator() ; iter.hasNext() 
;) {
  +                             
transactionLog.writeLong(((Long)iter.next()).longValue());
  +                     }
  +                     transactionLog.seek(0);
  +                     transactionLog.getFD().sync();
                } catch ( IOException e ) {
                        throwJMSException("Could not write transaction log on 
commit.",e);
                }
  -    return id;
  +             return id;
        }
   
        synchronized public void commitTx(Long txId) throws JMSException {
                try {
  -      transactions.remove(txId);
  -      transactionLog.writeLong(nextTransactionId);
  -      transactionLog.writeInt(transactions.size());
  -      for(Iterator iter = transactions.iterator() ; iter.hasNext() ;) {
  -        transactionLog.writeLong(((Long)iter.next()).longValue());
  -      }
  -      transactionLog.seek(0);
  +                     transactions.remove(txId);
  +                     transactionLog.writeLong(nextTransactionId);
  +                     transactionLog.writeInt(transactions.size());
  +                     for(Iterator iter = transactions.iterator() ; iter.hasNext() 
;) {
  +                             
transactionLog.writeLong(((Long)iter.next()).longValue());
  +                     }
  +                     transactionLog.seek(0);
  +                     transactionLog.getFD().sync();
                } catch ( IOException e ) {
                        throwJMSException("Could not write transaction log on 
commit.",e);
                }
  @@ -84,13 +86,14 @@
   
        synchronized public void rollbackTx(Long txId) throws JMSException {
                try {
  -      transactions.remove(txId);
  -      transactionLog.writeLong(nextTransactionId);
  -      transactionLog.writeInt(transactions.size());
  -      for(Iterator iter = transactions.iterator() ; iter.hasNext() ;) {
  -        transactionLog.writeLong(((Long)iter.next()).longValue());
  -      }
  -      transactionLog.seek(0);
  +                     transactions.remove(txId);
  +                     transactionLog.writeLong(nextTransactionId);
  +                     transactionLog.writeInt(transactions.size());
  +                     for(Iterator iter = transactions.iterator() ; iter.hasNext() 
;) {
  +                             
transactionLog.writeLong(((Long)iter.next()).longValue());
  +                     }
  +                     transactionLog.seek(0);
  +                     transactionLog.getFD().sync();
                } catch ( IOException e ) {
                        throwJMSException("Could not write transaction log on 
rollback.",e);
                }
  @@ -99,23 +102,24 @@
        synchronized public java.util.TreeSet restore() throws JMSException {
                java.util.TreeSet items=null;
   
  -    try {
  -      if( transactionLog.length() != 0 ) {
  -        nextTransactionId = transactionLog.readLong();
  -        int size = transactionLog.readInt();
  -        if( size > 0 ) {
  -          items = new java.util.TreeSet();
  -          for(int i=0 ; i<size ; i++) {
  -            long txId = transactionLog.readLong();
  -            items.add(new Long(txId));
  -          }
  -        }
  -      }
  -      transactionLog.seek(0);
  -      transactionLog.setLength(0);
  -    } catch ( Exception e ) {
  -      throwJMSException("Could not restore the transaction log.",e);
  -    }
  +             try {
  +                     if( transactionLog.length() != 0 ) {
  +                             nextTransactionId = transactionLog.readLong();
  +                             int size = transactionLog.readInt();
  +                             if( size > 0 ) {
  +                                     items = new java.util.TreeSet();
  +                                     for(int i=0 ; i<size ; i++) {
  +                                             long txId = transactionLog.readLong();
  +                                             items.add(new Long(txId));
  +                                     }
  +                             }
  +                     }
  +                     transactionLog.seek(0);
  +                     transactionLog.setLength(0);
  +                     transactionLog.getFD().sync();
  +             } catch ( Exception e ) {
  +                     throwJMSException("Could not restore the transaction log.",e);
  +             }
   
                return items;
        }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to