use of com.sun.messaging.jmq.io.disk.PHashMapMMF in project openmq by eclipse-ee4j.
the class TidList method updateTransactionState.
/**
* Update the state of a transaction
*
* @param id the transaction id to be updated
* @param tstate the new transaction state
* @exception BrokerException if an error occurs while persisting or the same transaction id does NOT exists the store
* already
* @exception NullPointerException if <code>id</code> is <code>null</code>
*/
void updateTransactionState(TransactionUID id, TransactionState tstate, boolean sync) throws IOException, BrokerException {
try {
TransactionInfo txnInfo = (TransactionInfo) tidMap.get(id);
if (txnInfo == null) {
logger.log(logger.ERROR, br.E_TRANSACTIONID_NOT_FOUND_IN_STORE, id);
throw new BrokerException(br.getString(br.E_TRANSACTIONID_NOT_FOUND_IN_STORE, id), Status.NOT_FOUND);
}
TransactionState txnState = txnInfo.getTransactionState();
int ts = tstate.getState();
if (txnState.getState() != ts) {
txnState.setState(ts);
if (tstate.getOnephasePrepare()) {
txnState.setOnephasePrepare(true);
}
if (updateOptimization) {
// To improve I/O performance, just persist the new
// state as client data and not the whole record
byte[] cd = generateClientData(id, txnInfo);
PHashMapMMF tidMapMMF = (PHashMapMMF) tidMap;
tidMapMMF.putClientData(id, cd);
} else {
tidMap.put(id, txnInfo);
}
} else {
// No need to sync
sync = false;
}
if (sync) {
sync(id);
}
} catch (Exception e) {
logger.log(logger.ERROR, br.X_UPDATE_TXNSTATE_FAILED, id, e);
throw new BrokerException(br.getString(br.X_UPDATE_TXNSTATE_FAILED, id), e);
}
}
use of com.sun.messaging.jmq.io.disk.PHashMapMMF in project openmq by eclipse-ee4j.
the class FileTxLogImpl method init.
@Override
public void init(Properties props, boolean reset) throws Exception {
if (_logger == null) {
throw new IllegalStateException("No logger set");
}
super.init(props, reset);
if (props != null) {
Enumeration en = props.propertyNames();
String name = null;
String value = null;
while (en.hasMoreElements()) {
name = (String) en.nextElement();
value = props.getProperty(name);
_logger.log(Level.INFO, _jbr.getString(_jbr.I_FILETXNLOG_SET_PROP, name + "=" + value, _tmname));
setProperty(name, value);
}
}
if (_txlogdir == null) {
throw new IllegalStateException("Property txlogDir not set");
}
String fname = (txlogSuffix == null ? FILENAME_BASE : (FILENAME_BASE + "." + txlogSuffix));
if (reset) {
_logger.log(Level.INFO, _jbr.getString(_jbr.I_FILETXNLOG_INIT_WITH_RESET, fname));
if (_txlogdirParent != null) {
String fn = _txlogdirParent + File.separator + FILENAME_JMSBRIDGES;
File f = new File(fn);
if (f.exists()) {
if (!f.delete()) {
_logger.log(Level.WARNING, "Failed to delete file " + fn + " on reset");
File dfn = new File(_txlogdirParent, FILENAME_JMSBRIDGES + ".deleted");
if (!f.renameTo(dfn)) {
_logger.log(Level.WARNING, "Failed rename file " + fn + " to " + dfn + " after deletion failure");
}
}
}
}
} else {
_logger.log(Level.INFO, _jbr.getString(_jbr.I_FILETXNLOG_INIT, fname));
}
_backFile = new File(_txlogdir, fname);
if (useMmap) {
_gxidMap = new PHashMapMMF(_backFile, _logsize, 1024, false, reset, false, false);
((PHashMapMMF) _gxidMap).intClientData(_clientDataSize);
} else {
_gxidMap = new PHashMap(_backFile, _logsize, 1024, false, reset, false, false);
}
try {
_gxidMap.load(this);
if (_clientDataSize > 0) {
loadClientData();
}
} catch (PHashMapLoadException pe) {
_logger.log(Level.WARNING, "Exception in loading txlog " + _backFile, pe);
throw pe;
}
VRFileWarning w = _gxidMap.getWarning();
if (w != null) {
_logger.log(Level.WARNING, "Warning in loading txlog, possible loss of record", w);
}
_logger.log(Level.INFO, _jbr.getString(_jbr.I_FILETXNLOG_LOADED, _backFile, String.valueOf(_gxidMap.size())));
}
use of com.sun.messaging.jmq.io.disk.PHashMapMMF in project openmq by eclipse-ee4j.
the class FileTxLogImpl method logHeuristicBranch.
/**
* branch heuristic decision should be already set in lr
*/
@Override
public void logHeuristicBranch(BranchXid bxid, LogRecord lr) throws Exception {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "txlog: log branch heuristic decision " + lr);
}
String key = lr.getGlobalXid().toString();
super.checkClosedAndSetInProgress();
try {
LogRecord oldlr = (LogRecord) _gxidMap.get(key);
if (oldlr == null) {
logGlobalDecision(lr);
if (sync) {
_gxidMap.force(key);
}
return;
}
if (oldlr.getBranchDecision(bxid) == lr.getBranchDecision(bxid)) {
return;
}
oldlr.setBranchDecision(bxid, lr.getBranchDecision(bxid));
if (useMmap) {
if (oldlr.getBranchCount() > _clientDataSize) {
throw new IllegalArgumentException("The number of branches exceeded maximum " + _clientDataSize + " allowed");
}
byte[] oldcd = ((PHashMapMMF) _gxidMap).getClientData(key);
oldlr.updateClientDataFromBranch(oldcd, bxid);
((PHashMapMMF) _gxidMap).putClientData(key, oldcd);
} else {
_gxidMap.put(key, oldlr);
}
if (sync) {
_gxidMap.force(key);
}
} finally {
super.setInProgress(false);
}
}
use of com.sun.messaging.jmq.io.disk.PHashMapMMF in project openmq by eclipse-ee4j.
the class TidList method updateTransactionBrokerState.
/**
* Update transaction's participant broker state if the txn's state matches the expected state.
*
* @param id the id of the transaction to be updated
* @param expectedTxnState the expected transaction state
* @param txnBkr the participant broker to be updated
* @exception BrokerException if the transaction is not found in the store or the txn's state doesn't match the expected
* state (Status.CONFLICT)
*/
void updateTransactionBrokerState(TransactionUID id, int expectedTxnState, TransactionBroker txnBkr, boolean sync) throws BrokerException {
try {
TransactionInfo txnInfo = (TransactionInfo) tidMap.get(id);
if (txnInfo == null) {
logger.log(Logger.ERROR, BrokerResources.E_TRANSACTIONID_NOT_FOUND_IN_STORE, id);
throw new BrokerException(br.getString(BrokerResources.E_TRANSACTIONID_NOT_FOUND_IN_STORE, id), Status.NOT_FOUND);
}
TransactionState txnState = txnInfo.getTransactionState();
if (txnState.getState() != expectedTxnState) {
Object[] args = { txnBkr, id, TransactionState.toString(expectedTxnState), TransactionState.toString(txnState.getState()) };
throw new BrokerException(br.getKString(BrokerResources.E_UPDATE_TXNBROKER_FAILED, args), Status.CONFLICT);
}
txnInfo.updateBrokerState(txnBkr);
if (updateOptimization) {
// To improve I/O performance, just persist the new
// state as client data and not the whole record
byte[] cd = generateClientData(id, txnInfo);
PHashMapMMF tidMapMMF = (PHashMapMMF) tidMap;
tidMapMMF.putClientData(id, cd);
} else {
tidMap.put(id, txnInfo);
}
if (sync) {
sync(id);
}
} catch (Exception e) {
logger.log(Logger.ERROR, BrokerResources.X_PERSIST_TRANSACTION_FAILED, id, e);
throw new BrokerException(br.getString(BrokerResources.X_PERSIST_TRANSACTION_FAILED, id), e);
}
}
Aggregations