activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r412802 - /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/DefaultPersistenceAdapterFactory.java
Date Thu, 08 Jun 2006 17:02:30 GMT
Author: chirino
Date: Thu Jun  8 10:02:30 2006
New Revision: 412802

URL: http://svn.apache.org/viewvc?rev=412802&view=rev
Log:
Implemented:
http://issues.apache.org/activemq/browse/AMQ-742


Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/DefaultPersistenceAdapterFactory.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/DefaultPersistenceAdapterFactory.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/DefaultPersistenceAdapterFactory.java?rev=412802&r1=412801&r2=412802&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/DefaultPersistenceAdapterFactory.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/DefaultPersistenceAdapterFactory.java
Thu Jun  8 10:02:30 2006
@@ -22,6 +22,7 @@
 
 import org.apache.activeio.journal.Journal;
 import org.apache.activeio.journal.active.JournalImpl;
+import org.apache.activeio.journal.active.JournalLockedException;
 import org.apache.activemq.store.jdbc.DataSourceSupport;
 import org.apache.activemq.store.jdbc.JDBCAdapter;
 import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
@@ -29,6 +30,8 @@
 import org.apache.activemq.store.journal.JournalPersistenceAdapter;
 import org.apache.activemq.store.journal.QuickJournalPersistenceAdapter;
 import org.apache.activemq.thread.TaskRunnerFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * Factory class that can create PersistenceAdapter objects.
@@ -37,6 +40,10 @@
  */
 public class DefaultPersistenceAdapterFactory extends DataSourceSupport implements PersistenceAdapterFactory
{
     
+    private static final int JOURNAL_LOCKED_WAIT_DELAY = 10*1000;
+
+    private static final Log log = LogFactory.getLog(DefaultPersistenceAdapterFactory.class);
+    
     private int journalLogFileSize = 1024*1024*20;
     private int journalLogFiles = 2;
     private TaskRunnerFactory taskRunnerFactory;
@@ -44,6 +51,7 @@
     private boolean useJournal=true;
     private boolean useQuickJournal=false;
     private File journalArchiveDirectory;
+    private boolean failIfJournalIsLocked=false;
     private JDBCPersistenceAdapter jdbcPersistenceAdapter = new JDBCPersistenceAdapter();
     
     public PersistenceAdapter createPersistenceAdapter() throws IOException {
@@ -155,7 +163,22 @@
      */
     protected void createJournal() throws IOException {
         File journalDir = new File(getDataDirectory(), "journal").getCanonicalFile();
-        journal = new JournalImpl(journalDir, journalLogFiles, journalLogFileSize, getJournalArchiveDirectory());
+        if( failIfJournalIsLocked ) {
+            journal = new JournalImpl(journalDir, journalLogFiles, journalLogFileSize, getJournalArchiveDirectory());
+        } else {
+            while( true ) {
+                try {
+                    journal = new JournalImpl(journalDir, journalLogFiles, journalLogFileSize,
getJournalArchiveDirectory());
+                    break;
+                } catch (JournalLockedException e) {
+                    log.info("Journal is locked... waiting "+(JOURNAL_LOCKED_WAIT_DELAY/1000)+"
seconds for the journal to be unlocked.");
+                    try {
+                        Thread.sleep(JOURNAL_LOCKED_WAIT_DELAY);
+                    } catch (InterruptedException e1) {
+                    }
+                }
+            }
+        }
     }
 
 }



Mime
View raw message