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;
}
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)));
}
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));
}
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());
}
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;
}
Aggregations