Search in sources :

Example 1 with UpdateOpaqueDataCallback

use of com.sun.messaging.bridge.api.UpdateOpaqueDataCallback in project openmq by eclipse-ee4j.

the class JDBCTxLogImpl method logHeuristicBranch.

/**
 * @param bxid the branch xid to update
 * @param lr the LogRecord to identify the record to update
 */
@Override
public void logHeuristicBranch(BranchXid bxid, LogRecord lr) throws Exception {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "jdbcTxLog: log branch heuristic decision  " + lr);
    }
    final GlobalXid gxid = lr.getGlobalXid();
    final BranchXid branchXid = bxid;
    final LogRecord newlr = lr;
    super.checkClosedAndSetInProgress();
    try {
        UpdateOpaqueDataCallback callback = new UpdateOpaqueDataCallback() {

            @Override
            public Object update(Object currlr) throws Exception {
                ObjectInputStream ois = new FilteringObjectInputStream(new ByteArrayInputStream((byte[]) currlr));
                LogRecord oldlr = (LogRecord) ois.readObject();
                if (oldlr == null) {
                    throw new IllegalArgumentException("Unexpected null current log record for " + gxid);
                }
                if (!oldlr.getGlobalXid().equals(gxid)) {
                    throw new IllegalArgumentException("Unexpected global xid " + oldlr.getGlobalXid() + " from store, expected:" + gxid);
                }
                ois.close();
                if (oldlr.getBranchDecision(branchXid) == newlr.getBranchDecision(branchXid)) {
                    return currlr;
                }
                oldlr.setBranchDecision(branchXid, newlr.getBranchDecision(branchXid));
                return oldlr;
            }
        };
        _store.updateTMLogRecord(gxid.toString(), lr.toBytes(), _jmsbridge, callback, true, true, _logger);
    } finally {
        super.setInProgress(false);
    }
}
Also used : GlobalXid(com.sun.messaging.bridge.service.jms.tx.GlobalXid) ByteArrayInputStream(java.io.ByteArrayInputStream) UpdateOpaqueDataCallback(com.sun.messaging.bridge.api.UpdateOpaqueDataCallback) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) BranchXid(com.sun.messaging.bridge.service.jms.tx.BranchXid) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

UpdateOpaqueDataCallback (com.sun.messaging.bridge.api.UpdateOpaqueDataCallback)1 BranchXid (com.sun.messaging.bridge.service.jms.tx.BranchXid)1 GlobalXid (com.sun.messaging.bridge.service.jms.tx.GlobalXid)1 FilteringObjectInputStream (com.sun.messaging.jmq.util.io.FilteringObjectInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1