Search in sources :

Example 1 with HOWLLog

use of org.apache.geronimo.transaction.log.HOWLLog in project aries by apache.

the class TransactionManagerService method createTransactionLog.

static TransactionLog createTransactionLog(Dictionary properties, XidFactory xidFactory) throws ConfigurationException {
    TransactionLog result = null;
    if (getBool(properties, RECOVERABLE, DEFAULT_RECOVERABLE)) {
        String bufferClassName = getString(properties, HOWL_BUFFER_CLASS_NAME, "org.objectweb.howl.log.BlockLogBuffer");
        int bufferSizeKBytes = getInt(properties, HOWL_BUFFER_SIZE, 4);
        if (bufferSizeKBytes < 1 || bufferSizeKBytes > 32) {
            throw new ConfigurationException(HOWL_BUFFER_SIZE, "The buffer size must be between one and thirty-two.");
        }
        boolean checksumEnabled = getBool(properties, HOWL_CHECKSUM_ENABLED, true);
        boolean adler32Checksum = getBool(properties, HOWL_ADLER32_CHECKSUM, true);
        int flushSleepTimeMilliseconds = getInt(properties, HOWL_FLUSH_SLEEP_TIME, 50);
        String logFileExt = getString(properties, HOWL_LOG_FILE_EXT, "log");
        String logFileName = getString(properties, HOWL_LOG_FILE_NAME, "transaction");
        int maxBlocksPerFile = getInt(properties, HOWL_MAX_BLOCKS_PER_FILE, -1);
        int maxLogFiles = getInt(properties, HOWL_MAX_LOG_FILES, 2);
        int minBuffers = getInt(properties, HOWL_MIN_BUFFERS, 4);
        if (minBuffers < 0) {
            throw new ConfigurationException(HOWL_MIN_BUFFERS, "The minimum number of buffers must be greater than zero.");
        }
        int maxBuffers = getInt(properties, HOWL_MAX_BUFFERS, 0);
        if (maxBuffers > 0 && minBuffers < maxBuffers) {
            throw new ConfigurationException(HOWL_MAX_BUFFERS, "The maximum number of buffers must be greater than the minimum number of buffers.");
        }
        int threadsWaitingForceThreshold = getInt(properties, HOWL_THREADS_WAITING_FORCE_THRESHOLD, -1);
        boolean flushPartialBuffers = getBool(properties, HOWL_FLUSH_PARTIAL_BUFFERS, true);
        String logFileDir = getString(properties, HOWL_LOG_FILE_DIR, null);
        if (logFileDir == null || logFileDir.length() == 0 || !new File(logFileDir).isAbsolute()) {
            throw new ConfigurationException(HOWL_LOG_FILE_DIR, "The log file directory must be set to an absolute directory.");
        }
        try {
            result = new HOWLLog(bufferClassName, bufferSizeKBytes, checksumEnabled, adler32Checksum, flushSleepTimeMilliseconds, logFileDir, logFileExt, logFileName, maxBlocksPerFile, maxBuffers, maxLogFiles, minBuffers, threadsWaitingForceThreshold, flushPartialBuffers, xidFactory, null);
            ((HOWLLog) result).doStart();
        } catch (Exception e) {
            // This should not really happen as we've checked properties earlier
            throw new ConfigurationException(null, e.getMessage(), e);
        }
    } else {
        result = new UnrecoverableLog();
    }
    return result;
}
Also used : TransactionLog(org.apache.geronimo.transaction.manager.TransactionLog) ConfigurationException(org.osgi.service.cm.ConfigurationException) HOWLLog(org.apache.geronimo.transaction.log.HOWLLog) File(java.io.File) ConfigurationException(org.osgi.service.cm.ConfigurationException) XAException(javax.transaction.xa.XAException) UnrecoverableLog(org.apache.geronimo.transaction.log.UnrecoverableLog)

Example 2 with HOWLLog

use of org.apache.geronimo.transaction.log.HOWLLog in project aries by apache.

the class LogConversionTest method changedNumberOfFiles.

@Test
@SuppressWarnings("unchecked")
public void changedNumberOfFiles() throws Exception {
    File logDir = new File(BASE, "changedNumberOfFiles");
    FileUtils.deleteDirectory(logDir);
    logDir.mkdirs();
    Hashtable<String, Object> properties = new Hashtable<String, Object>();
    HOWLLog txLog = createLog("changedNumberOfFiles", "transaction", 2, -1, 1, properties);
    txLog.doStart();
    transaction(txLog, 1, false);
    txLog.doStop();
    Hashtable<String, Object> newConfig = (Hashtable<String, Object>) properties.clone();
    newConfig.put("aries.transaction.howl.maxLogFiles", "20");
    long lm = earlierLastModified(new File(logDir, "transaction_1.log"));
    assertTrue(TransactionLogUtils.copyActiveTransactions(properties, newConfig));
    assertTrue("Transaction log should exist", new File(logDir, "transaction_1.log").exists());
    assertTrue("There should be 20 transaction log files", new File(logDir, "transaction_20.log").exists());
    assertThat("Transaction log should be processed", new File(logDir, "transaction_1.log").lastModified(), not(equalTo(lm)));
}
Also used : HOWLLog(org.apache.geronimo.transaction.log.HOWLLog) Hashtable(java.util.Hashtable) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 3 with HOWLLog

use of org.apache.geronimo.transaction.log.HOWLLog in project aries by apache.

the class LogConversionTest method initialConfigurationExistingTransactionLogNoChanges.

@Test
public void initialConfigurationExistingTransactionLogNoChanges() throws Exception {
    File logDir = new File(BASE, "initialConfigurationExistingTransactionLogNoChanges");
    FileUtils.deleteDirectory(logDir);
    logDir.mkdirs();
    Dictionary<String, Object> properties = new Hashtable<String, Object>();
    HOWLLog txLog = createLog("initialConfigurationExistingTransactionLogNoChanges", "transaction", 2, -1, 1, properties);
    txLog.doStart();
    transaction(txLog, 1, false);
    txLog.doStop();
    long lm = earlierLastModified(new File(logDir, "transaction_1.log"));
    assertFalse(TransactionLogUtils.copyActiveTransactions(null, properties));
    assertThat("Transaction log should not be touched", new File(logDir, "transaction_1.log").lastModified(), equalTo(lm));
}
Also used : HOWLLog(org.apache.geronimo.transaction.log.HOWLLog) Hashtable(java.util.Hashtable) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 4 with HOWLLog

use of org.apache.geronimo.transaction.log.HOWLLog in project aries by apache.

the class TransactionLogTest method checkLogClosed.

private void checkLogClosed(TransactionControlImpl toCheck) throws Exception {
    Field f = TransactionControlImpl.class.getDeclaredField("log");
    f.setAccessible(true);
    HOWLLog log = (HOWLLog) f.get(toCheck);
    f = HOWLLog.class.getDeclaredField("logger");
    f.setAccessible(true);
    org.objectweb.howl.log.Logger howlLogger = (org.objectweb.howl.log.Logger) f.get(log);
    f = org.objectweb.howl.log.Logger.class.getDeclaredField("bmgr");
    f.setAccessible(true);
    Object logBufferManager = f.get(howlLogger);
    f = logBufferManager.getClass().getDeclaredField("flushManager");
    f.setAccessible(true);
    Thread flushThread = (Thread) f.get(logBufferManager);
    assertFalse(flushThread.isAlive());
    f = org.objectweb.howl.log.Logger.class.getDeclaredField("lfmgr");
    f.setAccessible(true);
    Object logFileManager = f.get(howlLogger);
    f = logFileManager.getClass().getDeclaredField("eventManagerThread");
    f.setAccessible(true);
    Thread eventManagerThread = (Thread) f.get(logFileManager);
    assertFalse(eventManagerThread.isAlive());
}
Also used : Field(java.lang.reflect.Field) HOWLLog(org.apache.geronimo.transaction.log.HOWLLog)

Example 5 with HOWLLog

use of org.apache.geronimo.transaction.log.HOWLLog in project tomee by apache.

the class GeronimoTransactionManagerFactory method create.

public static // Deprecated, use defaultTransactionTimeout
GeronimoTransactionManager create(// Deprecated, use defaultTransactionTimeout
Integer defaultTransactionTimeoutSeconds, final Duration defaultTransactionTimeout, final boolean txRecovery, final byte[] tmId, final String bufferClassName, final int bufferSizeKb, final boolean checksumEnabled, final boolean adler32Checksum, // Deprecated, use flushSleepTime
Integer flushSleepTimeMilliseconds, final Duration flushSleepTime, final String logFileDir, final String logFileExt, final String logFileName, final int maxBlocksPerFile, final int maxBuffers, final int maxLogFiles, final int minBuffers, final int threadsWaitingForceThreshold) throws Exception {
    if (flushSleepTime.getUnit() == null) {
        flushSleepTime.setUnit(TimeUnit.MILLISECONDS);
    }
    if (flushSleepTimeMilliseconds == null) {
        flushSleepTimeMilliseconds = (int) TimeUnit.MILLISECONDS.convert(flushSleepTime.getTime(), flushSleepTime.getUnit());
    }
    if (defaultTransactionTimeout.getUnit() == null) {
        defaultTransactionTimeout.setUnit(TimeUnit.SECONDS);
    }
    if (defaultTransactionTimeoutSeconds == null) {
        defaultTransactionTimeoutSeconds = (int) TimeUnit.SECONDS.convert(defaultTransactionTimeout.getTime(), defaultTransactionTimeout.getUnit());
    }
    XidFactory xidFactory = null;
    TransactionLog txLog = null;
    if (txRecovery) {
        SystemInstance.get().setComponent(XAResourceWrapper.class, new GeronimoXAResourceWrapper());
        xidFactory = new XidFactoryImpl(tmId == null ? DEFAULT_TM_ID : tmId);
        txLog = new HOWLLog(bufferClassName == null ? "org.objectweb.howl.log.BlockLogBuffer" : bufferClassName, bufferSizeKb == 0 ? DEFAULT_BUFFER_SIZE : bufferSizeKb, checksumEnabled, adler32Checksum, flushSleepTimeMilliseconds, logFileDir, logFileExt, logFileName, maxBlocksPerFile, maxBuffers, maxLogFiles, minBuffers, threadsWaitingForceThreshold, xidFactory, SystemInstance.get().getBase().getDirectory("."));
        ((HOWLLog) txLog).doStart();
    }
    final GeronimoTransactionManager geronimoTransactionManager = new DestroyableTransactionManager(defaultTransactionTimeoutSeconds, xidFactory, txLog);
    final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management").set("j2eeType", "TransactionManager");
    LocalMBeanServer.registerDynamicWrapperSilently(new TransactionManagerMBean(geronimoTransactionManager, defaultTransactionTimeout, txLog), jmxName.build());
    return geronimoTransactionManager;
}
Also used : ObjectNameBuilder(org.apache.openejb.monitoring.ObjectNameBuilder) TransactionLog(org.apache.geronimo.transaction.manager.TransactionLog) XidFactoryImpl(org.apache.geronimo.transaction.manager.XidFactoryImpl) HOWLLog(org.apache.geronimo.transaction.log.HOWLLog) GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager) XidFactory(org.apache.geronimo.transaction.manager.XidFactory)

Aggregations

HOWLLog (org.apache.geronimo.transaction.log.HOWLLog)16 File (java.io.File)14 RandomAccessFile (java.io.RandomAccessFile)11 Test (org.junit.Test)11 Hashtable (java.util.Hashtable)10 XidFactory (org.apache.geronimo.transaction.manager.XidFactory)3 GeronimoTransactionManager (org.apache.geronimo.transaction.manager.GeronimoTransactionManager)2 TransactionLog (org.apache.geronimo.transaction.manager.TransactionLog)2 ConfigurationException (org.osgi.service.cm.ConfigurationException)2 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 XAException (javax.transaction.xa.XAException)1 XAResource (javax.transaction.xa.XAResource)1 UnrecoverableLog (org.apache.geronimo.transaction.log.UnrecoverableLog)1 NamedXAResource (org.apache.geronimo.transaction.manager.NamedXAResource)1 Recovery (org.apache.geronimo.transaction.manager.Recovery)1 TransactionBranchInfo (org.apache.geronimo.transaction.manager.TransactionBranchInfo)1