All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.atomikos.recovery.fs.OltpLogImp Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
/**
 * Copyright (C) 2000-2023 Atomikos 
 *
 * LICENSE CONDITIONS
 *
 * See http://www.atomikos.com/Main/WhichLicenseApplies for details.
 */

package com.atomikos.recovery.fs;


import com.atomikos.icatch.config.Configuration;
import com.atomikos.logging.Logger;
import com.atomikos.logging.LoggerFactory;
import com.atomikos.recovery.LogWriteException;
import com.atomikos.recovery.OltpLog;
import com.atomikos.recovery.PendingTransactionRecord;
import com.atomikos.recovery.TxState;

public class OltpLogImp implements OltpLog {


	private static final Logger LOGGER = LoggerFactory.createLogger(OltpLogImp.class);
	private Repository repository;
    private String recoveryDomainName;

	public void setRepository(Repository repository) {
		this.repository = repository;
		this.recoveryDomainName = Configuration.getConfigProperties().getTmUniqueName();
	}

	
	@Override
	public void write(PendingTransactionRecord pendingTransactionRecord) throws LogWriteException {
	    TxState state = pendingTransactionRecord.state;
	    if (pendingTransactionRecord.expires < System.currentTimeMillis()) {
	        if (state == TxState.IN_DOUBT) {
	            throw new IllegalArgumentException("Transaction has expired - " + state + " no longer allowed");
	        } else if (state == TxState.COMMITTING && pendingTransactionRecord.isRecoveredByDomain(recoveryDomainName)
	                 ){
	            throw new IllegalArgumentException("Transaction may have been subject to abort by recovery - COMMITTING no longer allowed");
	        }
	            
	    }
		if(pendingTransactionRecord.state.isRecoverableState()) {
			repository.put(pendingTransactionRecord.id, pendingTransactionRecord);	
		} else {
			LOGGER.logWarning("Attempt to log a record with unexpected state : " + pendingTransactionRecord.state);
		}
			
		
	}

	@Override
	public void close() {
		repository.close();
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy